Skip to content

Check API

Check API #183

Workflow file for this run

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