Skip to content

Commit f24411c

Browse files
committed
ci: comment OpenTofu plans on Cloudflare worker prod PRs
1 parent 5bb0ce0 commit f24411c

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

.github/workflows/cloudflare-worker-preview.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
} >> "$GITHUB_OUTPUT"
3535
3636
- name: Setup node
37-
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
37+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
3838
with:
3939
node-version-file: '.node-version'
4040
package-manager-cache: false
@@ -99,7 +99,7 @@ jobs:
9999
} >> "$GITHUB_STEP_SUMMARY"
100100
101101
- name: Publish preview URL
102-
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
102+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
103103
env:
104104
MARKER: '<!-- cloudflare-worker-preview -->'
105105
PREVIEW_URL: ${{ steps.preview.outputs.preview_url }}

.github/workflows/cloudflare-worker-prod.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
- dev
1111
workflow_dispatch:
1212

13+
env:
14+
OPENTOFU_VERSION: '1.11.5'
15+
1316
concurrency:
1417
group: cloudflare-infra
1518
cancel-in-progress: false
@@ -20,8 +23,10 @@ jobs:
2023
runs-on: ubuntu-latest
2124
permissions:
2225
contents: read
26+
pull-requests: write
2327
env:
2428
CLOUDFLARE_API_TOKEN: ${{ secrets.TF_CLOUDFLARE_API_TOKEN }}
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2530
TF_VAR_account_id: ${{ secrets.TF_VAR_ACCOUNT_ID }}
2631
TF_VAR_zone_id: ${{ secrets.TF_VAR_ZONE_ID }}
2732
TF_HTTP_ADDRESS: ${{ secrets.TF_HTTP_ADDRESS }}
@@ -49,7 +54,7 @@ jobs:
4954
printf 'TF_VAR_workers_message=%s\n' "$workers_message" >> "$GITHUB_ENV"
5055
5156
- name: Setup node
52-
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
57+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
5358
with:
5459
node-version-file: '.node-version'
5560
cache: 'npm'
@@ -65,7 +70,7 @@ jobs:
6570
- name: Setup OpenTofu
6671
uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8
6772
with:
68-
tofu_version: 1.11.5
73+
tofu_version: ${{ env.OPENTOFU_VERSION }}
6974

7075
- name: Check formatting
7176
run: tofu fmt -check
@@ -76,8 +81,11 @@ jobs:
7681
- name: Validate configuration
7782
run: tofu validate -no-color
7883

79-
- name: Plan infrastructure
80-
run: tofu plan -input=false -lock=false -no-color
84+
- name: Comment PR plan
85+
uses: dflook/tofu-plan@3f5dc358343fb58cd60f83b019e810315aa8258f # v2.2.3
86+
with:
87+
path: infra/web
88+
label: production
8189

8290
apply:
8391
if: (github.event_name == 'push' && github.ref_name == 'dev') || github.event_name == 'workflow_dispatch'
@@ -113,7 +121,7 @@ jobs:
113121
printf 'TF_VAR_workers_message=%s\n' "$workers_message" >> "$GITHUB_ENV"
114122
115123
- name: Setup node
116-
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
124+
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
117125
with:
118126
node-version-file: '.node-version'
119127
cache: 'npm'
@@ -129,7 +137,7 @@ jobs:
129137
- name: Setup OpenTofu
130138
uses: opentofu/setup-opentofu@9d84900f3238fab8cd84ce47d658d25dd008be2f # v1.0.8
131139
with:
132-
tofu_version: 1.11.5
140+
tofu_version: ${{ env.OPENTOFU_VERSION }}
133141

134142
- name: Check formatting
135143
run: tofu fmt -check

infra/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Preview deploys:
9797

9898
Production deploys:
9999

100+
- PRs that change `infra/web` get an OpenTofu plan comment on the PR from
101+
`.github/workflows/cloudflare-worker-prod.yml`.
100102
- `.github/workflows/cloudflare-worker-prod.yml` builds the app and runs `tofu apply` on
101103
pushes to `dev`, or via manual workflow dispatch.
102104
- `tofu apply` uploads `dist/` as a new immutable Worker version with

0 commit comments

Comments
 (0)