Skip to content

Commit 82f1e6e

Browse files
committed
Improve error handling and npm auth in release workflows
1 parent 26d9260 commit 82f1e6e

File tree

2 files changed

+94
-22
lines changed

2 files changed

+94
-22
lines changed

.github/workflows/canary.yml

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ jobs:
7474
for (const name of pkgs) {
7575
const v = versions[name];
7676
if (!v) continue;
77-
const info = JSON.parse(execSync('npm view ' + name + '@' + v + ' version dist.tarball gitHead --json').toString());
78-
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
79-
out[name] = { version: info.version, tarball: info.dist?.tarball, gitHead: info.gitHead, distTags: tags };
77+
try {
78+
const info = JSON.parse(execSync('npm view ' + name + '@' + v + ' version dist.tarball gitHead --json').toString());
79+
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
80+
out[name] = { version: info.version, tarball: info.dist?.tarball, gitHead: info.gitHead, distTags: tags };
81+
} catch (err) {
82+
console.error('Failed to get npm info for', name, ':', err.message);
83+
out[name] = { error: err.message, version: v };
84+
}
8085
}
8186
process.stdout.write('info='+JSON.stringify(out));
8287
" >> $GITHUB_OUTPUT
@@ -93,19 +98,29 @@ jobs:
9398
for (const name of pkgs) {
9499
const expected = info?.[name]?.version;
95100
if (!expected) continue;
96-
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
97-
const isPrerelease = /-/.test(expected);
98-
if (isPrerelease) {
99-
if (tags.next !== expected) {
100-
console.error(`[next] Dist-tag mismatch for ${name}: next=${tags.next} expected=${expected}`);
101-
process.exit(1);
101+
try {
102+
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
103+
const isPrerelease = /-/.test(expected);
104+
if (isPrerelease) {
105+
if (tags.next !== expected) {
106+
console.error(`[next] Dist-tag mismatch for ${name}: next=${tags.next} expected=${expected}`);
107+
process.exit(1);
108+
}
109+
} else {
110+
if (!tags.next) {
111+
console.error(`[next] Dist-tag missing for ${name}: expected a 'next' tag to exist`);
112+
process.exit(1);
113+
}
114+
console.log(`[next] Skipping strict next match for ${name} (stable version ${expected}).`);
102115
}
103-
} else {
104-
if (!tags.next) {
105-
console.error(`[next] Dist-tag missing for ${name}: expected a 'next' tag to exist`);
106-
process.exit(1);
116+
} catch (err) {
117+
console.error('Failed to verify dist-tags for', name, ':', err.message);
118+
// Don't fail the workflow if package doesn't exist yet
119+
if (err.message.includes('404') || err.message.includes('No match found')) {
120+
console.log(`[next] Package ${name} not found on npm yet, skipping verification`);
121+
continue;
107122
}
108-
console.log(`[next] Skipping strict next match for ${name} (stable version ${expected}).`);
123+
process.exit(1);
109124
}
110125
}
111126
console.log('Next dist-tags verified.');

.github/workflows/release.yml

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ jobs:
3939
pnpm turbo run compile
4040
pnpm turbo run test
4141
42+
- name: Configure npm auth (stable)
43+
env:
44+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
45+
run: |
46+
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
47+
npm config set registry https://registry.npmjs.org/
48+
49+
- name: Debug npm auth (stable)
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
run: |
53+
echo "Registry: $(npm config get registry)"
54+
echo "NPM_TOKEN length: ${#NPM_TOKEN}"
55+
npm whoami || echo "npm whoami failed - checking token"
56+
test -n "$NODE_AUTH_TOKEN" || (echo "NODE_AUTH_TOKEN missing" && exit 1)
57+
4258
- name: Publish packages to npm
4359
id: changesets
4460
uses: changesets/action@v1
@@ -50,7 +66,7 @@ jobs:
5066
createGithubReleases: true
5167
env:
5268
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
69+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
5470

5571
- name: Debug npm auth (stable)
5672
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.published != 'true' }}
@@ -78,9 +94,14 @@ jobs:
7894
for (const name of pkgs) {
7995
const v = versions[name];
8096
if (!v) continue;
81-
const info = JSON.parse(execSync('npm view ' + name + '@' + v + ' version dist.tarball gitHead --json').toString());
82-
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
83-
out[name] = { version: info.version, tarball: info.dist?.tarball, gitHead: info.gitHead, distTags: tags };
97+
try {
98+
const info = JSON.parse(execSync('npm view ' + name + '@' + v + ' version dist.tarball gitHead --json').toString());
99+
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
100+
out[name] = { version: info.version, tarball: info.dist?.tarball, gitHead: info.gitHead, distTags: tags };
101+
} catch (err) {
102+
console.error('Failed to get npm info for', name, ':', err.message);
103+
out[name] = { error: err.message };
104+
}
84105
}
85106
process.stdout.write('info='+JSON.stringify(out));
86107
" >> $GITHUB_OUTPUT
@@ -97,9 +118,14 @@ jobs:
97118
for (const name of pkgs) {
98119
const expected = versions[name];
99120
if (!expected) continue;
100-
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
101-
if (tags.latest !== expected) {
102-
console.error(`[stable] Dist-tag mismatch for ${name}: latest=${tags.latest} expected=${expected}`);
121+
try {
122+
const tags = JSON.parse(execSync('npm view ' + name + ' dist-tags --json').toString());
123+
if (tags.latest !== expected) {
124+
console.error(`[stable] Dist-tag mismatch for ${name}: latest=${tags.latest} expected=${expected}`);
125+
process.exit(1);
126+
}
127+
} catch (err) {
128+
console.error('Failed to verify dist-tags for', name, ':', err.message);
103129
process.exit(1);
104130
}
105131
}
@@ -185,4 +211,35 @@ jobs:
185211
log_url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`,
186212
environment_url: envUrl,
187213
description: desc
188-
})
214+
});
215+
216+
- name: Create deployment (stable - failed publish)
217+
if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.published != 'true' }}
218+
uses: actions/github-script@v7
219+
env:
220+
VERSIONS: ${{ steps.versions.outputs.versions }}
221+
with:
222+
script: |
223+
const { owner, repo } = context.repo;
224+
const payload = {
225+
channel: 'stable',
226+
distTag: 'latest',
227+
versions: JSON.parse(process.env.VERSIONS || '{}'),
228+
error: 'npm publish failed'
229+
};
230+
const ref = context.sha;
231+
const dep = await github.rest.repos.createDeployment({
232+
owner, repo, ref,
233+
environment: 'stable',
234+
auto_merge: false,
235+
required_contexts: [],
236+
transient_environment: false,
237+
description: `npm publish failed`,
238+
payload: JSON.stringify(payload)
239+
});
240+
await github.rest.repos.createDeploymentStatus({
241+
owner, repo, deployment_id: dep.data.id,
242+
state: 'failure',
243+
log_url: `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`,
244+
description: 'npm publish failed - check workflow logs'
245+
});

0 commit comments

Comments
 (0)