News Sync #259
This file contains hidden or 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: News Sync | |
| on: | |
| schedule: | |
| - cron: '17 8,18 * * *' # 2x/day at 08:17 and 18:17 UTC | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| concurrency: | |
| group: news-sync | |
| cancel-in-progress: false | |
| jobs: | |
| sync-news: | |
| runs-on: ubuntu-latest | |
| environment: news-sync | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install X11 dev headers (required by golang.design/x/clipboard) | |
| run: sudo apt-get install -y libx11-dev | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: 'stable' | |
| - run: go build -o sap-devs . | |
| - name: Fetch news episodes | |
| env: | |
| YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }} | |
| run: ./sap-devs news fetch-index --output content/packs/base/news-episodes.json | |
| - name: Open or update PR if changed | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| if git diff --quiet content/packs/base/news-episodes.json 2>/dev/null; then | |
| echo "No changes." | |
| exit 0 | |
| fi | |
| BRANCH="bot/news-sync-update" | |
| git checkout -B "$BRANCH" | |
| git add content/packs/base/news-episodes.json | |
| git commit -m "chore: update news episode index" | |
| git push -f origin "$BRANCH" | |
| EXISTING=$(gh pr list --head "$BRANCH" --json number -q '.[0].number // empty' 2>/dev/null || echo "") | |
| if [ -z "$EXISTING" ]; then | |
| gh pr create \ | |
| --title "chore: update news episode index" \ | |
| --body "Automated update of \`content/packs/base/news-episodes.json\`." \ | |
| --base main --head "$BRANCH" | |
| else | |
| echo "PR #$EXISTING already open; new commit pushed to $BRANCH" | |
| fi | |
| gh pr merge --auto --squash "$BRANCH" || \ | |
| echo "::warning::auto-merge not armed; check 'Allow auto-merge' is enabled in repo Settings" |