-
Notifications
You must be signed in to change notification settings - Fork 122
47 lines (46 loc) · 1.85 KB
/
shielding-check-cron.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
name: Datacenters check cron job
on:
schedule:
# UTC, at midnight every Monday
- cron: "0 0 * * 1"
jobs:
check-diff-and-create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Fetch latest JSON via Fastly API
run: |
curl -s https://api.fastly.com/datacenters -H "fastly-key: ${FASTLY_API_KEY}" --fail -o ./temp.json
env:
FASTLY_API_KEY: ${{ secrets.FASTLY_API_KEY }}
- name: Update JSON
id: update-json
if: success()
run: |
cat ./temp.json | jq . > etc/shielding/datacenters.json
rm -f ./temp.json
echo "diff-count=$(git diff --name-only | wc -l)" >> "$GITHUB_OUTPUT"
SHA1=`sha1sum etc/shielding/datacenters.json | awk '{print $1}'`
echo "sha1=$SHA1" >> "$GITHUB_OUTPUT"
echo "pr-count=$(gh pr list --search "${SHA1} in:title is:open" --json title -q '.[] | .title' | wc -l)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check diff and create PR
if: |
steps.update-json.outputs.pr-count == 0 &&
steps.update-json.outputs.diff-count > 0
run: |
DATE=`date +"%Y%m%d"`
BRANCH_NAME="datacenters-json-auto-update-${DATE}"
git config user.name "github-actions"
git config user.email "${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>"
git checkout -b "${BRANCH_NAME}"
git add .
git commit -m "Update datacenters.json"
git push origin "${BRANCH_NAME}"
gh pr create --title "Update datacenters.json - ${{ steps.update-json.outputs.sha1 }}" --base master --head "${BRANCH_NAME}" \
--body "Submitted by GitHub Actions automation.
You may want to close old bot PRs if they haven't merged yet."
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}