From a8df56d38fef2a256ebc9406f7f92f0263ddb17f Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 2 Oct 2023 08:11:36 +0200 Subject: [PATCH 1/6] build: publish to npm only if needed --- scripts/publish-npm.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 scripts/publish-npm.sh diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh new file mode 100755 index 000000000..37bdb8ae3 --- /dev/null +++ b/scripts/publish-npm.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# Reference: NPM RRFC --if-needed https://github.com/npm/rfcs/issues/466 + +function publish_npm() { + local lib=$1 + + LOCAL_SHASUM=$(npm show @dfinity/"$lib" dist.shasum) + NPM_TARBALL=$(npm show @dfinity/"$lib" dist.tarball) + NPM_SHASUM=$(curl -s "$NPM_TARBALL" 2>&1 | shasum | cut -f1 -d' ') + + if [ "$LOCAL_SHASUM" == "$NPM_SHASUM" ]; then + echo "No changes in @dfinity/$lib need to be published to NPM." + else + npm publish --workspace=packages/"$lib" --provenance + fi +} + +# Tips: libs use by other libs first +LIBS=utils,ledger,nns-proto,nns,sns,cmc,ckbtc,ic-management + +for lib in $(echo $LIBS | sed "s/,/ /g") +do + publish_npm "$lib" +done \ No newline at end of file From 9810dd731919ee8b764d7acdad7609fa3f3d9e2c Mon Sep 17 00:00:00 2001 From: Formatting Committer Date: Mon, 2 Oct 2023 06:12:45 +0000 Subject: [PATCH 2/6] Updating formatting --- scripts/publish-npm.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh index 37bdb8ae3..a06111ad9 100755 --- a/scripts/publish-npm.sh +++ b/scripts/publish-npm.sh @@ -7,7 +7,7 @@ function publish_npm() { LOCAL_SHASUM=$(npm show @dfinity/"$lib" dist.shasum) NPM_TARBALL=$(npm show @dfinity/"$lib" dist.tarball) - NPM_SHASUM=$(curl -s "$NPM_TARBALL" 2>&1 | shasum | cut -f1 -d' ') + NPM_SHASUM=$(curl -s "$NPM_TARBALL" 2>&1 | shasum | cut -f1 -d' ') if [ "$LOCAL_SHASUM" == "$NPM_SHASUM" ]; then echo "No changes in @dfinity/$lib need to be published to NPM." @@ -19,7 +19,6 @@ function publish_npm() { # Tips: libs use by other libs first LIBS=utils,ledger,nns-proto,nns,sns,cmc,ckbtc,ic-management -for lib in $(echo $LIBS | sed "s/,/ /g") -do - publish_npm "$lib" -done \ No newline at end of file +for lib in $(echo $LIBS | sed "s/,/ /g"); do + publish_npm "$lib" +done From 5bda1874226af4efd2ef5b3221ebf9c04c6c7841 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 2 Oct 2023 09:01:46 +0200 Subject: [PATCH 3/6] build: pack to get new shasum --- scripts/publish-npm.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh index 37bdb8ae3..ec8406311 100755 --- a/scripts/publish-npm.sh +++ b/scripts/publish-npm.sh @@ -5,7 +5,8 @@ function publish_npm() { local lib=$1 - LOCAL_SHASUM=$(npm show @dfinity/"$lib" dist.shasum) + LOCAL_SHASUM=$(npm pack -w packages/"$lib" --json | jq '.[] | .shasum' | sed -r 's/^"|"$//g') + NPM_TARBALL=$(npm show @dfinity/"$lib" dist.tarball) NPM_SHASUM=$(curl -s "$NPM_TARBALL" 2>&1 | shasum | cut -f1 -d' ') From e84beedbb80ffebd84462027b83bd54d5f338bbd Mon Sep 17 00:00:00 2001 From: Formatting Committer Date: Mon, 2 Oct 2023 07:02:46 +0000 Subject: [PATCH 4/6] Updating formatting --- scripts/publish-npm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh index ddd5118e7..a2008ec1c 100755 --- a/scripts/publish-npm.sh +++ b/scripts/publish-npm.sh @@ -5,7 +5,7 @@ function publish_npm() { local lib=$1 - LOCAL_SHASUM=$(npm pack -w packages/"$lib" --json | jq '.[] | .shasum' | sed -r 's/^"|"$//g') + LOCAL_SHASUM=$(npm pack -w packages/"$lib" --json | jq '.[] | .shasum' | sed -r 's/^"|"$//g') NPM_TARBALL=$(npm show @dfinity/"$lib" dist.tarball) NPM_SHASUM=$(curl -s "$NPM_TARBALL" 2>&1 | shasum | cut -f1 -d' ') From 6dc25c7608e83adf45a59a6df0ded87da9ed70e8 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 2 Oct 2023 09:07:21 +0200 Subject: [PATCH 5/6] build: use script to publish to npm --- .github/workflows/publish.yml | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a2cba4726..8effd7008 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -20,35 +20,7 @@ jobs: run: npm run build --workspaces - name: Set up npm run: printf '%s\n' '//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}' registry=https://registry.npmjs.org/ always-auth=true >> .npmrc - - name: Publish utils - run: npm publish --workspace=packages/utils --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish Ledger - run: npm publish --workspace=packages/ledger --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish NNS-proto - run: npm publish --workspace=packages/nns-proto --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish NNS - run: npm publish --workspace=packages/nns --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish SNS - run: npm publish --workspace=packages/sns --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish CMC - run: npm publish --workspace=packages/cmc --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish ckBTC - run: npm publish --workspace=packages/ckbtc --provenance --access public - env: - NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - - name: Publish ic-management - run: npm publish --workspace=packages/ic-management --provenance --access public + - name: Publish + run: ./scripts/publish-npm.sh env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} From 6d29cf16e8158b003f82d37c3d2e0708c7648181 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Mon, 2 Oct 2023 11:49:31 +0200 Subject: [PATCH 6/6] build: keep public flag is useful when we publish brand new lib and does not arm existing --- scripts/publish-npm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/publish-npm.sh b/scripts/publish-npm.sh index a2008ec1c..48e98d575 100755 --- a/scripts/publish-npm.sh +++ b/scripts/publish-npm.sh @@ -13,7 +13,7 @@ function publish_npm() { if [ "$LOCAL_SHASUM" == "$NPM_SHASUM" ]; then echo "No changes in @dfinity/$lib need to be published to NPM." else - npm publish --workspace=packages/"$lib" --provenance + npm publish --workspace=packages/"$lib" --provenance --access public fi }