Skip to content

Build README

Build README #2389

Workflow file for this run

name: Build README
on:
push:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18"
- uses: actions/cache@v3
name: Configure npm caching
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node.js dependencies
run: npm install
- name: Update README
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
node build.js
cat README.md
- name: Commit and push if changed
run: |
# 设置分支名称变量
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
git config user.email "tw93@qq.com"
git config user.name "Tw93-bot"
# 添加所有变更
git add -A
# 检查是否有变更
if git diff-index --quiet HEAD --; then
echo "No changes detected"
else
git commit -m "Updated content"
git push origin "HEAD:$BRANCH_NAME"
fi
- name: Ping IndexNow
run: |
KEY="6ff2b87724ac930114bf05c74db50bb5"
HOST="weekly.tw93.fun"
URLS=$(git diff --name-only HEAD~1 HEAD -- 'src/pages/posts/*.md' | while read f; do
slug=$(basename "$f" .md)
echo "https://$HOST/posts/$slug"
done)
if [ -z "$URLS" ]; then
echo "No post URLs changed, submitting homepage"
URLS="https://$HOST/"
fi
URL_LIST=$(echo "$URLS" | jq -R -s 'split("\n") | map(select(length > 0))')
echo "Submitting to IndexNow: $URL_LIST"
curl -s -X POST "https://api.indexnow.org/indexnow" \
-H "Content-Type: application/json" \
-d "{\"host\":\"$HOST\",\"key\":\"$KEY\",\"keyLocation\":\"https://$HOST/$KEY.txt\",\"urlList\":$URL_LIST}"