diff --git a/.github/workflows/build_wheels.yaml b/.github/workflows/build_wheels.yaml index 900d436..b72c432 100644 --- a/.github/workflows/build_wheels.yaml +++ b/.github/workflows/build_wheels.yaml @@ -1,26 +1,169 @@ -name: Build and Publish +# Triggered by repository_dispatch from green-mbpt when a new tag is created. +# Updates version.py, updates HDF5 file version attributes, commits changes, +# creates a matching tag, and deploys the package to PyPI. + +# NOTE: A direct / manual push for release is not allowed. Release can only be triggered +# via repository_dispatch from green-mbpt. This is to ensure that the version update and +# deployment steps are always executed when a new tag is created. + +name: Update Version and Deploy on: - push: - branches: - - main - tags: - - 'v*' - pull_request: + repository_dispatch: + types: [version-update] workflow_dispatch: + inputs: + tag: + description: 'Tag to create (e.g. v0.3.3-test). Always a dry run — no commits, tags, or PyPI uploads.' + required: true +# Canceling in-progress runs is disabled to ensure that the deployment step is not +# accidentally canceled if multiple tags are created in quick succession. +# The concurrency group is still defined to prevent multiple runs for the same tag, +# but it won't cancel an already running deployment if a new tag is pushed while +# it's still running. concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.event.client_payload.tag || github.event.inputs.tag }} + cancel-in-progress: false # safer for PyPI deployments jobs: - build_sdist: + update-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Generate token + id: generate-token + uses: actions/create-github-app-token@v1 + with: + app-id: ${{ secrets.GREEN_TAG_APP_ID }} + private-key: ${{ secrets.GREEN_TAG_APP_PRIVATE_KEY }} + owner: Green-Phys + + - name: Checkout green-grids + uses: actions/checkout@v4 + with: + token: ${{ steps.generate-token.outputs.token }} + + - name: Validate tag name + env: + TAG_NAME: ${{ github.event.client_payload.tag || github.event.inputs.tag }} + run: | + if [ -z "$TAG_NAME" ]; then + echo "Error: TAG_NAME is empty" + exit 1 + fi + if ! echo "$TAG_NAME" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9._-]+)?$'; then + echo "Error: TAG_NAME '$TAG_NAME' does not match expected format vX.Y.Z or vX.Y.Z-suffix" + exit 1 + fi + echo "TAG_NAME '$TAG_NAME' is valid" + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install h5py + run: python3 -m pip install h5py + + - name: Update version.py + env: + TAG_NAME: ${{ github.event.client_payload.tag || github.event.inputs.tag }} + run: | + VERSION=${TAG_NAME#v} + sed -i "s/__version__ = '.*'/__version__ = '$VERSION'/" \ + python/green_grids/version.py + + - name: Update data.h5 version attributes + env: + TAG_NAME: ${{ github.event.client_payload.tag || github.event.inputs.tag }} + run: | + VERSION=${TAG_NAME#v} + GRIDS_VERSION="$VERSION" python3 - <