RSS Watcher #31
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 Watcher | |
| on: | |
| schedule: | |
| # Run every 10 minutes | |
| - cron: '*/10 * * * *' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| scan: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ github.token }} | |
| fetch-depth: 1 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Ensure logs folder exists | |
| run: mkdir -p logs | |
| - name: Run RSS scan | |
| env: | |
| RSS_WEBHOOK: ${{ secrets.RSS_WEBHOOK }} | |
| run: npm run rss | |
| - name: Commit results to master | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # Configure git with token | |
| git config --global user.name "ModelWatcher" | |
| git config --global user.email "modelwatcher@github.com" | |
| # Save the new state before resetting | |
| cp logs/rss-state.json /tmp/rss-state-new.json 2>/dev/null || true | |
| # Fetch latest and reset | |
| git fetch origin master | |
| git reset --hard origin/master | |
| # Create logs dir and copy new state if we have one | |
| mkdir -p logs | |
| if [ -f /tmp/rss-state-new.json ]; then | |
| cp /tmp/rss-state-new.json logs/rss-state.json | |
| fi | |
| # Check if there are actual changes to commit | |
| if [ -f logs/rss-state.json ]; then | |
| ORIG_HASH=$(git show origin/master:logs/rss-state.json 2>/dev/null | sha256sum | cut -d' ' -f1 || echo "empty") | |
| NEW_HASH=$(sha256sum logs/rss-state.json | cut -d' ' -f1) | |
| if [ "$ORIG_HASH" = "$NEW_HASH" ] && [ "$ORIG_HASH" != "empty" ]; then | |
| echo "No post changes detected - skipping commit" | |
| exit 0 | |
| fi | |
| fi | |
| # Add and commit (only if there are changes) | |
| # Force add logs folder since it's gitignored | |
| git add -f logs/rss-state.json || true | |
| if ! git diff --quiet --staged; then | |
| git commit -m "Update RSS state - $(date -u +'%Y-%m-%d %H:%M UTC')" | |
| git push origin master | |
| echo "Updated RSS state on master branch" | |
| else | |
| echo "No changes to commit" | |
| fi |