44 push :
55 branches : [main]
66 paths :
7- - ' versions.yaml'
8- - ' .github/workflows/release-prod.yml'
7+ - ' infra/prod.tfvars'
98 workflow_dispatch :
109
1110# CRITICAL: Concurrency Control
@@ -18,7 +17,7 @@ permissions:
1817 id-token : write
1918
2019jobs :
21- # Phase 1: Extract and verify configuration from versions.yaml
20+ # Phase 1: Extract and verify configuration
2221 config :
2322 runs-on : ubuntu-latest
2423 outputs :
@@ -30,28 +29,28 @@ jobs:
3029 steps :
3130 - uses : actions/checkout@v4
3231
33- - name : Parse versions.yaml and Environment Config
32+ - name : Parse Configuration
3433 id : parse
3534 run : |
36- # Read the SHA from versions.yaml (dev section)
37- DEV_SHA=$(grep -A 1 "^dev:" versions.yaml | grep "image_version:" | sed 's/.*image_version: *//' | tr -d '" ')
35+ # Read all config from prod.tfvars
36+ PROJECT_ID=$(grep -E '^\s*project_id\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
37+ SA=$(grep -E '^\s*service_account\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
38+ BUCKET=$(grep -E '^\s*state_bucket\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
39+ # Read the version you manually set in prod.tfvars
40+ VERSION=$(grep -E '^\s*image_version\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')
3841
39- # Read from prod.tfvars
40- PROJECT_ID=$(grep -E '^\s*project_id\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
41- SA=$(grep -E '^\s*service_account\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
42- BUCKET=$(grep -E '^\s*state_bucket\s*=' infra/prod.tfvars | head -1 | sed -E 's/.*=\s*"([^"+)".*/\1/')
42+ # Derive dev project ID from prod service account
43+ # Format: tofu-provisioner@hubspoke-demo-dev-b87d.iam.gserviceaccount.com
44+ DEV_PROJECT_ID=$(echo "$SA" | sed -E 's/.*@([^\.]+)\.iam\.gserviceaccount\.com/\1/' | sed 's/-prod-[a-f0-9]\{4\}/-dev-b87d/')
4345
44- # Derive dev project ID (strip -prod- suffix and add -dev- pattern)
45- DEV_PROJECT_ID=$(echo "$PROJECT_ID" | sed 's/-prod-[a-f0-9]\{4\}/-dev-b87d/')
46-
47- echo "version=$DEV_SHA" >> $GITHUB_OUTPUT
46+ echo "version=$VERSION" >> $GITHUB_OUTPUT
4847 echo "service_account=$SA" >> $GITHUB_OUTPUT
4948 echo "state_bucket=$BUCKET" >> $GITHUB_OUTPUT
5049 echo "project_id=$PROJECT_ID" >> $GITHUB_OUTPUT
5150 echo "dev_project_id=$DEV_PROJECT_ID" >> $GITHUB_OUTPUT
5251
5352 echo "📋 Configuration:"
54- echo " Version (from versions.yaml ): $DEV_SHA "
53+ echo " Version (from prod.tfvars ): $VERSION "
5554 echo " Prod Project: $PROJECT_ID"
5655 echo " Dev Project: $DEV_PROJECT_ID"
5756
@@ -127,7 +126,6 @@ jobs:
127126 echo "📋 Running tofu plan..."
128127 tofu plan \
129128 -var-file="prod.tfvars" \
130- -var="image_version=${{ needs.config.outputs.version }}" \
131129 -no-color \
132130 -out=tfplan
133131
@@ -138,22 +136,6 @@ jobs:
138136 echo "🚀 Applying infrastructure changes..."
139137 tofu apply tfplan -no-color
140138
141- - name : Update versions.yaml Prod Section
142- if : success()
143- run : |
144- VERSION="${{ needs.config.outputs.version }}"
145- TIMESTAMP=$(date -Iseconds)
146-
147- # Update versions.yaml with prod deployment info
148- sed -i "/^prod:/,/^[^ ]/{s/image_version:.*/image_version: \"$VERSION\"/}" versions.yaml
149- sed -i "/^prod:/,/^[^ ]/{s/promoted_at:.*/promoted_at: \"$TIMESTAMP\"/}" versions.yaml
150-
151- git config --local user.email "github-actions[bot]@users.noreply.github.com"
152- git config --local user.name "github-actions[bot]"
153- git add versions.yaml
154- git commit -m "docs: update prod version to $VERSION [skip ci]"
155- git push
156-
157139 - name : Deployment Summary
158140 if : always()
159141 run : |
0 commit comments