From 90fbb7e457dcb34a83ca25177c8380c8340950f4 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Wed, 21 Aug 2024 09:54:32 -0400 Subject: [PATCH] chore(ci): Prepare JSR distribution --- .github/workflows/publish_schema.yml | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/publish_schema.yml diff --git a/.github/workflows/publish_schema.yml b/.github/workflows/publish_schema.yml new file mode 100644 index 0000000000..3cc78072f0 --- /dev/null +++ b/.github/workflows/publish_schema.yml @@ -0,0 +1,82 @@ +name: "Publish schema" + +on: + push: + branches: + - "master" + - "jsr/*" + tags: + - "schema-*" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +env: + AUTHOR_NAME: BIDS CI + AUTHOR_EMAIL: bids.maintenance@gmail.com + COMMITTER_NAME: BIDS CI + COMMITTER_EMAIL: bids.maintenance@gmail.com + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3 + - name: Install bidsschematools + run: | + pip install --upgrade tools/schemacode + git clean -fxd tools/schemacode + - name: Checkout jsr-dist + run: | + git fetch --depth=1 origin jsr-dist + git checkout -t origin/jsr-dist + - name: Regenerate schema + run: bst export > schema.json + - name: Regenerate context types + run: | + jq .meta.context schema.json \ + | npx quicktype --src-lang schema --lang ts -t Context --just-types \ + > context.ts + - name: Regenerate metaschema types + run: | + # Name the file schema so the type will be named Schema + bst export-metaschema > /tmp/schema.json + npx --package=json-schema-to-typescript json2ts --unknownAny /tmp/schema.json > metaschema.ts + - name: Determine next version + run: | + BASE=$( jq -r .schema_version schema.json ) + if [[ "$BASE" =~ ^[0-9]*.[0-9]*.[0-9]*$ ]]; then + # Release + VERSION=$BASE + else + DENOVER=$( jq -r .version jsr.json ) + # Should switch to using the commit hash of the source repo? + HASH=$( sha256sum schema.json | head -c 7 ) + if [[ $DENOVER =~ ^"$BASE".[0-9] ]]; then + PREFIX=${DENOVER%+*} + let SERIAL=1+${PREFIX#$BASE.} + else + SERIAL=1 + fi + VERSION="$BASE.$SERIAL+$HASH" + fi + echo VERSION=$VERSION | tee -a $GITHUB_ENV + - name: Check for changes, set version and commit + run: | + if ! git diff -s --exit-code; then + jq ".version = \"$VERSION\"" jsr.json > tmp.json && mv tmp.json jsr.json + git add jsr.json schema.json context.ts metaschema.ts + git commit -m "Update schema JSR distribution" + fi + - name: Publish to JSR + if: success() + run: | + npx jsr publish --dry-run