Skip to content

Sync from Reddit #20847

Sync from Reddit

Sync from Reddit #20847

name: Sync from Reddit
on:
workflow_dispatch:
schedule:
# run twice per hour at arbitrary minutes, avoiding busy top of hour
- cron: 17,47 * * * *
jobs:
sync-from-reddit:
name: Sync from Reddit
runs-on: ubuntu-22.04
outputs:
new-commit: ${{ steps.push.outputs.commit }}
permissions:
contents: write
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- uses: actions/checkout@v4
with:
ref: ${{ steps.extract_branch.outputs.branch }}
- name: Configure git user
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Setup Python
uses: actions/setup-python@v5
- name: Setup python requirements
run: pip install -r requirements.txt
- name: Download wiki from Reddit
run: python ./download-wiki.py
env:
REDDIT_CLIENT_ID: ${{ secrets.REDDIT_CLIENT_ID }}
REDDIT_CLIENT_SECRET: ${{ secrets.REDDIT_CLIENT_SECRET }}
REDDIT_USER_AGENT: ${{ secrets.REDDIT_USER_AGENT }}
REDDIT_USER_NAME: ${{ secrets.REDDIT_USER_NAME }}
REDDIT_PASSWORD: ${{ secrets.REDDIT_PASSWORD }}
- name: Push changes (if any)
id: push
run: |
git push
if [ "$GITHUB_SHA" != "$(git rev-parse HEAD)" ]; then
echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
fi
# Pushes from GitHub Actions do not trigger further actions; manually call deploy
deploy:
name: Deploy site
needs: sync-from-reddit
if: "${{ needs.sync-from-reddit.outputs.new-commit != '' }}"
permissions:
contents: write
uses: ./.github/workflows/deploy.yml
with:
new-commit: ${{ needs.sync-from-reddit.outputs.new-commit }}