Skip to content

Commit 9c8db54

Browse files
committed
Move purge keys to the last step
Signed-off-by: Thanabodee Charoenpiriyakij <[email protected]>
1 parent 7f26c5f commit 9c8db54

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

.github/workflows/release.yml

+39-5
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ jobs:
166166
steps:
167167
- uses: actions/download-artifact@v4
168168

169+
- name: Init purge keys file
170+
run: |
171+
touch purge_keys.txt
172+
169173
- name: Utils.sh
170174
run: |
171175
cat << 'EOF' > utils.sh
@@ -188,6 +192,7 @@ jobs:
188192
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
189193
}
190194
EOF
195+
191196
- name: Upload Precompiled to S3
192197
run: |
193198
source utils.sh
@@ -201,18 +206,19 @@ jobs:
201206
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${dest}" \
202207
--cache-control "public,max-age=3600" \
203208
--metadata "{\"surrogate-key\":\"builds builds/elixir builds/elixir/${surrogate_key}\",\"surrogate-control\":\"public,max-age=604800\"}"
209+
echo "builds/elixir/${surrogate_key}" >> purge_keys.txt
204210
205211
if [ "$zip" == "elixir-otp-${OTP_GENERIC_VERSION}.zip" ]; then
206212
aws s3 cp "${zip}" "s3://${AWS_S3_BUCKET}/builds/elixir/${ref_name}.zip" \
207213
--cache-control "public,max-age=3600" \
208214
--metadata "{\"surrogate-key\":\"builds builds/elixir builds/elixir/${ref_name}\",\"surrogate-control\":\"public,max-age=604800\"}"
209-
purge builds/elixir/${ref_name}
215+
echo builds/elixir/${ref_name} >> purge_keys.txt
210216
fi
211217
done
218+
212219
- name: Upload Docs to S3
213220
working-directory: Docs
214221
run: |
215-
source ../utils.sh
216222
version=$(echo ${{ github.ref_name }} | sed -e 's/^v//g')
217223
218224
unzip Docs.zip
@@ -222,17 +228,17 @@ jobs:
222228
app=$(echo "$f" | sed s/"doc\/"//)
223229
tarball="${app}-${version}.tar.gz"
224230
surrogate_key="docs/${app}-${version}"
231+
225232
tar -czf "${tarball}" -C "doc/${app}" .
226233
aws s3 cp "${tarball}" "s3://${AWS_S3_BUCKET}/docs/${tarball}" \
227234
--cache-control "public,max-age=3600" \
228235
--metadata "{\"surrogate-key\":\"${surrogate_key}\",\"surrogate-control\":\"public,max-age=604800\"}"
229-
purge "${surrogate_key}"
236+
echo "${surrogate_key}" >> purge_keys.txt
230237
fi
231238
done
232239
233240
- name: Update builds txt
234241
run: |
235-
source utils.sh
236242
date="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
237243
ref_name=${{ github.ref_name }}
238244
@@ -256,4 +262,32 @@ jobs:
256262
aws s3 cp builds.txt "s3://${AWS_S3_BUCKET}/builds/elixir/builds.txt" \
257263
--cache-control "public,max-age=3600" \
258264
--metadata '{"surrogate-key":"builds builds/elixir builds/elixir/txt","surrogate-control":"public,max-age=604800"}'
259-
purge builds/elixir/txt
265+
266+
echo 'buils/elixir/txt' >> purge_keys.txt
267+
268+
- name: Flush cache
269+
run: |
270+
function purge_key() {
271+
echo "Purge key $2"
272+
# curl \
273+
# -X POST \
274+
# -H "Fastly-Key: ${FASTLY_KEY}" \
275+
# -H "Accept: application/json" \
276+
# -H "Content-Length: 0" \
277+
# "https://api.fastly.com/service/$1/purge/$2"
278+
}
279+
280+
function purge() {
281+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
282+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
283+
sleep 2
284+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
285+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
286+
sleep 2
287+
purge_key ${FASTLY_REPO_SERVICE_ID} $1
288+
purge_key ${FASTLY_BUILDS_SERVICE_ID} $1
289+
}
290+
291+
for key in $(cat purge_keys.txt); do
292+
purge "${key}"
293+
done

0 commit comments

Comments
 (0)