-
-
Notifications
You must be signed in to change notification settings - Fork 669
44 lines (39 loc) · 1.44 KB
/
purge-cache.yml
File metadata and controls
44 lines (39 loc) · 1.44 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
name: Purge Fastly Cache
on:
push:
branches: [main]
paths: ['static/**', 'templates/**', '**/templates/**']
workflow_dispatch:
inputs:
target:
description: 'Surrogate key to purge'
required: true
default: 'pydotorg-app'
type: choice
options: [pydotorg-app, downloads, events, sponsors, jobs]
permissions: {}
jobs:
purge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
if: github.event_name == 'push'
with:
fetch-depth: 0
- name: Resolve keys
id: keys
run: |
if [ -n "${{ inputs.target }}" ]; then
echo "keys=${{ inputs.target }}" >> "$GITHUB_OUTPUT"
elif git diff --name-only ${{ github.event.before }}..${{ github.sha }} | grep -qE '^(static/|templates/)'; then
echo "keys=pydotorg-app" >> "$GITHUB_OUTPUT"
else
echo "keys=$(git diff --name-only ${{ github.event.before }}..${{ github.sha }} | grep -oP '^apps/\K[^/]+(?=/(templates|static)/)' | sort -u | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
fi
- name: Purge ${{ steps.keys.outputs.keys || 'pydotorg-app' }}
run: |
for KEY in ${{ steps.keys.outputs.keys || 'pydotorg-app' }}; do
curl -fsS -X POST \
"https://api.fastly.com/service/${{ secrets.FASTLY_SERVICE_ID }}/purge/$KEY" \
-H "Fastly-Key: ${{ secrets.FASTLY_API_KEY }}"
done