|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: release-${{ github.ref }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: read |
| 14 | + |
| 15 | +jobs: |
| 16 | + validate: |
| 17 | + uses: ./.github/workflows/validate.yml |
| 18 | + |
| 19 | + build: |
| 20 | + needs: validate |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v5 |
| 25 | + - name: Set up uv |
| 26 | + uses: astral-sh/setup-uv@v9.0.0 |
| 27 | + with: |
| 28 | + python-version: '3.12' |
| 29 | + - name: Check the release tag matches the package version |
| 30 | + env: |
| 31 | + TAG: ${{ github.event.release.tag_name }} |
| 32 | + run: | |
| 33 | + tag="${TAG#v}" |
| 34 | + version="$(uv version --short)" |
| 35 | + if [ "$tag" != "$version" ]; then |
| 36 | + echo "::error::Release tag '$TAG' does not match the version in pyproject.toml ('$version')." |
| 37 | + echo "Bump pyproject.toml, or retag the release." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + echo "Releasing guard-client $version" |
| 41 | + - name: Build the package |
| 42 | + run: uv build |
| 43 | + - name: Upload distributions |
| 44 | + uses: actions/upload-artifact@v7 |
| 45 | + with: |
| 46 | + name: release-dist |
| 47 | + path: dist/ |
| 48 | + retention-days: 7 |
| 49 | + |
| 50 | + publish-pypi: |
| 51 | + needs: build |
| 52 | + runs-on: ubuntu-latest |
| 53 | + environment: |
| 54 | + name: production |
| 55 | + permissions: |
| 56 | + id-token: write |
| 57 | + steps: |
| 58 | + - name: Download distributions |
| 59 | + uses: actions/download-artifact@v8 |
| 60 | + with: |
| 61 | + name: release-dist |
| 62 | + path: dist |
| 63 | + - name: Publish package distributions to PyPI |
| 64 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 65 | + |
| 66 | + attach-assets: |
| 67 | + needs: build |
| 68 | + runs-on: ubuntu-latest |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + steps: |
| 72 | + - name: Download distributions |
| 73 | + uses: actions/download-artifact@v8 |
| 74 | + with: |
| 75 | + name: release-dist |
| 76 | + path: dist |
| 77 | + |
| 78 | + - name: Upload assets to release |
| 79 | + uses: softprops/action-gh-release@v3 |
| 80 | + with: |
| 81 | + files: | |
| 82 | + dist/*.whl |
| 83 | + dist/*.tar.gz |
| 84 | +
|
| 85 | + docs: |
| 86 | + needs: publish-pypi |
| 87 | + runs-on: ubuntu-latest |
| 88 | + environment: |
| 89 | + name: production |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v5 |
| 93 | + - name: Set up uv |
| 94 | + uses: astral-sh/setup-uv@v9.0.0 |
| 95 | + with: |
| 96 | + python-version: '3.12' |
| 97 | + - name: Install the docs group |
| 98 | + run: uv sync --locked --group docs |
| 99 | + - name: Build the documentation |
| 100 | + run: uv run python scripts/build_docs.py --strict |
| 101 | + - name: Upload the documentation to MinIO |
| 102 | + env: |
| 103 | + AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_ACCESS_KEY }} |
| 104 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }} |
| 105 | + AWS_DEFAULT_REGION: ${{ vars.MINIO_REGION || 'us-east-1' }} |
| 106 | + AWS_ENDPOINT_URL_S3: ${{ vars.MINIO_ENDPOINT }} |
| 107 | + BUCKET: ${{ vars.DOCS_BUCKET }} |
| 108 | + run: | |
| 109 | + set -euo pipefail |
| 110 | +
|
| 111 | + # Say which setting is missing, rather than failing later against AWS. |
| 112 | + : "${AWS_ENDPOINT_URL_S3:?set the MINIO_ENDPOINT repository variable}" |
| 113 | + : "${BUCKET:?set the DOCS_BUCKET repository variable}" |
| 114 | +
|
| 115 | + # MinIO serves path-style addressing. Virtual-host style needs wildcard DNS |
| 116 | + # that a self-hosted instance usually does not have, and no environment |
| 117 | + # variable controls this, so it goes in the runner's throwaway CLI config. |
| 118 | + aws configure set default.s3.addressing_style path |
| 119 | +
|
| 120 | + package="$(uv run python -c "import json; print(json.load(open('docs/docs.json'))['package'])")" |
| 121 | + version="$(uv run python -c "import json; print(json.load(open('docs/docs.json'))['version'])")" |
| 122 | + key="docs/${package}/${version}.json" |
| 123 | +
|
| 124 | + # `--endpoint-url` is passed explicitly even though AWS_ENDPOINT_URL_S3 is |
| 125 | + # normally picked up on its own: that variable needs AWS CLI v2.13+, and a |
| 126 | + # runner with anything older would silently upload to the real AWS instead. |
| 127 | +
|
| 128 | + # A released version's documentation is immutable. Re-running a failed |
| 129 | + # release job must not quietly rewrite what people have already read. |
| 130 | + if aws --endpoint-url "$AWS_ENDPOINT_URL_S3" s3api head-object \ |
| 131 | + --bucket "$BUCKET" --key "$key" >/dev/null 2>&1; then |
| 132 | + echo "::notice::${key} already exists; leaving it untouched." |
| 133 | + else |
| 134 | + aws --endpoint-url "$AWS_ENDPOINT_URL_S3" \ |
| 135 | + s3 cp docs/docs.json "s3://${BUCKET}/${key}" \ |
| 136 | + --content-type application/json \ |
| 137 | + --cache-control "public, max-age=31536000, immutable" |
| 138 | + echo "Uploaded ${key}" |
| 139 | + fi |
| 140 | +
|
| 141 | + aws --endpoint-url "$AWS_ENDPOINT_URL_S3" \ |
| 142 | + s3 cp docs/docs.json "s3://${BUCKET}/docs/${package}/latest.json" \ |
| 143 | + --content-type application/json \ |
| 144 | + --cache-control "no-cache" |
| 145 | + echo "Updated docs/${package}/latest.json" |
0 commit comments