Repository navigation
185 lines (161 loc) · 5.71 KB
/
Copy pathpublish.yml
File metadata and controls
185 lines (161 loc) · 5.71 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
180
181
182
183
184
185
name: Publish packages to NPM
on:
workflow_dispatch:
inputs:
from_package:
description: "Publish missing packages to npm (no version bump)"
type: boolean
default: false
pull_request:
types:
- closed
branches:
- master
- dev
workflow_run:
workflows:
- Update API client
- Update API client (dev)
types:
- completed
permissions:
id-token: write
contents: read
jobs:
publish:
if:
github.event_name == 'workflow_dispatch' ||
((github.event.workflow_run.name == 'Update API client' ||
github.event.pull_request.base.ref == 'master') &&
(github.event.pull_request.merged == true ||
github.event.workflow_run.conclusion == 'success'))
runs-on: ubuntu-latest
env:
PUBLISH_PAT: ${{ secrets.PUBLISH_PAT }}
GH_TOKEN: ${{ secrets.PUBLISH_PAT }}
steps:
- name: Checkout ⬇️
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.PUBLISH_PAT }}
- name: Setup Node 🎛️
uses: actions/setup-node@v6
with:
node-version: 24
cache: "yarn"
registry-url: "https://registry.npmjs.org"
- name: Git Identity 🪪
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Yarn Install 📦️
run: yarn install --immutable
- name: Setup NX 1/2 🎛️
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: master
# This step is needed for nx affected to work when CI is running on a PR
# See also https://nx.dev/ci/recipes/set-up/monorepo-ci-github-actions#configuring-ci-using-github-actions-and-nx
- name: Setup NX 2/2 🎛
if:
(github.ref != 'refs/heads/master' &&
github.event.workflow_run.head_branch != 'master')
run: git branch --track master origin/master
- name: Build 🔨
run: |
if [ "${{ inputs.from_package }}" = "true" ]; then
yarn nx run-many -t build --parallel=3
else
yarn nx affected -t build --parallel=3
fi
# TODO: Uses the previous version. Needs a fix!
- name: Create version file 🔢
run: |
yarn nx run @mittwald/api-client:build:write-version-file
git add .
- name: Version and publish 🚀
if:
github.event.workflow_run.head_branch == 'master' || github.ref ==
'refs/heads/master'
run: |
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" != "master" ]; then
echo "::error::Refusing to publish a release from '$branch'"
exit 1
fi
# Recovery run: no version bump, only push what is missing on npm.
if [ "${{ inputs.from_package }}" = "true" ]; then
exec yarn lerna publish from-package --yes --no-private
fi
git describe --exact-match --tags || code=$?
if [ "${code:-0}" -eq 128 ]; then
# npm publish can fail for a single package (e.g. flaky sigstore
# provenance), which leaves the release half-published on npm.
# from-package then re-publishes only the missing packages.
yarn lerna publish \
--message "chore(release): bump version to %v" \
--skip-bump-only-releases \
--conventional-commits \
--create-release github \
--yes --no-private \
--tag-version-prefix "" \
|| {
echo "::warning::lerna publish failed - retrying missing packages via from-package"
yarn lerna publish from-package --yes --no-private
}
fi
publish-dev:
if:
github.event.workflow_run.name == 'Update API client (dev)' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
env:
PUBLISH_PAT: ${{ secrets.PUBLISH_PAT }}
GH_TOKEN: ${{ secrets.PUBLISH_PAT }}
steps:
- name: Checkout ⬇️
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.PUBLISH_PAT }}
ref: dev
- name: Setup Node 🎛️
uses: actions/setup-node@v6
with:
node-version: 24
cache: "yarn"
registry-url: "https://registry.npmjs.org"
- name: Git Identity 🪪
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Yarn Install 📦️
run: yarn install --immutable
- name: Setup NX 1/2 🎛️
uses: nrwl/nx-set-shas@v4
with:
main-branch-name: dev
- name: Build 🔨
run: yarn nx affected -t build --parallel=3
# TODO: Uses the previous version. Needs a fix!
- name: Create version file 🔢
run: |
yarn nx run @mittwald/api-client:build:write-version-file
git add .
- name: Version and publish 🚀
run: |
branch=$(git rev-parse --abbrev-ref HEAD)
if [ "$branch" != "dev" ]; then
echo "::error::Refusing to publish a development version from '$branch'"
exit 1
fi
git describe --exact-match --tags || code=$?
if [ "${code:-0}" -eq 128 ]; then
yarn lerna publish 0.0.0-development-$(git rev-parse --short=7 HEAD)-$(date +%Y%m%d) \
--message "chore(release): bump version to %v" \
--skip-bump-only-releases \
--yes --no-private \
--tag-version-prefix "" \
--dist-tag development
fi