Skip to content

chore(ci): Automatic release to npmjs (#378) #123

chore(ci): Automatic release to npmjs (#378)

chore(ci): Automatic release to npmjs (#378) #123

Workflow file for this run

name: Release-plz
permissions:
pull-requests: write
contents: write
on:
push:
branches:
- main
jobs:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_PLZ_TOKEN }}
- name: Install Protoc
uses: arduino/setup-protoc@v2
with:
version: "23.3"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install wasm-pack
uses: jetli/[email protected]
- name: Run release-plz
uses: MarcoIeni/[email protected]
id: release-plz
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Bump lumina-node npm version
if: ${{ steps.release-plz.outputs.prs_created }}
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN }}
run: |
node_wasm_version="$(cargo pkgid --manifest-path=node-wasm/Cargo.toml | cut -d@ -f 2)"
cd node-wasm/js
# Update the version of lumina-node-wasm dependency
npm pkg set "dependencies[lumina-node-wasm]=$node_wasm_version"
# Update lumina-node version
npm version $node_wasm_version
# push a commit to release-plz's pr
# fetch the branch created by release-plz
git fetch
# prepare graphql query
branch_name=${{ steps.release-plz.outputs.pr.head_branch }}
branch_sha="$(git rev-parse "$branch_name")"
package_json="$(base64 --wrap 0 package.json)"
query='{"query": "mutation {
createCommitOnBranch(input: {
branch: {
repositoryNameWithOwner: \"eigerco/lumina\",
branchName: \"'"$branch_name"'\"
},
message: {
headline: \"update lumina-node npm package\"
},
expectedHeadOid: \"'"$branch_sha"'\",
fileChanges: {
additions: [{
path: \"node-wasm/js/package.json\",
contents: \"'"$package_json"'\"
}]
}
})
{ commit { commitUrl } }
}"}'
# create new commit with changes
curl https://api.github.com/graphql \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
--data "$(echo "$query" | tr -d '\n')"
- name: Release to npm
env:
NPM_REGISTRY_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
run: |
published_version=$(npm show lumina-node-wasm version)
local_version="$(cargo pkgid --manifest-path=node-wasm/Cargo.toml | cut -d@ -f 2)"
if [ "$published_version" == "$local_version" ] ; then
echo Latest version already in npm, exiting
exit
fi
# publish lumina-node-wasm
wasm-pack build --target web node-wasm
# todo: uncomment on first release-plz pr
# wasm-pack publish --target web --access public node-wasm
# publish lumina-node
cd node-wasm/js
# todo: uncomment on first release-plz pr
# npm publish --access public