-
Notifications
You must be signed in to change notification settings - Fork 2
64 lines (52 loc) · 1.49 KB
/
run-poem-bot.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
56
57
58
59
60
61
62
63
64
name: Run Poem Bot
on:
schedule:
- cron: '0 5,15 * * *'
workflow_dispatch:
permissions:
contents: write
jobs:
run-poem-bot:
runs-on: ubuntu-latest
environment: env
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Update config.json with bot token
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
python - <<EOF
import json
import os
with open('config.json', 'r') as f:
config = json.load(f)
config['bot_token'] = os.environ['BOT_TOKEN']
with open('config.json', 'w') as f:
json.dump(config, f, indent=4)
EOF
- name: Run main.py
run: python main.py
- name: Check for changes in poem_ids.json
id: git-check
run: |
git diff --exit-code --quiet poem_ids.json || echo "changed=true" >> $GITHUB_OUTPUT
- name: Commit and push if changed
if: steps.git-check.outputs.changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add poem_ids.json
git commit -m "Update poem_ids.json"
git pull --no-rebase
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}