-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (157 loc) · 5.25 KB
/
wrangler.yaml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
##################################################
# Name: wrangler.yaml
# Description:
# A Workflow that builds a static website using
# Hugo before publishing to Cloudflare Workers
# with the Wrangler CLI
##################################################
name: Wrangler
on:
# Automatically run anytime there
# is a push to the default branch
push:
branches:
- trunk
# Automatically run anytime a PR
# targets the default branch
# for the defined types.
pull_request:
branches:
- trunk
types:
- opened
- reopened
- synchronize
- review_requested
permissions:
contents: read
pull-requests: write
checks: read
statuses: read
defaults:
run:
shell: bash
env:
HUGO_VERSION: 0.111.3
WRANGLER_API_TOKEN: ${{ secrets.CLOUDFLARE_WORKERS_TOKEN }}
BRANCH_NAME_CURRENT: ${{ github.head_ref || github.ref_name }}
BRANCH_NAME_DEFAULT: ${{ github.event.repository.default_branch }}
jobs:
##################################################
# Publish to Cloudflare Workers using the Wrangler CLI
##################################################
deploy:
name: Publish website
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
steps:
- id: checkout_repository
name: Checkout repository with submodules
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
clean: true
persist-credentials: true
- id: hugo_install
name: Download and Install Hugo
run: |
wget https://github.com/gohugoio/hugo/releases/download/v${{ env.HUGO_VERSION }}/hugo_extended_${{ env.HUGO_VERSION }}_linux-amd64.deb
sudo dpkg -i hugo_extended_${{ env.HUGO_VERSION }}_linux-amd64.deb
hugo version
- id: hugo_cleanup
name: Remove unwanted Hugo files before build
run: |
rm -f themes/*/content/post/* || echo "Failed to remove posts from theme"
rm -f themes/*/data/authors/* || echo "Failed to remove authors from theme"
rm -rf themes/*/exampleSite || echo "Failed to remove exampleSite from theme"
rm -rf assets/images/backup || echo "Failed to remove extra images"
rm -rf static/images/backup || echo "Failed to remove extra images"
- id: hugo_modules
name: Download Hugo modules
run: |
if [[ -f package.json ]]; then
echo "Running npm install"
npm install
fi
if [[ -f "go.mod" ]]; then
echo "Downloading Go modules"
go mod download -x
else
echo "No go.mod file found"
fi
echo "Downloading Hugo modules"
hugo mod clean
hugo mod tidy
hugo mod graph
# Any branch other than the default is staged for preview.
- id: hugo_build_staging
name: Build the website using Hugo (Staging)
if: env.BRANCH_NAME_CURRENT != env.BRANCH_NAME_DEFAULT
env:
TZ: "Australia/Sydney"
run: |
hugo --verbose --gc --minify --cleanDestinationDir --environment staging
touch public/.nojekyll
ls -la public/
# The default branch is 'Production'
- id: hugo_build_production
if: env.BRANCH_NAME_CURRENT == env.BRANCH_NAME_DEFAULT
name: Build the website using Hugo (Production)
env:
TZ: "Australia/Sydney"
run: |
hugo --verbose --gc --minify --cleanDestinationDir --environment production
touch public/.nojekyll
ls -la public/
- id: publish_website_staging
name: Publish website using Wrangler (Staging)
if: |
env.BRANCH_NAME_CURRENT != env.BRANCH_NAME_DEFAULT &&
steps.hugo_build_staging.outcome == 'success'
uses: cloudflare/wrangler-action@v3.4.1
with:
environment: staging
apiToken: ${{ env.WRANGLER_API_TOKEN }}
preCommands: |
npm --prefix workers-site install
command: deploy --env staging
# Only 'trunk' branch is pushed to the Production website
- id: publish_website_production
name: Publish website using Wrangler (Production)
if: |
env.BRANCH_NAME_CURRENT == env.BRANCH_NAME_DEFAULT &&
steps.hugo_build_production.outcome == 'success'
uses: cloudflare/wrangler-action@v3.4.1
with:
environment: production
apiToken: ${{ env.WRANGLER_API_TOKEN }}
preCommands: |
npm --prefix workers-site install
command: deploy --env production
##################################################
# Giphy thumbs up or down
##################################################
check:
name: PR Status Checks
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: true
matrix:
os:
- ubuntu-latest
needs: deploy
steps:
- name: PR Status Giphy
id: pr-status-giphy
uses: dgteixeira/pr-status-giphy-action@v2
if: github.event_name == 'pull_request'
env:
GIPHY_API_KEY: ${{ secrets.GIPHY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}