Run Poem Bot #305
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: 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 }} |