Skip to content

Commit 8788405

Browse files
authored
Merge pull request #1714 from input-output-hk/ci/idempotent-release-recovery
ci: make release workflow idempotent & recoverable
2 parents c750551 + 810d1f2 commit 8788405

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

.github/workflows/release.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ jobs:
1111
runs-on: ${{ matrix.os }}
1212
steps:
1313
- name: 📥 Checkout repository
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
# Fetch all history for all tags and branches
1717
fetch-depth: 0
1818
ref: master
1919
token: ${{ secrets.BOT_GH_TOKEN }}
2020

2121
- name: 🧰 Setup Node.js
22-
uses: actions/setup-node@v1
22+
uses: actions/setup-node@v4
2323
with:
2424
node-version: 18.12.0
2525
registry-url: 'https://registry.npmjs.org'
2626

2727
- name: Import bot's GPG key for signing commits
2828
id: import-gpg
29-
uses: crazy-max/ghaction-import-gpg@v5
29+
uses: crazy-max/ghaction-import-gpg@v6
3030
with:
3131
gpg_private_key: ${{ secrets.BOT_GPG_KEY }}
3232
git_config_global: true
@@ -44,11 +44,24 @@ jobs:
4444
run: |
4545
yarn build
4646
47-
- name: Publish
47+
# Phase 1 — decide versions, commit, tag, push to master, and create GitHub Releases.
48+
# No-ops when there are no new conventional commits (e.g. re-running after a publish
49+
# failure), so it never double-bumps an already-versioned release.
50+
- name: 🏷️ Version
4851
run: |
49-
if [ $RELEASE_MODE = "stable" ]; then yarn publish:stable; else yarn publish:rc; fi
52+
if [ "$RELEASE_MODE" = "stable" ]; then yarn version:stable; else yarn version:rc; fi
5053
env:
51-
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
5254
# Used for making a GitHub Release
5355
GH_TOKEN: ${{ secrets.BOT_GH_TOKEN }}
5456
RELEASE_MODE: ${{ vars.RELEASE_MODE }}
57+
58+
# Phase 2 — publish to npm via `lerna publish from-package`, which queries the registry
59+
# and publishes ONLY versions that are not yet there. This makes the job idempotent and
60+
# recoverable: if a previous run versioned/tagged but failed to publish, simply re-running
61+
# the workflow ships the missing packages without touching git history.
62+
- name: 📦 Publish to npm
63+
run: |
64+
if [ "$RELEASE_MODE" = "stable" ]; then yarn publish:stable; else yarn publish:rc; fi
65+
env:
66+
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
67+
RELEASE_MODE: ${{ vars.RELEASE_MODE }}

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
"prepare": "husky install",
3333
"prepublishOnly": "find . -type f -name package.json | grep -v node_modules | while read -r f ; do cat $f | jq 'del(.exports[\".\"].development)' > /tmp/package.json && mv /tmp/package.json $f; done",
3434
"version": "yarn install --mode=skip-build && git add yarn.lock",
35-
"publish:rc": "lerna publish --conventional-prerelease --allow-branch master --preid rc --pre-dist-tag rc --create-release github -m \"ci: publish rc packages [skip actions]\" --sign-git-commit",
36-
"publish:stable": "lerna publish --conventional-graduate --allow-branch master --create-release github -m \"ci: publish packages [skip actions]\" --sign-git-commit",
35+
"version:rc": "lerna version --conventional-prerelease --allow-branch master --preid rc --create-release github -m \"ci: publish rc packages [skip actions]\" --sign-git-commit",
36+
"version:stable": "lerna version --conventional-graduate --allow-branch master --create-release github -m \"ci: publish packages [skip actions]\" --sign-git-commit",
37+
"publish:rc": "lerna publish from-package --dist-tag rc --yes",
38+
"publish:stable": "lerna publish from-package --yes",
3739
"test": "yarn workspaces foreach -v run test",
3840
"test:build:verify": "yarn workspaces foreach -v run test:build:verify",
3941
"test:e2e": "yarn workspaces foreach -v run test:e2e",

0 commit comments

Comments
 (0)