Skip to content

Commit

Permalink
chore(ci): Automatic release to npmjs (#378)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikołaj Florkiewicz <[email protected]>
Co-authored-by: Maciej Zwoliński <[email protected]>
  • Loading branch information
fl0rek and zvolin authored Sep 20, 2024
1 parent fe0138d commit f310ba8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/release-plz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,80 @@ jobs:
- 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
2 changes: 2 additions & 0 deletions node-wasm/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/package-lock.json
1 change: 1 addition & 0 deletions node-wasm/js/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_REGISTRY_TOKEN}
1 change: 1 addition & 0 deletions node-wasm/pkg/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_REGISTRY_TOKEN}

0 comments on commit f310ba8

Please sign in to comment.