Update README with deployment info #1094
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: 'Update README with deployment info' | |
| on: | |
| schedule: | |
| - cron: '0 23,5,11,17 * * *' | |
| workflow_dispatch: | |
| env: | |
| PROJECT_ID: 'tugidoko-dev' | |
| REGION: 'asia-northeast1' | |
| SERVICE: 'nginx-app' | |
| WORKLOAD_IDENTITY_PROVIDER: 'projects/109380428695/locations/global/workloadIdentityPools/github-pool/providers/github-provider' # TODO: update to your workload identity provider | |
| jobs: | |
| update-readme: | |
| runs-on: 'ubuntu-latest' | |
| permissions: | |
| contents: 'write' | |
| id-token: 'write' | |
| steps: | |
| - name: 'Checkout' | |
| uses: 'actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332' | |
| with: | |
| token: ${{ secrets.PAT_TOKEN }} | |
| - id: 'auth' | |
| name: 'Authenticate to Google Cloud' | |
| uses: 'google-github-actions/auth@f112390a2df9932162083945e46d439060d66ec2' | |
| with: | |
| workload_identity_provider: '${{ env.WORKLOAD_IDENTITY_PROVIDER }}' | |
| - name: 'Set up Cloud SDK' | |
| uses: 'google-github-actions/setup-gcloud@f0990588f1e5b5af6827153b93673613abdc6ec7' | |
| - name: 'Get Cloud Run image info' | |
| id: 'image-info' | |
| run: |- | |
| IMAGE=$(gcloud run services describe "${{ env.SERVICE }}" \ | |
| --region="${{ env.REGION }}" \ | |
| --project="${{ env.PROJECT_ID }}" \ | |
| --format='value(spec.template.spec.containers[0].image)') | |
| echo "image=${IMAGE}" >> $GITHUB_OUTPUT | |
| DIGEST=$(gcloud container images describe "${IMAGE}" \ | |
| --format='value(image_summary.digest)') | |
| echo "digest=${DIGEST}" >> $GITHUB_OUTPUT | |
| DIGEST_SHORT=$(echo "${DIGEST}" | sed 's/^sha256://' | cut -c1-7) | |
| echo "digest_short=${DIGEST_SHORT}" >> $GITHUB_OUTPUT | |
| echo "Full digest: ${DIGEST}" | |
| - name: 'Compare with local digest' | |
| id: 'compare-digest' | |
| run: |- | |
| CLOUD_RUN_DIGEST="${{ steps.image-info.outputs.digest }}" | |
| DIGEST_FILE=".nginx-app-digest" | |
| echo "Cloud Run digest: ${CLOUD_RUN_DIGEST}" | |
| if [ -f "$DIGEST_FILE" ]; then | |
| LOCAL_DIGEST=$(cat "$DIGEST_FILE") | |
| echo "Local digest: ${LOCAL_DIGEST}" | |
| if [ "$CLOUD_RUN_DIGEST" = "$LOCAL_DIGEST" ]; then | |
| echo "color=green" >> $GITHUB_OUTPUT | |
| echo "✅ Digests match - deployment is in sync" | |
| else | |
| echo "color=red" >> $GITHUB_OUTPUT | |
| echo "❌ Digests don't match - deployment is out of sync" | |
| fi | |
| else | |
| echo "color=yellow" >> $GITHUB_OUTPUT | |
| echo "⚠️ Local digest file not found" | |
| fi | |
| - name: 'Update README' | |
| run: |- | |
| perl -i -pe 'BEGIN{undef $/;} s|<!-- DEPLOY_DIGEST -->.*?<!-- /DEPLOY_DIGEST -->|<!-- DEPLOY_DIGEST -->\n<img src="https://img.shields.io/badge/Image%20Digest-${{ steps.image-info.outputs.digest_short }}-${{ steps.compare-digest.outputs.color }}?logo=docker" alt="Badge">\n<!-- /DEPLOY_DIGEST -->|gs' README.md | |
| - name: 'Commit changes' | |
| run: |- | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git stash | |
| git pull --rebase origin main | |
| git stash pop || git checkout --ours README.md | |
| git add README.md | |
| git diff --quiet && git diff --staged --quiet || \ | |
| (git commit -m "chore: update deployment info [skip ci cd]" && git push) |