Skip to content

Commit 463bdac

Browse files
committed
ci: builds should have the correct version for autoupdating
1 parent a3a03bc commit 463bdac

File tree

1 file changed

+50
-4
lines changed

1 file changed

+50
-4
lines changed

.circleci/config.yml

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
working_directory: ~/
8484
command: |
8585
if [ ! -d ~/.asdf ]; then
86-
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
86+
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
8787
fi
8888
echo '. "$HOME/.asdf/asdf.sh"' >> ~/.bashrc
8989
. ~/.bashrc
@@ -244,13 +244,19 @@ jobs:
244244

245245
- attach_workspace:
246246
at: ../api
247+
# Need the correct version when building, for auto-updating
248+
- run: npm version $(cat ../api/v.txt)
247249
- run: npm run make
248250
- persist_to_workspace:
249251
root: "."
250252
paths:
251253
- out/make
252254

253255
release:
256+
parameters:
257+
check:
258+
type: boolean
259+
default: false
254260
docker:
255261
- image: node:22.1.0-bookworm-slim
256262
resource_class: medium
@@ -263,6 +269,13 @@ jobs:
263269
command: |
264270
apt update
265271
apt install -y git
272+
# Need curl if we need to check cancel
273+
- when:
274+
condition: << parameters.check >>
275+
steps:
276+
- run:
277+
working_directory: ~/
278+
command: apt install -y curl
266279

267280
- checkout:
268281
path: ~/project
@@ -279,16 +292,49 @@ jobs:
279292

280293
- attach_workspace:
281294
at: "."
282-
- run: npx semantic-release
295+
# Dry-run the release because we need the next version number for the
296+
# build, and we can skip the whole process if there will be no release.
297+
# See https://semantic-release.gitbook.io/semantic-release/support/faq#is-there-a-way-to-preview-which-version-would-currently-get-published
298+
- when:
299+
condition: << parameters.check >>
300+
steps:
301+
# Note that the version regex is not up to SemVer spec
302+
- run: |
303+
npx semantic-release --dry-run \
304+
| { grep -Po 'next release version is \K(?:\d+\.){2}\d+' || :; } \
305+
> v.txt
306+
cat v.txt
307+
- run: |
308+
if [ ! -s v.txt ]; then
309+
curl \
310+
--header "Circle-Token: $CIRCLE_TOKEN" \
311+
-X POST \
312+
"https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/cancel"
313+
fi
314+
- persist_to_workspace:
315+
root: "."
316+
paths:
317+
- v.txt
318+
- when:
319+
condition:
320+
not: << parameters.check >>
321+
steps:
322+
- run: npx semantic-release
283323

284324
workflows:
285-
main:
325+
publish:
286326
when:
287327
equal:
288328
- << pipeline.git.branch >>
289329
- master
290330
jobs:
291-
- get_scrcpy_server
331+
- release:
332+
name: check_release
333+
check: true
334+
335+
- get_scrcpy_server:
336+
requires:
337+
- check_release
292338

293339
- get_adb_server:
294340
name: get_adb_server_linux

0 commit comments

Comments
 (0)