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