-
Notifications
You must be signed in to change notification settings - Fork 0
288 lines (253 loc) · 10.5 KB
/
release.yml
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
name: Release
on:
push:
paths:
- '.changeset/**'
- 'src/**'
branches:
- main
workflow_dispatch:
inputs:
commit_message:
description: 'Custom commit message'
required: false
default: 'Version Packages'
debug:
description: 'Set to true to enable debug mode'
required: false
default: 'false'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
jobs:
build:
name: Build ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ windows-latest, ubuntu-latest, macos-latest ]
include:
- os: windows-latest
triplet: x64-windows
- os: ubuntu-latest
triplet: x64-linux
- os: macos-latest
triplet: x64-osx
env:
# Indicates the location of the vcpkg as a Git submodule of the project repository.
VCPKG_ROOT: ${{ github.workspace }}/deps/vcpkg
# Tells vcpkg where binary packages are stored.
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/deps/vcpkg/bincache
# Let's use GitHub Action cache as storage for the vcpkg Binary Caching feature.
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'
steps:
# Set env vars needed for vcpkg to leverage the GitHub Action cache as a storage
# for Binary Caching.
- uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- uses: actions/checkout@v4
with:
submodules: true
- name: Bump version
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i "s/set(VCPKG_FMT_TEMPLATE_VERSION .*)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i "s/set(VCPKG_FMT_TEMPLATE_VERSION .*)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
sed -i '' -E "s/set\(VCPKG_FMT_TEMPLATE_VERSION .*\)/set(VCPKG_FMT_TEMPLATE_VERSION $RELEASE_VERSION)/" CMakeLists.txt
fi
# Create the directory to store the vcpkg's binary cache.
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
shell: bash
# Set up the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
- uses: lukka/get-cmake@latest
- name: List $RUNNER_WORKSPACE before vcpkg is setup
run: find $RUNNER_WORKSPACE
if: ${{ inputs.debug == 'true' }}
shell: bash
- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
id: runvcpkg
with:
vcpkgDirectory: '${{ env.VCPKG_ROOT }}'
vcpkgJsonGlob: '**/vcpkg.json'
- name: List $RUNNER_WORKSPACE before build
run: find $RUNNER_WORKSPACE
if: ${{ inputs.debug == 'true' }}
shell: bash
- name: Prints output of run-vcpkg's action.
if: ${{ inputs.debug == 'true' }}
run: echo "root='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_ROOT_OUT }}', triplet='${{ steps.runvcpkg.outputs.RUNVCPKG_VCPKG_DEFAULT_TRIPLET_OUT }}' "
- name: Run CMake+vcpkg+Ninja
uses: lukka/run-cmake@v10
id: runcmake
with:
cmakeListsTxtPath: '${{ github.workspace }}/CMakeLists.txt'
configurePreset: 'vcpkg-fmt-template-ninja-multiconfiguration-vcpkg'
buildPreset: 'vcpkg-fmt-template-ninja-multiconfiguration-vcpkg'
- name: List $RUNNER_WORKSPACE after build
run: find $RUNNER_WORKSPACE
if: ${{ inputs.debug == 'true' }}
shell: bash
# Upload vcpkg's logs as artifacts.
- name: Upload vcpkg build log files
if: failure()
uses: actions/upload-artifact@v4
with:
name: vcpkg-log-files-${{ matrix.os }}
path: deps/vcpkg/buildtrees/**/*.log
# Upload builds logs as artifacts.
- name: Upload builds log files
if: failure()
uses: actions/upload-artifact@v4
with:
name: builds-log-files-${{ matrix.os }}
path: builds/**/*.log
# Package (Release configuration only).
- name: Package (Release configuration)
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
shell: bash
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
cpack --preset vcpkg-fmt-template-ninja-multiconfiguration-vcpkg-windows
elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
cpack --preset vcpkg-fmt-template-ninja-multiconfiguration-vcpkg-linux
elif [ "${{ matrix.os }}" == "macos-latest" ]; then
cpack --preset vcpkg-fmt-template-ninja-multiconfiguration-vcpkg-osx
fi
# Upload packages as artifacts.
- name: Upload package artifacts
if: "success() && contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
uses: actions/upload-artifact@v4
with:
name: packages-${{ matrix.os }}
path: |
packages/*.*
publish:
name: Publish
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2
name: Install pnpm
id: pnpm-install
with:
version: 8
run_install: false
- name: Cache node modules
uses: actions/cache@v4
with:
path: node_modules
key: pnpm-deps-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
pnpm-deps-${{ hashFiles('pnpm-lock.yaml') }}
- name: Install dependencies
run: pnpm install
- name: Create Release Pull Request
id: changesets
uses: changesets/action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract release version and notes from changelog
run: |
RELEASE_VERSION=$(sed -nE 's/^##[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)/\1/p' CHANGELOG.md | head -1)
echo "RELEASE_VERSION=$RELEASE_VERSION" >> $GITHUB_ENV
echo "RELEASE_TAG=v$RELEASE_VERSION" >> $GITHUB_ENV
RELEASE_NOTES=$(awk -v ver="$RELEASE_VERSION" -v latest="## Latest Release" \
'BEGIN {RS=""; ORS="\n\n"; output=0} \
$0 ~ "## " ver {output=1; next} \
$0 ~ latest {output=0} \
output {print $0}' CHANGELOG.md)
if [ -z "$RELEASE_NOTES" ]; then
RELEASE_NOTES=$(awk -v ver="$RELEASE_VERSION" \
'BEGIN {RS=""; ORS="\n\n"; output=0} \
$0 ~ "## " ver {output=1; next} \
output {print $0}' CHANGELOG.md)
fi
RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "$RELEASE_NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create and push release tag
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
git tag ${{ env.RELEASE_TAG }}
git push origin ${{ env.RELEASE_TAG }}
- name: Create Release
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
id: create_release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
name: ${{ env.RELEASE_TAG }}
body: ${{ env.RELEASE_NOTES }}
draft: false
prerelease: false
- name: Commit version bump
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
pnpm version-bump
pnpm version-bump:commit
- name: Update changelog
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
run: |
pnpm changelog:latest
pnpm changelog:format
pnpm changelog:commit
upload:
name: Upload packages artifacts
if: "contains(github.event.head_commit.message, 'Version Packages') || contains(github.event.inputs.commit_message, 'Version Packages')"
needs: [build, publish]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download packages-windows-latest artifact
uses: actions/download-artifact@v4
with:
name: packages-windows-latest
path: artifacts
- name: Download packages-ubuntu-latest artifact
uses: actions/download-artifact@v4
with:
name: packages-ubuntu-latest
path: artifacts
- name: Download packages-macos-latest artifact
uses: actions/download-artifact@v4
with:
name: packages-macos-latest
path: artifacts
- name: Get latest release
id: latest_release
run: |
RELEASE_ID=$(gh release list --repo $GITHUB_REPOSITORY | head -n 1 | awk '{print $1}')
echo "RELEASE_ID=$RELEASE_ID" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload release assets (packages)
run: |
for file in artifacts/*; do
[ -e "$file" ] || continue
echo "Uploading $file"
gh release upload $RELEASE_ID "$file" --clobber --repo $GITHUB_REPOSITORY
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}