Skip to content

Commit 5ccb400

Browse files
authored
fix(ci): let npm-release be dispatched for a tag (#10)
Promoting v1.2.6 out of prerelease fired no workflow run, so the npm publish never happened while the crates one did. The release event is not a reliable trigger, and npm-release had no other way in — the only recovery was editing the release again and hoping. Adds workflow_dispatch with a tag input. Publishing is already idempotent, so a re-dispatch of an published version is a no-op rather than a failure. The release id is now looked up from the tag instead of read off github.event.release.id, which is empty on a dispatch. One code path serves both triggers rather than a second one that only gets exercised in an emergency.
1 parent abc0c02 commit 5ccb400

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

.github/workflows/npm-release.yml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,20 @@ name: NPM release
1414
on:
1515
release:
1616
types: [published, edited]
17+
# Re-dispatch to publish a release the event never reached — promoting a prerelease does not
18+
# always fire `edited`, and without this the only recovery is editing the release again and hoping.
19+
# Publishing is idempotent: a version already on npm is skipped rather than failing.
20+
workflow_dispatch:
21+
inputs:
22+
tag:
23+
description: "Release tag to publish, e.g. v1.2.6"
24+
required: true
25+
type: string
1726

1827
jobs:
1928
publish:
2029
name: Publish to npm
21-
if: github.event.release.prerelease == false
30+
if: ${{ github.event_name == 'workflow_dispatch' || github.event.release.prerelease == false }}
2231
runs-on: ubuntu-latest
2332
permissions:
2433
contents: write # required to update release body via API
@@ -31,9 +40,26 @@ jobs:
3140
- name: Checkout
3241
uses: actions/checkout@v4
3342
with:
34-
ref: refs/tags/${{ github.event.release.tag_name }}
43+
ref: refs/tags/${{ github.event.release.tag_name || inputs.tag }}
3544
fetch-depth: 0
3645

46+
- name: Resolve the release
47+
id: rel
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
run: |
51+
TAG="${{ github.event.release.tag_name || inputs.tag }}"
52+
# `github.event.release.id` is empty on a workflow_dispatch, so look it up by tag — which
53+
# also works for the release event and keeps one code path.
54+
ID=$(curl -sL -H "Authorization: Bearer $GITHUB_TOKEN" \
55+
"https://api.github.com/repos/${{ github.repository }}/releases/tags/$TAG" | jq -r '.id')
56+
if [ -z "$ID" ] || [ "$ID" = "null" ]; then
57+
echo "No release found for tag $TAG"
58+
exit 1
59+
fi
60+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
61+
echo "id=$ID" >> "$GITHUB_OUTPUT"
62+
3763
- name: Download npm package tarball from release
3864
env:
3965
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -45,7 +71,7 @@ jobs:
4571
for attempt in 1 2 3 4 5 6 7 8 9 10; do
4672
DECK_URL=$(curl -sL -H "Authorization: Bearer $GITHUB_TOKEN" \
4773
-H "Accept: application/vnd.github+json" \
48-
"https://api.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}/assets?per_page=100" \
74+
"https://api.github.com/repos/${{ github.repository }}/releases/${{ steps.rel.outputs.id }}/assets?per_page=100" \
4975
| jq -r '.[] | select(.name == "spacedevin-deck-npm-package.tgz" and .state == "uploaded") | .url')
5076
[ -n "$DECK_URL" ] && [ "$DECK_URL" != "null" ] && break
5177
echo "tarball not uploaded yet (attempt $attempt/10) — waiting 30s"
@@ -76,10 +102,10 @@ jobs:
76102
env:
77103
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78104
run: |
79-
TAG="${{ github.event.release.tag_name }}"
105+
TAG="${{ steps.rel.outputs.tag }}"
80106
VERSION="${TAG#v}"
81107
NPM_URL="https://www.npmjs.com/package/@spacedevin/deck/v/${VERSION}"
82-
RELEASE_ID="${{ github.event.release.id }}"
108+
RELEASE_ID="${{ steps.rel.outputs.id }}"
83109
REPO="${{ github.repository }}"
84110
CURRENT_BODY=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
85111
"https://api.github.com/repos/${REPO}/releases/${RELEASE_ID}" | jq -r '.body // ""')

0 commit comments

Comments
 (0)