From f310ba808be0294575972edb86d28f8691209a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Florkiewicz?= Date: Fri, 20 Sep 2024 16:07:00 +0200 Subject: [PATCH] chore(ci): Automatic release to npmjs (#378) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mikołaj Florkiewicz Co-authored-by: Maciej Zwoliński --- .github/workflows/release-plz.yml | 72 +++++++++++++++++++++++++++++++ node-wasm/js/.gitignore | 2 + node-wasm/js/.npmrc | 1 + node-wasm/pkg/.npmrc | 1 + 4 files changed, 76 insertions(+) create mode 100644 node-wasm/js/.gitignore create mode 100644 node-wasm/js/.npmrc create mode 100644 node-wasm/pkg/.npmrc diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml index b75ecc94..e41827e7 100644 --- a/.github/workflows/release-plz.yml +++ b/.github/workflows/release-plz.yml @@ -29,8 +29,80 @@ jobs: - name: Install Rust toolchain uses: dtolnay/rust-toolchain@stable + - name: Install wasm-pack + uses: jetli/wasm-pack-action@v0.4.0 + - name: Run release-plz uses: MarcoIeni/release-plz-action@v0.5 + 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 diff --git a/node-wasm/js/.gitignore b/node-wasm/js/.gitignore new file mode 100644 index 00000000..d5025124 --- /dev/null +++ b/node-wasm/js/.gitignore @@ -0,0 +1,2 @@ +/node_modules +/package-lock.json diff --git a/node-wasm/js/.npmrc b/node-wasm/js/.npmrc new file mode 100644 index 00000000..91aec623 --- /dev/null +++ b/node-wasm/js/.npmrc @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NPM_REGISTRY_TOKEN} diff --git a/node-wasm/pkg/.npmrc b/node-wasm/pkg/.npmrc new file mode 100644 index 00000000..91aec623 --- /dev/null +++ b/node-wasm/pkg/.npmrc @@ -0,0 +1 @@ +//registry.npmjs.org/:_authToken=${NPM_REGISTRY_TOKEN}