Skip to content

Fetch Tweets

Fetch Tweets #4416

Workflow file for this run

name: Fetch Tweets
on:
# 定时执行 - 每 15 分钟运行一次
schedule:
- cron: '*/15 * * * *'
# 手动触发
workflow_dispatch:
# 推送到 master 分支时触发
push:
branches:
- master
paths:
- 'scripts/fetch-tweets.mjs'
- '.github/workflows/fetch-tweets.yml'
- 'data/followers.txt' # 关注者列表变化时自动触发
- 'data/followers.json' # 关注者列表变化时自动触发
jobs:
fetch:
runs-on: ubuntu-latest
# 授予写入权限,允许提交代码
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# 使用 GITHUB_TOKEN 进行认证,允许推送
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Verify curl is available
run: curl --version
- name: Build followers.json from followers.txt
run: node scripts/build-followers.mjs
- name: Validate followers configuration
run: node scripts/validate-followers.mjs
- name: Fetch tweets
run: node scripts/fetch-tweets.mjs
continue-on-error: true
- name: Check if data changed
id: check
run: |
if git diff --quiet data/tweets.json; then
echo "changed=false" >> $GITHUB_OUTPUT
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push
if: steps.check.outputs.changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add data/tweets.json
git commit -m "chore: update tweets data [skip ci]"
git push
# - name: Trigger Vercel deployment (optional)
# if: steps.check.outputs.changed == 'true'
# run: |
# if [ -n "${{ secrets.VERCEL_DEPLOY_HOOK }}" ]; then
# curl -X POST "${{ secrets.VERCEL_DEPLOY_HOOK }}"
# echo "Vercel deployment triggered"
# else
# echo "VERCEL_DEPLOY_HOOK not configured, skipping"
# fi