@@ -3,75 +3,213 @@ name: 'nativescript -> npm'
33on :
44 workflow_dispatch :
55 inputs :
6- bump_version :
7- description : ' Bump Version'
8- required : true
9- default : true
10- type : boolean
6+ release_type :
7+ description : ' Release type. "dev" publishes a -next prerelease without bumping package.json. patch/minor/major/prerelease bump package.json, commit + tag to main, then publish as a stable release.'
8+ type : choice
9+ options :
10+ - auto
11+ - patch
12+ - minor
13+ - major
14+ - prerelease
15+ default : auto
1116 next_version :
1217 description : ' Next Version with Next tag'
1318 required : true
1419 default : false
1520 type : boolean
1621
17- permissions :
18- contents : read
22+ permissions : read-all
23+
24+ env :
25+ NPM_TAG : ' next'
1926
2027jobs :
21- release :
28+ build :
29+ name : Build
2230 runs-on : macos-latest
31+ permissions :
32+ contents : write
33+ outputs :
34+ npm_version : ${{ steps.npm_version_output.outputs.NPM_VERSION }}
35+ npm_tag : ${{ steps.npm_version_output.outputs.NPM_TAG }}
36+ is_release : ${{ steps.npm_version_output.outputs.IS_RELEASE }}
2337
2438 steps :
25-
2639 - name : Harden the runner (Audit all outbound calls)
27- uses : step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13 .1
40+ uses : step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16 .1
2841 with :
2942 egress-policy : audit
3043
31- - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32-
33- - uses : actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
44+ - uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
45+ with :
46+ fetch-depth : 0
47+ token : ${{ secrets.GITHUB_TOKEN }}
48+
49+ - uses : actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
3450 with :
3551 node-version : 22.14.0
52+ registry-url : " https://registry.npmjs.org"
3653
3754 - name : Setup
3855 run : npm i --ignore-scripts --legacy-peer-deps --no-package-lock
3956
57+ - name : Get Current Version
58+ run : |
59+ NPM_VERSION=$(node -e "console.log(require('./package.json').version);")
60+ echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
61+
62+ - name : Bump, commit and tag stable release (manual dispatch)
63+ if : ${{ github.event_name == 'workflow_dispatch' && inputs.release_type != 'auto' && inputs.release_type != 'dev' }}
64+ run : |
65+ git config user.name "github-actions[bot]"
66+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
67+ npm version ${{ inputs.release_type }} -m "chore: release v%s"
68+ NPM_VERSION=$(node -e "console.log(require('./package.json').version);")
69+ echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
70+ git push origin HEAD:${GITHUB_REF_NAME} --follow-tags
71+
72+ - name : Bump version for dev release
73+ if : ${{ !contains(github.ref, 'refs/tags/') && (github.event_name != 'workflow_dispatch' || inputs.release_type == 'dev') }}
74+ run : |
75+ NPM_VERSION=$(node ./scripts/get-next-version.js)
76+ echo NPM_VERSION=$NPM_VERSION >> $GITHUB_ENV
77+ npm version $NPM_VERSION --no-git-tag-version
78+
4079 - name : Bump Standard Version
41- if : github.event. inputs.bump_version == 'true '
80+ if : inputs.release_type == 'auto '
4281 run : |
4382 npm run release
4483
4584 - name : Generate Version
4685 run : |
4786 echo NPM_VERSION=$(node -e "console.log(require('./package.json').version);") >> $GITHUB_ENV
4887
49- - name : Bump Version
50- if : github.event.inputs.next_version == 'true'
51- run : npm version $NPM_VERSION
88+ - name : Output NPM Version and tag
89+ id : npm_version_output
90+ run : |
91+ NPM_TAG=$(node ./scripts/get-npm-tag.js)
92+ if [[ "${GITHUB_REF}" == refs/tags/* ]] || [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ inputs.release_type }}" != "dev" && "${{ inputs.release_type }}" != "auto" ]]; then
93+ IS_RELEASE=true
94+ else
95+ IS_RELEASE=false
96+ fi
97+ echo NPM_VERSION=$NPM_VERSION >> $GITHUB_OUTPUT
98+ echo NPM_TAG=$NPM_TAG >> $GITHUB_OUTPUT
99+ echo IS_RELEASE=$IS_RELEASE >> $GITHUB_OUTPUT
52100
53101 - name : Build nativescript
54102 run : npm pack
55-
56- - name : npm ENV
57- env :
58- NPM_TOKEN : ${{ secrets.NPM_PUBLISH_TOKEN }}
59- run : echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
60103
61- - name : Publish next nativescript version
62- if : github.event.inputs.next_version == 'true'
104+ - name : Upload npm package artifact
105+ uses : actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
106+ with :
107+ name : npm-package
108+ path : akylas-nativescript-cli-${{steps.npm_version_output.outputs.NPM_VERSION}}.tgz
109+
110+ publish :
111+ runs-on : ubuntu-latest
112+ environment : npm-publish
113+ needs :
114+ - build
115+ permissions :
116+ contents : read
117+ id-token : write
118+ env :
119+ NPM_VERSION : ${{needs.build.outputs.npm_version}}
120+ NPM_TAG : ${{needs.build.outputs.npm_tag}}
121+ steps :
122+ - name : Harden the runner (Audit all outbound calls)
123+ uses : step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
124+ with :
125+ egress-policy : audit
126+
127+ - uses : actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
128+ with :
129+ node-version : 22.14.0
130+ registry-url : " https://registry.npmjs.org"
131+
132+ - uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
133+ with :
134+ name : npm-package
135+ path : dist
136+
137+ - name : Update npm (required for OIDC trusted publishing)
138+ run : |
139+ npm install -g npm@^11.5.1
140+ npm --version
141+
142+ - name : Publish package (OIDC trusted publishing)
143+ if : ${{ vars.USE_NPM_TOKEN != 'true' }}
63144 run : |
64- echo "Publishing nativescript@$NPM_VERSION to NPM with tag $NPM_TAG..."
65- npm publish akylas-nativescript-cli-$NPM_VERSION.tgz --tag $NPM_TAG
145+ echo "Publishing nativescript@$NPM_VERSION to NPM with tag $NPM_TAG via OIDC trusted publishing..."
146+ unset NODE_AUTH_TOKEN
147+ if [ -n "${NPM_CONFIG_USERCONFIG:-}" ]; then
148+ rm -f "$NPM_CONFIG_USERCONFIG"
149+ fi
150+ npm publish ./dist/akylas-nativescript-cli-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance
151+ env :
152+ NODE_AUTH_TOKEN : " "
66153
67- - name : Publish nativescript
68- if : github.event.inputs.next_version == 'false'
154+ - name : Publish package (granular token)
155+ if : ${{ vars.USE_NPM_TOKEN == 'true' }}
69156 run : |
70- echo "Publishing nativescript@$NPM_VERSION to NPM..."
71- npm publish akylas-nativescript-cli-$NPM_VERSION.tgz
157+ echo "Publishing nativescript@$NPM_VERSION to NPM with tag $NPM_TAG via granular token..."
158+ npm publish ./dist/nativescript-${{env.NPM_VERSION}}.tgz --tag $NPM_TAG --access public --provenance
159+ env :
160+ NODE_AUTH_TOKEN : ${{ secrets.NPM_PUBLISH_TOKEN }}
161+
162+ github-release :
163+ runs-on : ubuntu-latest
164+ # runs for tag pushes and for manual dispatches that bumped a stable release
165+ if : ${{ needs.build.outputs.is_release == 'true' }}
166+ permissions :
167+ contents : write
168+ needs :
169+ - build
170+ env :
171+ NPM_VERSION : ${{needs.build.outputs.npm_version}}
172+ steps :
173+ - name : Harden the runner (Audit all outbound calls)
174+ uses : step-security/harden-runner@fe104658747b27e96e4f7e80cd0a94068e53901d # v2.16.1
175+ with :
176+ egress-policy : audit
177+
178+ - uses : actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
179+ with :
180+ fetch-depth : 0
181+ ref : v${{needs.build.outputs.npm_version}}
72182
73- - name : Push to git
74- if : github.event.inputs.bump_version == 'true'
183+ - uses : actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
184+ with :
185+ node-version : 22.14.0
186+
187+ - name : Setup
188+ run : npm i --ignore-scripts --legacy-peer-deps --no-package-lock
189+
190+ - uses : actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
191+ with :
192+ name : npm-package
193+ path : dist
194+
195+ - name : Generate provenance statement
75196 run : |
76- git push origin --tags
77- git push origin
197+ TGZ_PATH=$(ls dist/nativescript-*.tgz | head -n1)
198+ TGZ_NAME=$(basename "$TGZ_PATH")
199+ TGZ_SHA=$(sha256sum "$TGZ_PATH" | awk '{ print $1 }')
200+ PROV_PATH="dist/${TGZ_NAME%.tgz}.intoto.jsonl"
201+
202+ cat > "$PROV_PATH" <<EOF
203+ {"_type":"https://in-toto.io/Statement/v1","subject":[{"name":"$TGZ_NAME","digest":{"sha256":"$TGZ_SHA"}}],"predicateType":"https://slsa.dev/provenance/v1"}
204+ EOF
205+
206+ - name : Partial Changelog
207+ run : npx conventional-changelog -p angular -r2 > body.md
208+
209+ - uses : ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1.21.0
210+ with :
211+ tag : v${{needs.build.outputs.npm_version}}
212+ artifacts : " dist/nativescript-*.tgz,dist/nativescript-*.intoto.jsonl"
213+ bodyFile : " body.md"
214+ prerelease : ${{needs.build.outputs.npm_tag != 'latest'}}
215+ allowUpdates : true
0 commit comments