forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
purge-fastly
executable file
·34 lines (29 loc) · 1.04 KB
/
purge-fastly
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
#!/usr/bin/env bash
# [start-readme]
#
# Run this script to manually purge the [Fastly cache](https://github.com/github/docs-internal#fastly-cdn).
# Note this script requires a `FASTLY_SERVICE_ID` and `FASTLY_TOKEN` in your `.env` file.
#
# [end-readme]
usage()
{
echo "Error! Unable to purge the Fastly cache"
echo ""
echo "Add FASTLY_SERVICE_ID and FASTLY_TOKEN to the environment or create a .env file in the project root and set these values:"
echo ""
echo "FASTLY_SERVICE_ID=<value-goes-here>"
echo "FASTLY_TOKEN=<value-goes-here>"
exit
}
# attempt to load from .env if Fastly config is not already in ENV
if [ -z "$FASTLY_SERVICE_ID" ] || [ -z "$FASTLY_TOKEN" ]; then
# abort if .env file doesn't exist
[ -f .env ] || usage
# load config from .env
export $(cat .env | xargs)
fi
if [ -z "$FASTLY_SERVICE_ID" ] || [ -z "$FASTLY_TOKEN" ]; then
usage
else
curl -H "fastly-key: $FASTLY_TOKEN" -H "accept: application/json" -H "fastly-soft-purge: 1" -X POST "https://api.fastly.com/service/$FASTLY_SERVICE_ID/purge/all-the-things"
fi