diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9c565864..3f8d8889 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,6 +43,11 @@ jobs: needs: release-check if: needs.release-check.outputs.auto-version != '' steps: + - name: Configure + run: | + git config --global user.email "team@dandiarchive.org" + git config --global user.name "DANDI Bot" + - name: Checkout source uses: actions/checkout@v5 with: @@ -66,12 +71,7 @@ jobs: - name: Get schema version run: | - SCHEMA_VERSION="$(python -c 'from dandischema.consts import DANDI_SCHEMA_VERSION; print(DANDI_SCHEMA_VERSION)')" - if ! echo "$SCHEMA_VERSION" | grep -qP '^\d+\.\d+\.\d+$' - then printf "[ERROR] Invalid schema version: '%s'\n" "$SCHEMA_VERSION" - exit 1 - fi - echo "SCHEMA_VERSION=$SCHEMA_VERSION" >> "$GITHUB_ENV" + tools/get-schema-version # it will also check if schema version is ok - name: Checkout dandi/schema uses: actions/checkout@v5 @@ -118,19 +118,6 @@ jobs: - name: Commit schema changes and create new tag run: | - LIBRARY_VERSION="$(git -C ../dandischema describe --tags --exact-match)" - - git config --global user.email "team@dandiarchive.org" - git config --global user.name "DANDI Bot" - - git add releases - if ! git diff --quiet --cached - then git commit -m "Publish model schema v$SCHEMA_VERSION as of dandischema v$LIBRARY_VERSION" - git push - git -C ../dandischema tag -m "Schema v$SCHEMA_VERSION, released in dandischema v$LIBRARY_VERSION" schema-$SCHEMA_VERSION - git -C ../dandischema push --tags - else echo "No changes to commit" - fi - working-directory: schema + tools/commit-and-push-schemata ../schema # vim:set sts=2: diff --git a/tools/commit-and-push-schemata b/tools/commit-and-push-schemata new file mode 100755 index 00000000..cb35150a --- /dev/null +++ b/tools/commit-and-push-schemata @@ -0,0 +1,27 @@ +#!/bin/bash + +set -eu + +tools_path=$(dirname "$0") +# Path of the `dandi-schema` repo +dandi_schema_path="${tools_path}"/.. +# Path of the `schema` repo +schemata_path=${1:-.} + +LIBRARY_VERSION="$(git -C "${dandi_schema_path}" describe --tags --exact-match)" +SCHEMA_VERSION="$("$tools_path"/get-schema-version)" + +git -C "$schemata_path" add releases + +if ! git -C "$schemata_path" diff --quiet --cached +then + # Publish/release a new schema to the `schema` repo + git -C "$schemata_path" commit -m "Publish model schema v$SCHEMA_VERSION as of dandischema v$LIBRARY_VERSION" + git -C "$schemata_path" push + + # Tag the `dandi-schema` repo with the new schema version + git -C "$dandi_schema_path" tag -m "Schema v$SCHEMA_VERSION, released in dandischema v$LIBRARY_VERSION" "schema-$SCHEMA_VERSION" + git -C "$dandi_schema_path" push --tags +else + echo "No changes to commit" +fi diff --git a/tools/get-schema-version b/tools/get-schema-version new file mode 100755 index 00000000..b68ce9b2 --- /dev/null +++ b/tools/get-schema-version @@ -0,0 +1,12 @@ +#!/usr/bin/env python3 + +import re +import sys + +from dandischema.consts import DANDI_SCHEMA_VERSION + +if not re.match(r"[0-9]+\.[0-9]+\.[0-9]+$", DANDI_SCHEMA_VERSION): + sys.stderr.write(f"[ERROR] Invalid schema version: '{DANDI_SCHEMA_VERSION}'\n") + sys.exit(1) + +print(DANDI_SCHEMA_VERSION)