Skip to content

Commit f31ef54

Browse files
SenseyeSergiu Oala
andauthored
chore: dipatch npm-publish from release-pleas (#117)
Co-authored-by: Sergiu Oala <soala@netflix.com>
1 parent 7e94768 commit f31ef54

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

‎.github/workflows/npm-publish.yml‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
name: npm-publish
22

33
on:
4-
release:
5-
types: [published]
64
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: >-
8+
Release tag to publish, for example v1.0.0. Leave empty to run
9+
validation only (dry run).
10+
type: string
711

812
permissions:
913
contents: read
1014

1115
concurrency:
12-
# tag_name grouping - queues actual releases for the same tag
13-
# run_id - fallback value required for group as tag_name might not always be present (manual triggers)
14-
group: npm-publish-${{ github.event.release.tag_name || github.run_id }}
16+
# tag grouping - queues repeat publishes of the same release
17+
# run_id - fallback for validation-only runs, which have no tag
18+
group: npm-publish-${{ inputs.tag || github.run_id }}
1519
cancel-in-progress: false
1620

1721
jobs:
@@ -21,29 +25,28 @@ jobs:
2125
steps:
2226
- uses: actions/checkout@v7
2327
with:
24-
ref: ${{ github.event.release.tag_name || github.ref }}
28+
ref: ${{ inputs.tag || github.ref }}
2529
persist-credentials: false
2630

2731
- uses: actions/setup-node@v7
2832
with:
29-
node-version: 22.x
33+
node-version: 26.x
3034

3135
- name: verify release version
32-
if: github.event_name == 'release'
36+
if: inputs.tag != ''
3337
run: |
3438
pkg_name=$(jq -r .name package.json)
3539
pkg_version=$(jq -r .version package.json)
36-
tag_version="${GITHUB_EVENT_RELEASE_TAG_NAME#v}"
37-
if [ "$pkg_version" != "$tag_version" ]; then
38-
echo "package.json version ($pkg_version) does not match release tag ($tag_version)"
40+
if [ "v${pkg_version}" != "$RELEASE_TAG" ]; then
41+
echo "package.json version ($pkg_version) does not match release tag ($RELEASE_TAG)"
3942
exit 1
4043
fi
4144
if npm view "${pkg_name}@${pkg_version}" version >/dev/null 2>&1; then
4245
echo "${pkg_name}@${pkg_version} is already published"
4346
exit 1
4447
fi
4548
env:
46-
GITHUB_EVENT_RELEASE_TAG_NAME: ${{ github.event.release.tag_name }}
49+
RELEASE_TAG: ${{ inputs.tag }}
4750

4851
- name: validate publish package contents
4952
run: |
@@ -55,7 +58,7 @@ jobs:
5558
publish:
5659
name: publish
5760
needs: validate
58-
if: github.event_name == 'release'
61+
if: inputs.tag != ''
5962
runs-on: ubuntu-latest
6063
environment: Publish
6164
permissions:
@@ -64,12 +67,12 @@ jobs:
6467
steps:
6568
- uses: actions/checkout@v7
6669
with:
67-
ref: ${{ github.event.release.tag_name }}
70+
ref: ${{ inputs.tag }}
6871
persist-credentials: false
6972

7073
- uses: actions/setup-node@v7
7174
with:
72-
node-version: 22.x
75+
node-version: 26.x
7376
registry-url: https://registry.npmjs.org
7477

7578
- name: publish to npm

‎.github/workflows/release-please.yml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,25 @@ permissions:
77
contents: write
88
issues: write
99
pull-requests: write
10+
# Releases created with GITHUB_TOKEN cannot trigger other workflows, so
11+
# npm-publish is dispatched explicitly below. workflow_dispatch is one of the
12+
# few events that always creates a run, even from GITHUB_TOKEN.
13+
actions: write
1014
jobs:
1115
release-please:
1216
runs-on: ubuntu-latest
1317
steps:
1418
- uses: googleapis/release-please-action@v5
19+
id: release
1520
with:
1621
release-type: node
22+
23+
# releases_created is only true on the run that tagged a release, which is
24+
# the run triggered by merging the release PR.
25+
- name: trigger npm-publish
26+
if: steps.release.outputs.releases_created == 'true'
27+
env:
28+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
GH_REPO: ${{ github.repository }}
30+
TAG: ${{ steps.release.outputs.tag_name }}
31+
run: gh workflow run npm-publish.yml --ref "$GITHUB_REF_NAME" -f tag="$TAG"

‎README.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,15 @@ If you have style errors, you can auto fix whitespace issues by running:
543543
make codestyle-fix
544544
```
545545

546+
### Releasing
547+
548+
Releases are automated with [release-please](https://github.com/googleapis/release-please#readme):
549+
550+
1. Merge conventional-commit-style PRs (`fix:`, `feat:`, etc.) into `master`.
551+
2. `release-please` opens or updates a Release PR with the version bump and changelog.
552+
3. Review and merge the Release PR when ready to ship.
553+
4. `release-please` tags the release and dispatches the `npm-publish` workflow, which validates and publishes the package to npm.
554+
546555
## License
547556

548557
Copyright (c) 2018 Alex Liu

0 commit comments

Comments
 (0)