Repository navigation
140 lines (127 loc) · 6.16 KB
/
Copy pathrelease.yaml
File metadata and controls
140 lines (127 loc) · 6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
name: Release
# Changesets "PR-or-publish" flow:
#
# 1. Developer merges feature PR(s) containing changeset markdown files
# (`.changeset/*.md`) into master.
# 2. This workflow runs on every master push. The Changesets Action detects
# pending changesets and opens (or updates) a "Version Packages" PR that:
# - consumes the `.changeset/*.md` files
# - bumps `package.json#version` for affected packages (respects the
# `fixed` group in `.changeset/config.json` — all @lhx-kit/* bump
# together)
# - generates/updates each package's CHANGELOG.md
# 3. A maintainer reviews and MERGES that Version Packages PR.
# 4. On merge, this same workflow runs again. It finds no pending
# changesets BUT sees the bumped versions, so it goes into "publish"
# mode: runs `pnpm release` which does `pnpm -r build && changeset
# publish`. Packages with `private: true` in their package.json are
# automatically skipped (currently all of them — toggle off when ready).
#
# Why this is safer than "publish on every push":
# - Version bump is a separate, reviewable PR (human checks CHANGELOG).
# - No accidental publish from an unrelated master push.
# - Rollback = revert the Version Packages PR.
#
# Auth to npm: Trusted Publishing via GitHub OIDC.
# - NO NPM_TOKEN secret is needed. npm exchanges this job's OIDC id_token
# (issued because `permissions.id-token: write` is set below) for a
# short-lived publish credential.
# - Prerequisite: each @lhx-kit/* package has a Trusted Publisher
# configured on npmjs.com pointing at:
# org/user = juwenzhang, repo = lhx-kit,
# workflow filename = release.yaml, environment = (empty)
# See .github/SETUP.md for the one-time setup steps.
# - Provenance is still produced automatically (id-token + OIDC = signed).
#
# Required repository secrets:
# - GITHUB_TOKEN — auto-provided by GitHub; needs contents:write + pull-requests:write
# (set in permissions below)
# - REPO_PUSH_TOKEN — optional PAT to push the Version Packages PR onto
# protected branches; falls back to GITHUB_TOKEN.
on:
push:
branches:
- master
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write # push version bump PR + tags
pull-requests: write # open / update the Version Packages PR
id-token: write # npm provenance (optional but recommended)
jobs:
release:
name: Release (Changesets)
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# Full history so changesets can generate accurate changelogs.
fetch-depth: 0
# Default GITHUB_TOKEN cannot push to protected branches. A PAT
# with `contents:write` can be set as REPO_PUSH_TOKEN to bypass;
# fallback here keeps the workflow functional when running in
# forks or without the PAT (just opens PR, does not push tags).
token: ${{ secrets.REPO_PUSH_TOKEN || secrets.GITHUB_TOKEN }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
# version is read from root package.json "packageManager"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
# Needed for npm publish with provenance
registry-url: https://registry.npmjs.org
- name: Upgrade npm to >= 11.5.1 (required for Trusted Publishing)
# Node 22 ships npm 10.x by default, which DOES NOT support the
# OIDC token-exchange endpoint /-/npm/v1/oidc/token/exchange used
# by Trusted Publishing. Publishing will fail with a misleading
# `E404 Not Found - PUT https://registry.npmjs.org/...` even
# after the provenance statement is signed successfully.
#
# Fix: upgrade npm to the latest v11 (>= 11.5.1) which supports
# OIDC Trusted Publishing. Pinned to 11.x because npm 12.x
# requires Node >= 22 and may change behaviour; npm 11 is the
# battle-tested baseline for trusted publishing.
#
# This must run AFTER setup-node so PATH is right, and BEFORE
# the publish step so changesets/action picks up the new npm.
run: npm install -g npm@11
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build packages
# Build happens BEFORE changeset publish so `dist/` is present when
# the publish step packs each package. If the action falls into the
# "open PR" branch (no pending publishes), the build is still
# useful as a smoke test that master is publishable.
run: pnpm -r --filter='./packages/*' build
- name: Create Release PR or publish
id: changesets
uses: changesets/action@v1
with:
# `publish: pnpm release` runs when the "Version Packages" PR is
# merged. It calls `pnpm release` from root → `changeset publish`.
publish: pnpm release
# `version` (omitted) → action uses default `changeset version`,
# which we've aliased in package.json to also run `pnpm install
# --lockfile-only` so the lockfile stays in sync.
version: pnpm run version
commit: "chore(release): version packages"
title: "chore(release): version packages"
createGithubReleases: true
env:
GITHUB_TOKEN: ${{ secrets.REPO_PUSH_TOKEN || secrets.GITHUB_TOKEN }}
# No NPM_TOKEN — Trusted Publishing (OIDC) is used instead.
# Provenance is implicit when publishing via OIDC; keeping the
# explicit flag makes intent obvious and is a no-op duplicate.
NPM_CONFIG_PROVENANCE: "true"
- name: Summary
if: always()
run: |
echo "### Changesets result" >> "$GITHUB_STEP_SUMMARY"
echo "- published: ${{ steps.changesets.outputs.published }}" >> "$GITHUB_STEP_SUMMARY"
echo "- publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}" >> "$GITHUB_STEP_SUMMARY"
echo "- hasChangesets: ${{ steps.changesets.outputs.hasChangesets }}" >> "$GITHUB_STEP_SUMMARY"