Skip to content

Commit 43530c0

Browse files
committed
Address review comments
Signed-off-by: Varun Sharma <varunsh@stepsecurity.io>
1 parent 611b7ac commit 43530c0

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

.github/workflows/npm-publish.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,30 @@ jobs:
1919
with:
2020
ref: ${{ github.event.inputs.tag }}
2121

22-
- name: Match semver pattern
23-
uses: actions-ecosystem/action-regex-match@v2
24-
id: regex-match
25-
with:
26-
text: ${{ github.event.inputs.tag }}
27-
regex: '^v((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$'
28-
2922
- name: Check package version
3023
id: cpv
3124
uses: PostHog/check-package-version@v2
3225

26+
- run: npm install semver
27+
3328
- name: Validate tag
3429
uses: actions/github-script@v6
3530
with:
3631
script: |
37-
const match = `${{ steps.regex-match.outputs.match }}`;
38-
if(match === '') {
39-
core.setFailed(`Tag ${context.payload.inputs.tag} does not match semver pattern`);
40-
} else {
32+
const semver = require('semver')
33+
34+
const tag = `${context.payload.inputs.tag}`;
35+
const version = tag.substring(1);
36+
37+
if (semver.valid(version)) {
4138
const isNewVersion = `${{ steps.cpv.outputs.is-new-version }}`;
42-
if(isNewVersion === 'true') {
39+
if (isNewVersion === 'true') {
4340
console.log(`Version ${context.payload.inputs.tag} has not been published yet`);
4441
} else {
4542
core.setFailed(`Version ${context.payload.inputs.tag} is already published`);
4643
}
44+
} else {
45+
core.setFailed(`Tag ${context.payload.inputs.tag} does not match semver pattern`);
4746
}
4847
check-status:
4948
needs: check-version
@@ -86,7 +85,7 @@ jobs:
8685
});
8786
8887
for (const check_run of check_runs.data.check_runs) {
89-
if (!(check_run.status === 'completed' && check_run.conclusion === 'success')){
88+
if (check_run.status !== 'completed' || check_run.conclusion !== 'success') {
9089
console.log(`${check_run.name} check failed`);
9190
core.setFailed(`Required status check ${check_run.name} did not succeed`);
9291
}
@@ -107,19 +106,23 @@ jobs:
107106
allowed-endpoints: >
108107
github.com:443
109108
hooks.slack.com:443
109+
nodejs.org:443
110110
prod.api.stepsecurity.io:443
111111
registry.npmjs.org:443
112112
113113
- uses: actions/checkout@v3
114114
with:
115115
ref: ${{ github.event.inputs.tag }}
116116

117-
- uses: actions/setup-node@v3
117+
- uses: ljharb/actions/node/install@main
118+
name: "nvm install lts/* && npm install"
118119
with:
119-
node-version: "16.x"
120-
registry-url: "https://registry.npmjs.org"
120+
node-version: "lts/*"
121+
env:
122+
NPM_CONFIG_LEGACY_PEER_DEPS: true
121123

122-
- run: npm install
124+
- run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NODE_AUTH_TOKEN }}" >> .npmrc
125+
- run: npm publish --dry-run
123126

124127
- uses: step-security/wait-for-secrets@v1
125128
id: wait-for-secrets
@@ -131,5 +134,3 @@ jobs:
131134
description: 'OTP from authenticator app'
132135
133136
- run: npm publish --access public --otp ${{ steps.wait-for-secrets.outputs.OTP }}
134-
env:
135-
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}

0 commit comments

Comments
 (0)