Skip to content

Commit 1c41352

Browse files
authored
Merge pull request #18 from aredotna/publishing
Sets up publishing workflow
2 parents 4b704ee + fdba78e commit 1c41352

2 files changed

Lines changed: 112 additions & 47 deletions

File tree

.github/workflows/publish.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Publish
2+
3+
on:
4+
pull_request_target:
5+
types: [closed]
6+
7+
concurrency:
8+
group: release-main
9+
cancel-in-progress: false
10+
11+
jobs:
12+
publish:
13+
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
id-token: write
18+
19+
steps:
20+
- name: Determine release bump from labels
21+
id: release_meta
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
const labels = (context.payload.pull_request.labels || []).map((label) => label.name);
26+
const candidates = ["major", "minor", "patch"];
27+
const matched = candidates.filter((candidate) => labels.includes(candidate));
28+
29+
if (matched.length === 0) {
30+
core.notice("No release label found (major|minor|patch). Skipping publish.");
31+
core.setOutput("should_release", "false");
32+
return;
33+
}
34+
35+
if (matched.length > 1) {
36+
core.setFailed(`Multiple release labels found: ${matched.join(", ")}. Keep exactly one of major|minor|patch.`);
37+
return;
38+
}
39+
40+
core.info(`Selected release bump: ${matched[0]}`);
41+
core.setOutput("should_release", "true");
42+
core.setOutput("bump", matched[0]);
43+
44+
- uses: actions/checkout@v4
45+
if: steps.release_meta.outputs.should_release == 'true'
46+
with:
47+
ref: main
48+
fetch-depth: 0
49+
50+
- uses: actions/setup-node@v4
51+
if: steps.release_meta.outputs.should_release == 'true'
52+
with:
53+
node-version: 20
54+
cache: npm
55+
registry-url: https://registry.npmjs.org
56+
57+
- run: npm ci
58+
if: steps.release_meta.outputs.should_release == 'true'
59+
60+
- run: npm run check
61+
if: steps.release_meta.outputs.should_release == 'true'
62+
env:
63+
ARENA_VCR_MODE: replay
64+
ARENA_API_URL: https://staging-api.are.na
65+
66+
- name: Configure git author
67+
if: steps.release_meta.outputs.should_release == 'true'
68+
run: |
69+
git config user.name "github-actions[bot]"
70+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
71+
72+
- name: Bump version and create tag
73+
id: version
74+
if: steps.release_meta.outputs.should_release == 'true'
75+
run: |
76+
NEW_TAG="$(npm version "${{ steps.release_meta.outputs.bump }}" -m "release: %s")"
77+
echo "tag=${NEW_TAG}" >> "$GITHUB_OUTPUT"
78+
79+
- name: Push release commit and tags
80+
if: steps.release_meta.outputs.should_release == 'true'
81+
run: git push origin HEAD:main --follow-tags
82+
83+
- run: npm publish --provenance --access public
84+
if: steps.release_meta.outputs.should_release == 'true'
85+
86+
- name: Create GitHub Release
87+
if: steps.release_meta.outputs.should_release == 'true'
88+
env:
89+
GH_TOKEN: ${{ github.token }}
90+
run: gh release create "${{ steps.version.outputs.tag }}" --generate-notes

RELEASE.md

Lines changed: 22 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,56 @@
22

33
Use this checklist to cut a new npm release for `@aredotna/cli`.
44

5+
Publishing is automated by GitHub Actions when a PR with a release label is merged to `main`.
6+
Use exactly one label on the PR: `major`, `minor`, or `patch`.
7+
The workflow bumps the version, publishes to npm with trusted publishing (OIDC), pushes the release commit and tag, and creates a GitHub Release.
8+
59
## 1) Preflight
610

7-
- [ ] Ensure you are on the intended release branch:
11+
- [ ] Ensure release label is present on the PR:
812

913
```bash
10-
git branch --show-current
14+
gh pr view --json labels --jq '.labels[].name'
1115
```
1216

13-
- [ ] Ensure working tree is clean:
14-
15-
```bash
16-
git status --short
17-
```
17+
- [ ] Verify exactly one of `major|minor|patch` is set.
1818

19-
- [ ] Run full checks:
19+
- [ ] (Optional) Run full checks locally before merge:
2020

2121
```bash
2222
npm run check
2323
```
2424

25-
## 2) Confirm npm auth
26-
27-
- [ ] Verify npm login:
25+
## 2) Merge the PR to `main`
2826

29-
```bash
30-
npm whoami
31-
```
32-
33-
If this fails with `401 Unauthorized`, authenticate first:
34-
35-
```bash
36-
npm login
37-
```
27+
- [ ] Merge the labeled PR.
3828

39-
## 3) Bump version
40-
41-
- [ ] Choose version type (`patch`, `minor`, `major`) and bump:
42-
43-
```bash
44-
npm version patch
45-
```
46-
47-
This updates `package.json`, creates a release commit, and creates a git tag.
48-
49-
## 4) Publish package
50-
51-
- [ ] Publish to npm:
52-
53-
```bash
54-
npm publish
55-
```
29+
This triggers `.github/workflows/publish.yml`.
5630

57-
## 5) Push commit + tag
31+
## 3) Confirm publish workflow success
5832

59-
- [ ] Push branch and tags:
33+
- [ ] Wait for the "Publish" workflow on the pushed tag to complete successfully:
6034

6135
```bash
62-
git push origin "$(git branch --show-current)" --follow-tags
36+
gh run list --workflow publish.yml --limit 5
6337
```
6438

65-
## 6) Verify release
39+
## 4) Verify release
6640

6741
- [ ] Check published version:
6842

6943
```bash
7044
npm view @aredotna/cli version
7145
```
7246

73-
- [ ] Confirm tag exists remotely:
47+
- [ ] Verify GitHub Release exists for the tag:
7448

7549
```bash
76-
git ls-remote --tags origin | tail
50+
VERSION="$(npm view @aredotna/cli version)"
51+
gh release view "v${VERSION}"
7752
```
7853

79-
## 7) Optional post-release smoke test
54+
## 5) Optional post-release smoke test
8055

8156
- [ ] Install latest globally:
8257

@@ -93,6 +68,6 @@ arena whoami --json
9368

9469
## Troubleshooting
9570

96-
- `npm whoami` fails with 401: run `npm login` and retry.
97-
- `npm publish` says version exists: bump again (`npm version patch`) and republish.
98-
- Push fails due to remote changes: rebase/merge branch, rerun checks, then push again.
71+
- Publish job fails with OIDC/trusted publishing error: verify trusted publisher settings on npm exactly match `aredotna/cli` and workflow file `publish.yml`.
72+
- Workflow skips publishing: merged PR did not contain one of `major`, `minor`, or `patch` labels.
73+
- Workflow fails with multiple release labels: keep exactly one of `major|minor|patch` on the PR.

0 commit comments

Comments
 (0)