|
| 1 | +name: Docs deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [next] |
| 6 | + paths: |
| 7 | + - 'docs/**' |
| 8 | + - 'Dockerfile' |
| 9 | + - '.dockerignore' |
| 10 | + - '.github/workflows/docs-deploy.yml' |
| 11 | + pull_request: |
| 12 | + types: [opened, synchronize, reopened, closed] |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + pull-requests: write |
| 18 | + id-token: write |
| 19 | + |
| 20 | +env: |
| 21 | + GCP_PROJECT_NUMBER: 204644970562 |
| 22 | + CLOUD_RUN_SERVICE: react-spring |
| 23 | + CLOUD_RUN_REGION: europe-west1 |
| 24 | + |
| 25 | +jobs: |
| 26 | + pr-changes: |
| 27 | + if: github.event_name == 'pull_request' && github.event.action != 'closed' |
| 28 | + runs-on: ubuntu-latest |
| 29 | + outputs: |
| 30 | + docs: ${{ steps.filter.outputs.docs }} |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + - uses: dorny/paths-filter@v3 |
| 34 | + id: filter |
| 35 | + with: |
| 36 | + filters: | |
| 37 | + docs: |
| 38 | + - 'docs/**' |
| 39 | + - 'Dockerfile' |
| 40 | + - '.dockerignore' |
| 41 | + - '.github/workflows/docs-deploy.yml' |
| 42 | +
|
| 43 | + deploy-prod: |
| 44 | + if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' |
| 45 | + runs-on: ubuntu-latest |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + - uses: google-github-actions/auth@v2 |
| 49 | + with: |
| 50 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 51 | + service_account: ${{ secrets.GCP_SA_EMAIL }} |
| 52 | + - uses: google-github-actions/setup-gcloud@v2 |
| 53 | + - name: Deploy to Cloud Run (prod) |
| 54 | + run: | |
| 55 | + gcloud run deploy "$CLOUD_RUN_SERVICE" \ |
| 56 | + --source . \ |
| 57 | + --region "$CLOUD_RUN_REGION" \ |
| 58 | + --quiet |
| 59 | +
|
| 60 | + deploy-preview: |
| 61 | + needs: pr-changes |
| 62 | + if: | |
| 63 | + github.event_name == 'pull_request' && |
| 64 | + github.event.action != 'closed' && |
| 65 | + needs.pr-changes.outputs.docs == 'true' |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + - uses: google-github-actions/auth@v2 |
| 70 | + with: |
| 71 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 72 | + service_account: ${{ secrets.GCP_SA_EMAIL }} |
| 73 | + - uses: google-github-actions/setup-gcloud@v2 |
| 74 | + - name: Deploy preview revision |
| 75 | + id: deploy |
| 76 | + run: | |
| 77 | + TAG="pr-${{ github.event.number }}" |
| 78 | + gcloud run deploy "$CLOUD_RUN_SERVICE" \ |
| 79 | + --source . \ |
| 80 | + --region "$CLOUD_RUN_REGION" \ |
| 81 | + --tag "$TAG" \ |
| 82 | + --no-traffic \ |
| 83 | + --quiet |
| 84 | + URL="https://${TAG}---${CLOUD_RUN_SERVICE}-${GCP_PROJECT_NUMBER}.${CLOUD_RUN_REGION}.run.app" |
| 85 | + echo "url=$URL" >> "$GITHUB_OUTPUT" |
| 86 | + - uses: marocchino/sticky-pull-request-comment@v2 |
| 87 | + with: |
| 88 | + header: docs-preview |
| 89 | + message: | |
| 90 | + **Docs preview:** ${{ steps.deploy.outputs.url }} |
| 91 | +
|
| 92 | + Deployed at `${{ github.sha }}`. Updates on every push. |
| 93 | +
|
| 94 | + cleanup-preview: |
| 95 | + if: github.event_name == 'pull_request' && github.event.action == 'closed' |
| 96 | + runs-on: ubuntu-latest |
| 97 | + steps: |
| 98 | + - uses: google-github-actions/auth@v2 |
| 99 | + with: |
| 100 | + workload_identity_provider: ${{ secrets.WIF_PROVIDER }} |
| 101 | + service_account: ${{ secrets.GCP_SA_EMAIL }} |
| 102 | + - uses: google-github-actions/setup-gcloud@v2 |
| 103 | + # tolerate failure: the PR may not have triggered a preview deploy |
| 104 | + - name: Remove preview tag |
| 105 | + run: | |
| 106 | + gcloud run services update-traffic "$CLOUD_RUN_SERVICE" \ |
| 107 | + --region "$CLOUD_RUN_REGION" \ |
| 108 | + --remove-tags "pr-${{ github.event.number }}" \ |
| 109 | + --quiet || echo "No preview tag to remove" |
0 commit comments