Skip to content

Commit 4a69886

Browse files
committed
Wait for Cloud Run deploy before env sync
1 parent cd8f260 commit 4a69886

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

.github/workflows/sync-cloud-run-env.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ jobs:
100100
project_id: ${{ env.GCP_PROJECT_ID }}
101101
version: ">= 416.0.0"
102102

103+
- name: Wait for Cloud Run deployment of current commit
104+
if: steps.config.outputs.enabled == 'true'
105+
run: |
106+
set -euo pipefail
107+
108+
target_sha="${GITHUB_SHA}"
109+
deadline=$((SECONDS + 1800))
110+
111+
while true; do
112+
deployed_sha="$(gcloud run services describe "${CLOUD_RUN_SERVICE}" --region "${CLOUD_RUN_REGION}" --format='value(spec.template.metadata.labels.commit-sha)' 2>/dev/null || true)"
113+
if [ -n "${deployed_sha}" ] && [ "${deployed_sha}" = "${target_sha}" ]; then
114+
echo "Cloud Run service ${CLOUD_RUN_SERVICE} is on commit ${deployed_sha}."
115+
break
116+
fi
117+
118+
if [ "${SECONDS}" -ge "${deadline}" ]; then
119+
echo "Timed out waiting for Cloud Run service ${CLOUD_RUN_SERVICE} to deploy commit ${target_sha}. Last seen commit: ${deployed_sha:-<none>}" >&2
120+
exit 1
121+
fi
122+
123+
echo "Waiting for Cloud Run service ${CLOUD_RUN_SERVICE} to deploy commit ${target_sha}. Last seen commit: ${deployed_sha:-<none>}" >&2
124+
sleep 10
125+
done
126+
103127
- name: Sync Cloud Run environment
104128
if: steps.config.outputs.enabled == 'true'
105129
run: |

tests/test_sync_cloud_run_env_workflow.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ grep -Fq 'permissions:' "$workflow_file"
1010
grep -Fq 'id-token: write' "$workflow_file"
1111
grep -Fq 'workload_identity_provider: ${{ env.GCP_WORKLOAD_IDENTITY_PROVIDER }}' "$workflow_file"
1212
grep -Fq 'service_account: ${{ env.GCP_WORKLOAD_IDENTITY_SERVICE_ACCOUNT }}' "$workflow_file"
13+
grep -Fq 'Wait for Cloud Run deployment of current commit' "$workflow_file"
14+
grep -Fq 'target_sha="${GITHUB_SHA}"' "$workflow_file"
15+
grep -Fq "gcloud run services describe \"\${CLOUD_RUN_SERVICE}\" --region \"\${CLOUD_RUN_REGION}\" --format='value(spec.template.metadata.labels.commit-sha)'" "$workflow_file"
16+
grep -Fq 'Timed out waiting for Cloud Run service ${CLOUD_RUN_SERVICE} to deploy commit ${target_sha}. Last seen commit: ${deployed_sha:-<none>}' "$workflow_file"
1317
grep -Fq 'ENABLE_GITHUB_ENV_SYNC: ${{ vars.ENABLE_GITHUB_ENV_SYNC }}' "$workflow_file"
1418
grep -Fq 'CLOUD_RUN_REGION: ${{ vars.CLOUD_RUN_REGION }}' "$workflow_file"
1519
grep -Fq 'CLOUD_RUN_SERVICE: ${{ vars.CLOUD_RUN_SERVICE }}' "$workflow_file"

0 commit comments

Comments
 (0)