@@ -2,30 +2,38 @@ name: NPM Publish
22
33on :
44 workflow_dispatch :
5+ inputs :
6+ dry-run-enabled :
7+ description : ' Enable dry run for publishing (does not publish to npmjs)'
8+ required : false
9+ default : false
10+ type : boolean
511
612permissions :
13+ id-token : write
714 contents : read
815
916jobs :
10- publish :
11- name : Publish NPM package
17+ build-npm-package :
18+ name : Build NPM package
1219 runs-on : smart-contracts-linux-medium
20+ outputs :
21+ npm-artifact-name : ${{ steps.set-publish-data.outputs.artifact-name }}
1322 steps :
14- - name : Harden Runner
15- uses : step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
23+ - name : Prepare Runner
24+ uses : pandaswhocode/initialize-github-job@ed4a98646fe0235e6ecf3af5414b355d2abe3bf3 # v1.0.3
1625 with :
17- egress-policy : audit
18-
19- - name : Checkout Code
20- uses : actions/ checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
21- with :
22- submodules : recursive
26+ checkout : ' true '
27+ checkout-ref : ' ${{ github.ref }} '
28+ checkout-token : ' ${{ secrets.GITHUB_TOKEN }} '
29+ checkout-fetch-depth : ' 1 '
30+ setup-node : ' true '
31+ node-version : ' 20 '
2332
24- - name : Set up Node.js
25- uses : actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
33+ - name : Setup JQ
34+ uses : dcarbone/install-jq-action@b7ef57d46ece78760b4019dbc4080a1ba2a40b45 # v3.2.0
2635 with :
27- node-version : ' 20'
28- registry-url : ' https://registry.npmjs.org'
36+ version : 1.7
2937
3038 - name : Install Foundry
3139 uses : step-security/foundry-toolchain@01e2d127ea061e2ce8fa34340de71ca8518f093e # v1.2.1
4149 - name : Run Unit Tests
4250 run : npm run test
4351
44- - name : Publish NPM package
45- run : npm publish --access public
46- env :
47- NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
52+ - name : Set Publish Data
53+ id : set-publish-data
54+ run : |
55+ VERSION=$(jq -r '.version' './package.json')
56+ NPM_PACKAGE_NAME="hashgraph-system-contracts-forking-${VERSION}.tgz"
57+ echo "artifact-name=${NPM_PACKAGE_NAME}" >> "${GITHUB_OUTPUT}"
58+
59+ - name : Build NPM package
60+ run : npm pack
61+
62+ - name : Upload Hedera Custodians Library Package Artifact
63+ uses : actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
64+ with :
65+ name : npm-package
66+ path : ./${{ steps.set-publish-data.outputs.artifact-name }}
67+ if-no-files-found : error
68+
69+ publish-npm-package :
70+ runs-on : ubuntu-latest
71+ needs :
72+ - build-npm-package
73+ steps :
74+ - name : Prepare Runner
75+ uses : pandaswhocode/initialize-github-job@ed4a98646fe0235e6ecf3af5414b355d2abe3bf3 # v1.0.3
76+ with :
77+ checkout : ' true'
78+ checkout-ref : ' ${{ github.ref }}'
79+ checkout-fetch-depth : ' 1'
80+ checkout-token : ' ${{ secrets.GITHUB_TOKEN }}'
81+ setup-node : ' true'
82+ node-version : ' 20'
83+ node-registry : ' https://registry.npmjs.org'
84+
85+ - name : Install NPM latest
86+ run : npm install -g npm@11.7.0
87+
88+ - name : Download Hedera Custodians Library NPM Package
89+ uses : actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
90+ with :
91+ name : npm-package
92+
93+ - name : Publish NPM Package
94+ run : |
95+ args="--access=public"
96+ if [[ "${{ inputs.dry-run-enabled || 'false' }}" == "true" ]]; then
97+ args="${args} --dry-run"
98+ fi
99+
100+ package="${{ needs.build-npm-package.outputs.npm-artifact-name }}"
101+ echo "::group::Publishing package: ${package} with args: ${args}"
102+ npm publish ${package} ${args}
103+ echo "::endgroup::"
0 commit comments