Deploy #7344
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: Deploy | |
| on: | |
| schedule: | |
| - cron: '0 * * * *' # Every hour | |
| push: | |
| branches: [main] | |
| workflow_dispatch: # Manual trigger | |
| # Add permissions for the GITHUB_TOKEN | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| env: | |
| NODE_OPTIONS: '--max-http-header-size=16384' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Fetch new feeds | |
| run: npm run refresh | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name 'GitHub Action' | |
| git config --global user.email '[email protected]' | |
| - name: Commit feed updates | |
| run: | | |
| git add src/content/feeds/ | |
| git diff --staged --quiet || (git commit -m "Update feeds" && git push) | |
| - name: Build | |
| run: npm run build | |
| - name: Deploy to GitHub Pages | |
| uses: peaceiris/actions-gh-pages@v3 | |
| with: | |
| github_token: ${{ secrets.GITHUB_TOKEN }} | |
| publish_dir: ./dist | |
| # Discord notifications - runs after deployment | |
| - name: Send Discord notifications for new RSS items | |
| env: | |
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| RSS_FEED_URL: 'https://astoria-tech.github.io/subcurrent-astro/rss.xml' | |
| run: | | |
| # Check if the RSS feed is available, with a timeout | |
| max_attempts=30 | |
| attempt=0 | |
| echo "Checking for RSS feed availability..." | |
| while [ $attempt -lt $max_attempts ]; do | |
| attempt=$((attempt+1)) | |
| http_status=$(curl -s -o /dev/null -w "%{http_code}" $RSS_FEED_URL) | |
| if [ "$http_status" == "200" ]; then | |
| echo "RSS feed is available! Proceeding with Discord notifications." | |
| break | |
| else | |
| echo "Attempt $attempt: RSS feed not yet available (HTTP status: $http_status). Waiting..." | |
| sleep 10 | |
| fi | |
| # If we've reached max attempts, continue anyway | |
| if [ $attempt -eq $max_attempts ]; then | |
| echo "Warning: RSS feed could not be verified after maximum attempts. Proceeding anyway." | |
| fi | |
| done | |
| # Run the Discord notifier with error handling | |
| node --loader ts-node/esm src/utils/discordNotifier.ts || echo "Discord notification failed but continuing workflow" | |
| # Commit the Discord notification tracking file | |
| echo "Looking for Discord timestamp tracking file..." | |
| if [ -f ".discord-sent-posts.json" ]; then | |
| echo "Found tracking file: .discord-sent-posts.json" | |
| git add .discord-sent-posts.json | |
| git diff --staged --quiet || (git commit -m "Update Discord notification tracking data" && git push) | |
| else | |
| echo "Warning: .discord-sent-posts.json file not found after running Discord notifier" | |
| fi |