Skip to content

Merge pull request #19 from tarilen/dependabot/github_actions/github-… #36

Merge pull request #19 from tarilen/dependabot/github_actions/github-…

Merge pull request #19 from tarilen/dependabot/github_actions/github-… #36

Workflow file for this run

name: deploy
on:
push:
branches: [ main ]
paths:
- 'site/**'
- 'tofu/**'
- '.github/workflows/deploy.yml'
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
# Standard Azure envs for azure/login
ARM_USE_OIDC: "true"
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
# TF_VAR_ prefixes map to OpenTofu/Terraform variables
TF_VAR_client_id: ${{ secrets.AZURE_CLIENT_ID }}
TF_VAR_tenant_id: ${{ secrets.AZURE_TENANT_ID }}
TF_VAR_subscription_id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
jobs:
provision-and-upload:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Stamp Commit SHA
run: |
echo $GITHUB_SHA > site/version.txt
- name: Azure OIDC login
uses: azure/login@532459ea530d8321f2fb9bb10d1e0bcf23869a43 # v3.0.0
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Install OpenTofu
uses: opentofu/setup-opentofu@a1320f892987e89d278cc92dc5adc984fb93aca4 # v2.0.2
with:
tofu_version: "1.6.0"
- name: Init/Apply OpenTofu
working-directory: tofu
run: |
tofu init -upgrade
tofu apply -auto-approve -input=false
- name: Read outputs
id: tfout
working-directory: tofu
run: |
echo "web=$(tofu output -raw static_web_url)" >> "$GITHUB_OUTPUT"
TOKEN=$(tofu output -raw swa_api_token)
echo "::add-mask::$TOKEN"
echo "token=$TOKEN" >> "$GITHUB_OUTPUT"
- name: Deploy site to Static Web App
uses: Azure/static-web-apps-deploy@1a947af9992250f3bc2e68ad0754c0b0c11566c9 # v1
with:
azure_static_web_apps_api_token: ${{ steps.tfout.outputs.token }}
action: upload
app_location: "site"
skip_app_build: true
- name: Post the site URL
run: |
echo "Site: ${{ steps.tfout.outputs.web }}"
- name: Post-deploy smoke test
env:
SITE: https://resume.theginger.dev
run: |
echo "Post deploy SHA verification"
for i in $(seq 1 6); do
isLive=$(curl -fsSL --max-time 10 "$SITE/version.txt?cb=$GITHUB_SHA" | tr -d '[:space:]' || true)
if [ "${isLive}" = "${GITHUB_SHA}" ]; then
body=$(curl -fsSL --max-time 10 "$SITE/?cb=$GITHUB_SHA" || true)
if [[ "${body}" == *"Damian Ortega"* ]]; then
echo "$GITHUB_SHA is live and content is intact"; exit 0
fi
fi
echo "attempt $i: not ready (live='$isLive'); waiting…"; sleep 10
done
echo "::error::smoke test failed — new version not live or content assertion failed"
exit 1