Fix build-and-release github action #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Update Release | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-update: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Rust | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
override: true | |
- name: Install wasm-pack | |
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | |
- name: Build | |
run: wasm-pack build --target web | |
- name: Get or create release | |
id: get_or_create_release | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
try { | |
const release = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: 'latest' | |
}); | |
return release.data; | |
} catch (error) { | |
if (error.status === 404) { | |
const newRelease = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: 'latest', | |
name: 'Latest Release', | |
body: 'This is the latest release of the WebAssembly module.', | |
draft: false, | |
prerelease: false | |
}); | |
return newRelease.data; | |
} | |
throw error; | |
} | |
- name: Upload WebAssembly Module | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ fromJson(steps.get_or_create_release.outputs.result).upload_url }} | |
asset_path: ./pkg/gsea_rs_bg.wasm | |
asset_name: gsea_rs_bg.wasm | |
asset_content_type: application/wasm | |
- name: Upload JavaScript Wrapper | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ fromJson(steps.get_or_create_release.outputs.result).upload_url }} | |
asset_path: ./pkg/gsea_rs.js | |
asset_name: gsea_rs.js | |
asset_content_type: application/javascript |