RSS New Episode PR #324
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: RSS New Episode PR | |
| on: | |
| schedule: | |
| # Runs every 2 hours | |
| - cron: '0 */2 * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| check-rss: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Fetch new episodes from RSS | |
| run: node scripts/rss-to-posts.js | |
| env: | |
| # Override by setting RSS_FEED_URL as a repository variable | |
| RSS_FEED_URL: ${{ vars.RSS_FEED_URL != '' && vars.RSS_FEED_URL || 'https://pinecast.com/feed/housefinesse' }} | |
| - name: Check for new files | |
| id: diff | |
| run: | | |
| NEW_POSTS=$(git ls-files --others --exclude-standard src/posts/) | |
| NEW_IMAGES=$(git ls-files --others --exclude-standard src/img/cover-images/) | |
| NEW_ALL=$(printf '%s\n%s' "$NEW_POSTS" "$NEW_IMAGES" | grep -v '^$' || true) | |
| if [ -z "$NEW_ALL" ]; then | |
| echo "found=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| echo "found=true" >> "$GITHUB_OUTPUT" | |
| # Derive branch name from first new post filename | |
| FIRST_POST=$(echo "$NEW_POSTS" | sort | head -1) | |
| BASENAME=$(basename "$FIRST_POST" .md) | |
| # Strip YYYY-MM-DD- prefix to get the episode slug | |
| EPISODE_SLUG=$(echo "$BASENAME" | sed 's/^[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}-//') | |
| POST_COUNT=$(echo "$NEW_POSTS" | grep -c '.' || echo 0) | |
| if [ "$POST_COUNT" -gt 1 ]; then | |
| echo "branch=rss-episodes/$(date -u +%Y%m%d)" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "branch=rss-episode/$EPISODE_SLUG" >> "$GITHUB_OUTPUT" | |
| fi | |
| # Store file list for PR body | |
| echo "files<<EOF" >> "$GITHUB_OUTPUT" | |
| echo "$NEW_ALL" >> "$GITHUB_OUTPUT" | |
| echo "EOF" >> "$GITHUB_OUTPUT" | |
| - name: Create branch and open PR | |
| if: steps.diff.outputs.found == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| BRANCH="${{ steps.diff.outputs.branch }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # Create or reset the branch locally | |
| git checkout -B "$BRANCH" | |
| git add src/posts/ src/img/cover-images/ | |
| git commit -m "feat: add new episode from RSS feed ($BRANCH)" | |
| # Push; force-with-lease is safe — we just created this branch from main | |
| git push --force-with-lease -u origin "$BRANCH" | |
| FILE_LIST=$(echo "${{ steps.diff.outputs.files }}" | sed 's/^/- /') | |
| # Only open a PR if one doesn't already exist for this branch | |
| EXISTING_PR=$(gh pr list --head "$BRANCH" --state open --json number --jq '.[0].number') | |
| if [ -n "$EXISTING_PR" ]; then | |
| echo "PR #$EXISTING_PR already open for $BRANCH — skipping gh pr create." | |
| exit 0 | |
| fi | |
| EPISODE_SLUG=$(echo "$BRANCH" | sed 's|rss-episode[s]*/||') | |
| { | |
| echo "## New episode from RSS feed" | |
| echo "" | |
| echo "Auto-generated from Pinecast RSS. Please review before merging:" | |
| echo "" | |
| echo "- [ ] Post content and description look correct" | |
| echo "- [ ] Cover image downloaded OK (check \`src/img/cover-images/\`)" | |
| echo "- [ ] Tags are accurate" | |
| echo "" | |
| echo "**New files:**" | |
| echo "$FILE_LIST" | |
| } > /tmp/pr-body.md | |
| gh pr create \ | |
| --base main \ | |
| --head "$BRANCH" \ | |
| --title "New episode: $EPISODE_SLUG" \ | |
| --body-file /tmp/pr-body.md |