name: Deploy RSSHub to Cloudflare Container on: schedule: - cron: '*/5 * * * *' workflow_dispatch: inputs: force_deploy: description: 'Force deploy even if tag is unchanged' required: false type: boolean default: false jobs: check-and-deploy: runs-on: ubuntu-latest permissions: contents: write packages: read steps: - name: Checkout uses: actions/checkout@v4 - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: 10 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '22' cache: 'pnpm' - name: Install dependencies run: pnpm install - name: Get latest RSSHub image tag id: get-latest env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Use GitHub API to get package versions sorted by creation time (newest first) LATEST_TAG=$(curl -s -H "Authorization: Bearer $GH_TOKEN" \ "https://api.github.com/users/diygod/packages/container/rsshub/versions?per_page=100" | \ jq -r '.[].metadata.container.tags[]' | \ grep -E '^chromium-bundled-[a-f0-9]{40}$' | \ head -1) if [ -z "$LATEST_TAG" ]; then echo "Failed to get latest tag" exit 1 fi echo "Latest tag: $LATEST_TAG" echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT - name: Get current tag from wrangler.toml id: get-current run: | CURRENT_TAG=$(grep -oP 'image = "registry\.cloudflare\.com/[^/]+/rsshub:\K[^"]+' wrangler.toml || echo "") echo "Current tag: $CURRENT_TAG" echo "tag=$CURRENT_TAG" >> $GITHUB_OUTPUT - name: Check if update needed id: check-update run: | FORCE_DEPLOY="${{ inputs.force_deploy }}" if [ "$FORCE_DEPLOY" = "true" ]; then echo "Force deploy requested" echo "needed=true" >> $GITHUB_OUTPUT elif [ "${{ steps.get-latest.outputs.tag }}" != "${{ steps.get-current.outputs.tag }}" ]; then echo "Update needed: ${{ steps.get-current.outputs.tag }} -> ${{ steps.get-latest.outputs.tag }}" echo "needed=true" >> $GITHUB_OUTPUT else echo "No update needed, current tag is latest" echo "needed=false" >> $GITHUB_OUTPUT fi - name: Update wrangler.toml if: steps.check-update.outputs.needed == 'true' run: | sed -i 's|image = "registry.cloudflare.com/[^/]*/rsshub:[^"]*"|image = "registry.cloudflare.com/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/rsshub:${{ steps.get-latest.outputs.tag }}"|' wrangler.toml cat wrangler.toml - name: Login to GitHub Container Registry if: steps.check-update.outputs.needed == 'true' uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Pull RSSHub image if: steps.check-update.outputs.needed == 'true' run: | docker pull ghcr.io/diygod/rsshub:${{ steps.get-latest.outputs.tag }} docker tag ghcr.io/diygod/rsshub:${{ steps.get-latest.outputs.tag }} rsshub:${{ steps.get-latest.outputs.tag }} - name: Push image to Cloudflare if: steps.check-update.outputs.needed == 'true' run: | npx wrangler containers push rsshub:${{ steps.get-latest.outputs.tag }} env: CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - name: Deploy to Cloudflare if: steps.check-update.outputs.needed == 'true' uses: cloudflare/wrangler-action@v3 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - name: Restore placeholder in wrangler.toml before commit if: steps.check-update.outputs.needed == 'true' run: | sed -i 's|image = "registry.cloudflare.com/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/rsshub:|image = "registry.cloudflare.com/CLOUDFLARE_ACCOUNT_ID/rsshub:|' wrangler.toml cat wrangler.toml - name: Commit updated wrangler.toml if: steps.check-update.outputs.needed == 'true' run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add wrangler.toml if git diff --staged --quiet; then echo "No changes to commit (force deploy with same tag)" else git commit -m "chore: update rsshub image to ${{ steps.get-latest.outputs.tag }}" git push fi