-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (47 loc) · 1.6 KB
/
scheduled.yml
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
name: Check API
on:
schedule:
- cron: '0 8,22 * * *'
jobs:
check_api:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.compare.outputs.changed }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Fetch current blog posts from API
run: |
curl -s https://107106.xyz/blog/list/all > src/routes/blog/[slug]/new_list.json
- name: Fetch previous blog posts from cache
id: fetch_previous
run: |
if [ -f src/routes/blog/[slug]/list.json ]; then
echo "list found"
else
echo "[]" > src/routes/blog/[slug]/list.json
fi
- name: Compare lists
id: compare
run: |
if cmp -s src/routes/blog/[slug]/new_list.json src/routes/blog/[slug]/list.json; then
echo "::set-output name=changed::false"
echo "list not changed"
else
echo "::set-output name=changed::true"
cp src/routes/blog/[slug]/new_list.json src/routes/blog/[slug]/list.json
echo "list changed"
fi
- name: Commit and push
if: steps.compare.outputs.changed == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add src/routes/blog/[slug]/list.json
git commit -m "update blog posts cache"
git push
build:
name: Build
needs: check_api
if: needs.check_api.outputs.changed == 'true'
uses: ./.github/workflows/build.yml