Skip to content

Commit 21cc2f5

Browse files
authored
Make release publishing explicit and retry-safe (#18)
Separate Changesets versioning from npm publishing, make retries idempotent, and create GitHub releases explicitly.
1 parent 70164be commit 21cc2f5

1 file changed

Lines changed: 51 additions & 4 deletions

File tree

.github/workflows/release.yml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,59 @@ jobs:
7373
- name: Verify npm package contents
7474
run: npm pack --dry-run --json
7575

76-
- name: Create version PR or publish to npm
77-
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run)
76+
- name: Detect pending changesets
77+
id: changesets
78+
shell: bash
79+
run: |
80+
shopt -s nullglob
81+
files=(.changeset/*.md)
82+
if (( ${#files[@]} > 0 )); then
83+
echo "pending=true" >> "$GITHUB_OUTPUT"
84+
else
85+
echo "pending=false" >> "$GITHUB_OUTPUT"
86+
fi
87+
88+
- name: Create or update version PR
89+
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.pending == 'true'
7890
uses: changesets/action@v1
7991
with:
8092
version: bun run version-packages
81-
publish: npm publish --access public --provenance
82-
createGithubReleases: true
8393
env:
8494
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
96+
- name: Read package metadata
97+
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.pending == 'false'
98+
id: package
99+
shell: bash
100+
run: |
101+
echo "name=$(node -p "require('./package.json').name")" >> "$GITHUB_OUTPUT"
102+
echo "version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
103+
104+
- name: Check whether package version is already published
105+
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.pending == 'false'
106+
id: registry
107+
shell: bash
108+
run: |
109+
if npm view "${{ steps.package.outputs.name }}@${{ steps.package.outputs.version }}" version >/dev/null 2>&1; then
110+
echo "published=true" >> "$GITHUB_OUTPUT"
111+
else
112+
echo "published=false" >> "$GITHUB_OUTPUT"
113+
fi
114+
115+
- name: Publish package to npm
116+
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.pending == 'false' && steps.registry.outputs.published == 'false'
117+
run: npm publish --access public --provenance
118+
119+
- name: Create GitHub release
120+
if: github.ref == 'refs/heads/main' && !(github.event_name == 'workflow_dispatch' && inputs.dry_run) && steps.changesets.outputs.pending == 'false'
121+
env:
122+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123+
VERSION: ${{ steps.package.outputs.version }}
124+
shell: bash
125+
run: |
126+
tag="v${VERSION}"
127+
if gh release view "$tag" >/dev/null 2>&1; then
128+
echo "GitHub release $tag already exists"
129+
else
130+
gh release create "$tag" --target "$GITHUB_SHA" --title "$tag" --generate-notes
131+
fi

0 commit comments

Comments
 (0)