Add dry-run paths to release workflow #86
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| pull_request: | |
| types: [opened, reopened, synchronize, labeled, unlabeled] | |
| branches: | |
| - "master" | |
| - "ci" | |
| - "[0-9]+.[0-9x]+*" | |
| jobs: | |
| classify-release: | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| pull-requests: read | |
| outputs: | |
| mode: ${{ steps.mode.outputs.mode }} | |
| steps: | |
| - name: Select release mode | |
| id: mode | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| let mode = 'skip'; | |
| if (context.eventName === 'workflow_dispatch') { | |
| mode = 'dry_run'; | |
| } else { | |
| const { action, label, pull_request: pr } = context.payload; | |
| if (action === 'labeled' || action === 'unlabeled') { | |
| // Ignore unrelated label changes and do not release on removal. | |
| if (action === 'labeled' && label.name === 'release-dry-run') { | |
| mode = 'dry_run'; | |
| } | |
| } else if (pr.labels.some(({ name }) => name === 'release-dry-run')) { | |
| mode = 'dry_run'; | |
| } else { | |
| // Preserve the previous version-file filter for ordinary PRs. | |
| const files = await github.paginate(github.rest.pulls.listFiles, { | |
| ...context.repo, | |
| pull_number: pr.number, | |
| per_page: 100, | |
| }); | |
| if (files.some(({ filename }) => filename === 'asyncpg/_version.py')) { | |
| mode = 'release'; | |
| } | |
| } | |
| } | |
| core.setOutput('mode', mode); | |
| core.info(`Release mode: ${mode}`); | |
| validate-release-request: | |
| needs: classify-release | |
| if: needs.classify-release.outputs.mode == 'release' | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Validate release PR | |
| uses: edgedb/action-release/validate-pr@master | |
| id: checkver | |
| with: | |
| require_team: Release Managers | |
| require_approval: no | |
| github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | |
| version_file: asyncpg/_version.py | |
| version_line_pattern: | | |
| __version__(?:\s*:\s*typing\.Final)?\s*=\s*(?:['"])([[:PEP440:]])(?:['"]) | |
| - name: Stop if not approved | |
| if: steps.checkver.outputs.approved != 'true' | |
| run: | | |
| echo ::error::PR is not approved yet. | |
| exit 1 | |
| - name: Store release version for later use | |
| env: | |
| VERSION: ${{ steps.checkver.outputs.version }} | |
| run: | | |
| mkdir -p dist/ | |
| echo "${VERSION}" > dist/VERSION | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-version | |
| path: dist/VERSION | |
| build-sdist: | |
| needs: [classify-release, validate-release-request] | |
| if: >- | |
| ${{ !cancelled() && needs.classify-release.outputs.mode != 'skip' && | |
| (needs.classify-release.outputs.mode == 'dry_run' || | |
| needs.validate-release-request.result == 'success') }} | |
| runs-on: ubuntu-24.04 | |
| env: | |
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 50 | |
| submodules: true | |
| persist-credentials: false | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.x" | |
| - name: Build source distribution | |
| run: | | |
| pip install -U setuptools wheel build | |
| python -m build --sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-sdist | |
| path: dist/*.tar.* | |
| build-wheels-matrix: | |
| needs: [classify-release, validate-release-request] | |
| if: >- | |
| ${{ !cancelled() && needs.classify-release.outputs.mode != 'skip' && | |
| (needs.classify-release.outputs.mode == 'dry_run' || | |
| needs.validate-release-request.result == 'success') }} | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| include: ${{ steps.set-matrix.outputs.include }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| persist-credentials: false | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.x" | |
| - name: Install cibuildwheel | |
| run: pip install cibuildwheel==3.3.1 | |
| - name: Build cibuildwheel matrix | |
| id: set-matrix | |
| env: | |
| # skipping pypy for now | |
| CIBW_SKIP: > | |
| pp* | |
| run: | | |
| set -euo pipefail | |
| MATRIX_INCLUDE=$( | |
| { | |
| cibuildwheel --print-build-identifiers --platform linux --archs x86_64 | jq -nRc '{"only": inputs, "os": "ubuntu-24.04"}' \ | |
| && cibuildwheel --print-build-identifiers --platform linux --archs aarch64 | jq -nRc '{"only": inputs, "os": "ubuntu-24.04-arm"}' \ | |
| && cibuildwheel --print-build-identifiers --platform macos --archs x86_64 | jq -nRc '{"only": inputs, "os": "macos-15-intel"}' \ | |
| && cibuildwheel --print-build-identifiers --platform macos --archs arm64 | jq -nRc '{"only": inputs, "os": "macos-15"}' \ | |
| && cibuildwheel --print-build-identifiers --platform windows --archs x86,AMD64 | jq -nRc '{"only": inputs, "os": "windows-2025"}' \ | |
| && cibuildwheel --print-build-identifiers --platform windows --archs ARM64 | jq -nRc '{"only": inputs, "os": "windows-11-arm"}' | |
| } | jq -sc | |
| ) | |
| echo "include=$MATRIX_INCLUDE" >> "$GITHUB_OUTPUT" | |
| build-wheels: | |
| needs: build-wheels-matrix | |
| runs-on: ${{ matrix.os }} | |
| name: Build ${{ matrix.only }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: ${{ fromJson(needs.build-wheels-matrix.outputs.include) }} | |
| defaults: | |
| run: | |
| shell: bash | |
| env: | |
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 50 | |
| submodules: true | |
| persist-credentials: false | |
| - name: Set up QEMU | |
| if: runner.os == 'Linux' | |
| uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 | |
| - uses: pypa/cibuildwheel@298ed2fb2c105540f5ed055e8a6ad78d82dd3a7e # v3.3.1 | |
| with: | |
| only: ${{ matrix.only }} | |
| env: | |
| CIBW_BUILD_VERBOSITY: 1 | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist-wheels-${{ matrix.only }} | |
| path: wheelhouse/*.whl | |
| merge-artifacts: | |
| runs-on: ubuntu-24.04 | |
| needs: [build-sdist, build-wheels] | |
| steps: | |
| - name: Merge Artifacts | |
| uses: actions/upload-artifact/merge@v4 | |
| with: | |
| name: dist | |
| pattern: dist-* | |
| delete-merged: true | |
| publish-docs: | |
| needs: [classify-release, build-sdist, build-wheels] | |
| runs-on: ubuntu-24.04 | |
| env: | |
| PIP_DISABLE_PIP_VERSION_CHECK: 1 | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 5 | |
| submodules: true | |
| persist-credentials: false | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.x" | |
| - name: Build docs | |
| run: | | |
| pip install --group docs | |
| pip install -e . | |
| make htmldocs | |
| - name: Upload docs preview | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: docs-preview | |
| path: docs/_build/html/ | |
| - name: Checkout gh-pages | |
| if: needs.classify-release.outputs.mode == 'release' | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 5 | |
| ref: gh-pages | |
| path: docs/gh-pages | |
| persist-credentials: false | |
| - name: Sync docs | |
| if: needs.classify-release.outputs.mode == 'release' | |
| run: | | |
| rsync -a docs/_build/html/ docs/gh-pages/current/ | |
| - name: Commit and push docs | |
| if: needs.classify-release.outputs.mode == 'release' | |
| uses: magicstack/gha-commit-and-push@master | |
| with: | |
| target_branch: gh-pages | |
| workdir: docs/gh-pages | |
| commit_message: Automatic documentation update | |
| github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | |
| ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }} | |
| gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }} | |
| gpg_key_id: "5C468778062D87BF!" | |
| publish: | |
| needs: [classify-release, merge-artifacts, publish-docs] | |
| if: needs.classify-release.outputs.mode == 'release' | |
| runs-on: ubuntu-24.04 | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/asyncpg | |
| permissions: | |
| id-token: write | |
| attestations: write | |
| contents: write | |
| deployments: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 5 | |
| submodules: false | |
| persist-credentials: false | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Extract Release Version | |
| id: relver | |
| run: | | |
| set -e | |
| echo "version=$(cat dist/VERSION)" >> "$GITHUB_OUTPUT" | |
| rm dist/VERSION | |
| - name: Merge and tag the PR | |
| uses: edgedb/action-release/merge@master | |
| with: | |
| github_token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }} | |
| ssh_key: ${{ secrets.RELEASE_BOT_SSH_KEY }} | |
| gpg_key: ${{ secrets.RELEASE_BOT_GPG_KEY }} | |
| gpg_key_id: "5C468778062D87BF!" | |
| tag_name: v${{ steps.relver.outputs.version }} | |
| - name: Publish Github Release | |
| uses: elprans/gh-action-create-release@master | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ steps.relver.outputs.version }} | |
| release_name: v${{ steps.relver.outputs.version }} | |
| target: ${{ github.event.pull_request.base.ref }} | |
| body: ${{ github.event.pull_request.body }} | |
| - run: | | |
| ls -al dist/ | |
| - name: Upload to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| attestations: true |