update data.json #1582
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: update data.json | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
scrape_and_save: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "16" | |
- name: Install dependencies | |
run: npm install | |
- name: Run scraping script | |
run: node src/scrape.js > data.json | |
- name: Commit data.json | |
run: | | |
filename="data.json" | |
if grep -q -i "error" $filename; then | |
echo "存在错误。" | |
cat $filename | |
else | |
echo "没有错误。" | |
git config --global user.name "NowScott" | |
git config --global user.email "[email protected]" | |
if ! git diff --quiet --exit-code; then | |
git add $filename | |
git commit -m "Update data.json" | |
git push | |
else | |
echo "没有变化。" | |
fi | |
fi | |