Skip to content

Commit d471de8

Browse files
yoannmoinetclaude
andcommitted
ci: rewrite release workflow with channel support and OIDC publish
- Trigger on 'released' (ignores drafts) + manual dispatch - Channel support: 'latest' (from master only) and 'dev' (any branch) - Version validation: no override for latest on master, dev must match x.y.z-dev.N pattern - Publish via yarn workspace npm publish with --provenance (OIDC, no token) - Full git history (fetch-depth: 0) for version operations - Playwright install for e2e tests before publish Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 092344e commit d471de8

1 file changed

Lines changed: 77 additions & 17 deletions

File tree

.github/workflows/release.yaml

Lines changed: 77 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ name: Release
22

33
on:
44
release:
5-
types: [published]
5+
types: [released]
66
workflow_dispatch:
77
inputs:
8+
channel:
9+
description: 'Publish channel'
10+
required: true
11+
default: 'dev'
12+
type: choice
13+
options:
14+
- latest
15+
- dev
816
version:
9-
description: 'Version to publish (e.g. 1.0.0). Leave empty to use the version from package.json.'
17+
description: 'Version to publish (leave empty to use package.json version)'
1018
required: false
1119
type: string
1220

@@ -15,40 +23,88 @@ jobs:
1523
name: Publish to NPM
1624
runs-on: ubuntu-latest
1725

18-
# Only run on master — for releases, check the target branch; for manual dispatch, check the ref
19-
if: >-
20-
(github.event_name == 'release' && github.event.release.target_commitish == 'master') ||
21-
(github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master')
22-
2326
permissions:
2427
contents: write
2528
id-token: write
2629

2730
steps:
2831
- uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
2934

3035
- name: Install Node
3136
uses: actions/setup-node@v4
3237
with:
3338
node-version-file: 'package.json'
3439
registry-url: 'https://registry.npmjs.org'
3540

41+
- name: Validate and set channel
42+
id: channel
43+
run: |
44+
CHANNEL="${{ github.event.inputs.channel || 'latest' }}"
45+
46+
if [ "${{ github.event_name }}" = "release" ]; then
47+
BRANCH="${{ github.event.release.target_commitish }}"
48+
else
49+
BRANCH="${{ github.ref_name }}"
50+
fi
51+
52+
if [ "$CHANNEL" = "latest" ] && [ "$BRANCH" != "master" ]; then
53+
echo "Error: 'latest' channel can only be published from 'master'."
54+
echo "Current branch: $BRANCH"
55+
exit 1
56+
fi
57+
58+
echo "channel=$CHANNEL" >> $GITHUB_OUTPUT
59+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
60+
echo "Publishing to channel: $CHANNEL from branch: $BRANCH"
61+
62+
- name: Validate and set version
63+
id: version
64+
env:
65+
INPUT_VERSION: ${{ github.event.inputs.version }}
66+
CHANNEL: ${{ steps.channel.outputs.channel }}
67+
BRANCH: ${{ steps.channel.outputs.branch }}
68+
run: |
69+
if [ -n "$INPUT_VERSION" ]; then
70+
echo "Using provided version: $INPUT_VERSION"
71+
72+
if [ "$BRANCH" = "master" ] && [ "$CHANNEL" = "latest" ]; then
73+
echo "Error: Cannot override version for 'latest' on master. Use package.json version."
74+
exit 1
75+
fi
76+
77+
if [ "$CHANNEL" = "dev" ]; then
78+
if ! echo "$INPUT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-dev\.[0-9]+$'; then
79+
echo "Error: Dev versions must match x.y.z-dev.N (e.g. 1.0.1-dev.0)"
80+
exit 1
81+
fi
82+
fi
83+
84+
echo "version=$INPUT_VERSION" >> $GITHUB_OUTPUT
85+
echo "has_version=true" >> $GITHUB_OUTPUT
86+
else
87+
echo "No version provided, using package.json"
88+
echo "has_version=false" >> $GITHUB_OUTPUT
89+
fi
90+
3691
- run: yarn install
3792

3893
- name: Install Playwright
3994
run: yarn workspace @nipple/tests playwright install --with-deps
4095

41-
- name: Update version
42-
if: inputs.version != ''
43-
working-directory: packages/nipplejs
96+
- name: Set version
97+
if: steps.version.outputs.has_version == 'true'
4498
env:
45-
RELEASE_VERSION: ${{ inputs.version }}
46-
run: npm version "$RELEASE_VERSION" --no-git-tag-version
99+
RELEASE_VERSION: ${{ steps.version.outputs.version }}
100+
run: |
101+
cd packages/nipplejs
102+
npm version "$RELEASE_VERSION" --no-git-tag-version
47103
48104
- name: Commit version bump
49-
if: inputs.version != ''
105+
if: steps.version.outputs.has_version == 'true'
50106
env:
51-
RELEASE_VERSION: ${{ inputs.version }}
107+
RELEASE_VERSION: ${{ steps.version.outputs.version }}
52108
run: |
53109
git config user.name "github-actions[bot]"
54110
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
@@ -63,7 +119,11 @@ jobs:
63119
- run: yarn test:e2e
64120

65121
- name: Publish
66-
working-directory: packages/nipplejs
67-
run: npm publish --provenance --access public
68122
env:
69-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
123+
CHANNEL: ${{ steps.channel.outputs.channel }}
124+
run: |
125+
if [ "$CHANNEL" = "dev" ]; then
126+
yarn workspace nipplejs npm publish --provenance --access public --tag dev
127+
else
128+
yarn workspace nipplejs npm publish --provenance --access public
129+
fi

0 commit comments

Comments
 (0)