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