-
Notifications
You must be signed in to change notification settings - Fork 177
179 lines (154 loc) · 6.46 KB
/
Copy pathrelease.yml
File metadata and controls
179 lines (154 loc) · 6.46 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
name: Release
on:
push:
branches:
- main
workflow_dispatch:
inputs:
baseline_ref:
description: "Override baseline (commit SHA or tag) for the changeset generator. Leave empty to use the latest release-* tag."
required: false
env:
NODE_VERSION: lts/jod
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
hasReleases: ${{ steps.detect.outputs.hasReleases }}
pendingReleases: ${{ steps.detect.outputs.pendingReleases }}
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.RELEASE_PLEASE_AUTH }}
- name: Install pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- name: Set up node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ env.NODE_VERSION }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Generate changesets from conventional commits
env:
BASELINE_REF: ${{ inputs.baseline_ref }}
run: node tools/scripts/commits-to-changesets.mjs
# Runs BEFORE the changesets action so it reads main's working tree
# (the action may switch the working dir to its PR branch).
- name: Detect pending releases
id: detect
run: |
PENDING=$(node tools/scripts/detect-pending-releases.mjs)
echo "pendingReleases=$PENDING" >> "$GITHUB_OUTPUT"
if [ "$PENDING" = "[]" ]; then
echo "hasReleases=false" >> "$GITHUB_OUTPUT"
else
echo "hasReleases=true" >> "$GITHUB_OUTPUT"
fi
echo "Pending releases: $PENDING"
# Version-only mode: opens/updates the changeset-release/main version PR
# when .changeset/*.md files exist. No publish step — job 2 handles
# npm publishing and GitHub releases with the right tag format.
- name: Changesets action
uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1.8.0
with:
version: pnpm changeset:version
commit: "chore(main): release"
title: "chore(main): release"
createGithubReleases: false
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_PLEASE_AUTH }}
publish:
runs-on: ubuntu-latest
needs: release
if: needs.release.outputs.hasReleases == 'true'
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
fetch-depth: 0
fetch-tags: true
token: ${{ secrets.RELEASE_PLEASE_AUTH }}
- name: Install pnpm
uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8
- name: Set up node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: "https://registry.npmjs.org"
cache: pnpm
# Trusted publishing requires npm >= 11.5.1
- run: npm install -g npm@~11.10.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Get publishable libs
id: get-libs
run: |
LIBS_CSV=$(node -e "const nx = require('./nx.json'); console.log(nx.release.projects.map(p => p.replace('libs/', '')).join(','))")
LIBS_SPACE=$(node -e "const nx = require('./nx.json'); console.log(nx.release.projects.map(p => p.replace('libs/', '')).join(' '))")
echo "libs_csv=$LIBS_CSV" >> $GITHUB_OUTPUT
echo "libs_space=$LIBS_SPACE" >> $GITHUB_OUTPUT
- name: Build publishable libs
run: pnpm exec nx run-many --target=build --projects=${{ steps.get-libs.outputs.libs_csv }} --parallel
- name: Prepare packages for publishing
run: |
for lib in ${{ steps.get-libs.outputs.libs_space }}; do
if [ -d "dist/libs/$lib" ]; then
echo "Preparing $lib for publishing..."
cp "libs/$lib/README.md" "dist/libs/$lib/" 2>/dev/null || true
node tools/scripts/prepare-publish.mjs "dist/libs/$lib/package.json"
fi
done
# nx release publish is idempotent — it skips packages already on npm.
- name: Publish released packages
run: pnpm exec nx release publish --tag latest --access public --provenance
# Per-package `<short>-v<version>` tag + GitHub release for every pending
# entry — apps included. Runs AFTER npm publish so a failed publish
# doesn't leave orphan tags. The `cowswap-v*` and `explorer-v*` tags
# this pushes are what triggers deployment.yml.
- name: Create tags and GitHub releases
env:
GH_TOKEN: ${{ secrets.RELEASE_PLEASE_AUTH }}
PENDING_RELEASES: ${{ needs.release.outputs.pendingReleases }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
node -e '
const pkgs = JSON.parse(process.env.PENDING_RELEASES || "[]");
for (const p of pkgs) {
process.stdout.write(`${p.tag}\t${p.path}\n`);
}
' > /tmp/pending.tsv
while IFS=$'\t' read -r tag path; do
[ -z "$tag" ] && continue
echo "Creating tag and release for ${tag}"
if [ -f "${path}/CHANGELOG.md" ]; then
NOTES=$(awk '/^## /{p++; if(p==2)exit; if(p==1)next} p==1' "${path}/CHANGELOG.md")
else
NOTES=""
fi
[ -z "$NOTES" ] && NOTES="Release ${tag}"
git tag -a "${tag}" -m "Release ${tag}"
git push origin "${tag}"
printf '%s\n' "$NOTES" > /tmp/notes.md
gh release create "${tag}" \
--title "${tag}" \
--notes-file /tmp/notes.md
done < /tmp/pending.tsv
# Converter baseline tag. The converter's `git describe --match release-*`
# depends on this to know where to start scanning commits next run.
- name: Tag release baseline
run: |
TAG="release-$(date -u +%Y%m%dT%H%M%SZ)"
git tag -a "$TAG" -m "Release published at $TAG"
git push origin "$TAG"