Skip to content

Commit 9eeab01

Browse files
committed
chore(ci): Prepare JSR distribution
1 parent 335db02 commit 9eeab01

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: "Publish schema"
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
- "jsr/*"
8+
tags:
9+
- "schema-*"
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
defaults:
16+
run:
17+
shell: bash
18+
19+
env:
20+
GIT_AUTHOR_NAME: BIDS CI
21+
GIT_AUTHOR_EMAIL: [email protected]
22+
GIT_COMMITTER_NAME: BIDS CI
23+
GIT_COMMITTER_EMAIL: [email protected]
24+
25+
jobs:
26+
publish:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: actions/setup-python@v5
31+
with:
32+
python-version: 3
33+
- name: Install bidsschematools
34+
run: |
35+
pip install --upgrade tools/schemacode
36+
git clean -fxd tools/schemacode
37+
- name: Checkout jsr-dist
38+
run: |
39+
git fetch --depth=1 origin jsr-dist
40+
git checkout -t origin/jsr-dist
41+
- name: Regenerate schema
42+
run: bst export > schema.json
43+
- name: Regenerate context types
44+
run: |
45+
jq .meta.context schema.json \
46+
| npx quicktype --src-lang schema --lang ts -t Context --just-types \
47+
> context.ts
48+
- name: Regenerate metaschema types
49+
run: |
50+
# Name the file schema so the type will be named Schema
51+
bst export-metaschema > /tmp/schema.json
52+
npx --package=json-schema-to-typescript json2ts --unknownAny /tmp/schema.json > metaschema.ts
53+
- name: Determine next version
54+
run: |
55+
BASE=$( jq -r .schema_version schema.json )
56+
if [[ "$BASE" =~ ^[0-9]*.[0-9]*.[0-9]*$ ]]; then
57+
# Release, so unconditionally update version
58+
VERSION=$BASE
59+
jq ".version = \"$VERSION\"" jsr.json > tmp.json && mv tmp.json jsr.json
60+
else
61+
DENOVER=$( jq -r .version jsr.json )
62+
# Should switch to using the commit hash of the source repo?
63+
HASH=$( sha256sum schema.json | head -c 7 )
64+
if [[ $DENOVER =~ ^"$BASE".[0-9] ]]; then
65+
PREFIX=${DENOVER%+*}
66+
let SERIAL=1+${PREFIX#$BASE.}
67+
else
68+
SERIAL=1
69+
fi
70+
VERSION="$BASE.$SERIAL+$HASH"
71+
fi
72+
echo VERSION=$VERSION | tee -a $GITHUB_ENV
73+
- name: Check for changes, set version and commit
74+
run: |
75+
if ! git diff -s --exit-code; then
76+
jq ".version = \"$VERSION\"" jsr.json > tmp.json && mv tmp.json jsr.json
77+
git add jsr.json schema.json context.ts metaschema.ts
78+
git commit -m "Update schema JSR distribution"
79+
fi
80+
- name: Publish to JSR
81+
if: success()
82+
run: |
83+
npx jsr publish --dry-run

0 commit comments

Comments
 (0)