|
1 | 1 | name: CD (Production) |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - 'v*.*.*' # GA releases: v1.0.0, v1.4.2 |
7 | | - - 'v*.*.*-*' # SemVer pre-releases: v1.0.0-rc.1 |
8 | | - - 'v*.*.*[a-z]*' # PEP 440 pre-releases: v1.0.0rc1, v1.0.0b2 (release-please-python form) |
| 4 | + release: |
| 5 | + types: [published] |
9 | 6 |
|
10 | 7 | permissions: |
11 | 8 | contents: read |
12 | 9 |
|
13 | 10 | jobs: |
14 | 11 | production-deploy: |
15 | 12 |
|
| 13 | + # Safety rail: only deploy when the release tag is version-shaped |
| 14 | + # (v*.*.*, v*.*.*-*, v*.*.*[a-z]*). startsWith() is a cheap pre-filter; |
| 15 | + # the "Validate release tag" step enforces the strict regex. |
| 16 | + if: startsWith(github.event.release.tag_name, 'v') |
| 17 | + |
16 | 18 | runs-on: ubuntu-latest |
17 | 19 | environment: production |
18 | 20 |
|
19 | 21 | steps: |
| 22 | + - name: Validate release tag matches version pattern |
| 23 | + env: |
| 24 | + TAG: ${{ github.event.release.tag_name }} |
| 25 | + run: | |
| 26 | + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+|[a-z].*)?$ ]]; then |
| 27 | + echo "Release tag '$TAG' does not match the v*.*.* pattern. Refusing to deploy." |
| 28 | + exit 1 |
| 29 | + fi |
| 30 | +
|
20 | 31 | - name: Check out source repository |
21 | 32 | uses: actions/checkout@v6.0.3 |
22 | 33 | with: |
23 | 34 | fetch-depth: 0 |
| 35 | + # Fully-qualified tag ref avoids ambiguity if a branch is ever |
| 36 | + # created with the same name as the release tag. |
| 37 | + ref: refs/tags/${{ github.event.release.tag_name }} |
24 | 38 |
|
25 | 39 | - name: Install uv in container |
26 | 40 | uses: astral-sh/setup-uv@v8.2.0 |
|
69 | 83 |
|
70 | 84 | - name: Render App Engine configs |
71 | 85 | env: |
72 | | - APP_VERSION: ${{ github.ref_name }} |
| 86 | + APP_VERSION: ${{ github.event.release.tag_name }} |
73 | 87 | ENVIRONMENT: "production" |
74 | 88 | CLOUD_SQL_INSTANCE_NAME: "${{ secrets.CLOUD_SQL_INSTANCE_NAME }}" |
75 | 89 | CLOUD_SQL_DATABASE: "${{ vars.CLOUD_SQL_DATABASE }}" |
|
0 commit comments