Skip to content

optimize push_wp.yml and update the format of some writeups #38

optimize push_wp.yml and update the format of some writeups

optimize push_wp.yml and update the format of some writeups #38

Workflow file for this run

name: Update calendar on PR Merged
on:
pull_request_target: # 保证可以使用 secrets
types: [closed]
paths:
- 'docs/**'
permissions:
contents: write
jobs:
update:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PAT_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Get added md files
run: |
echo "Fetching changed files from PR #${{ github.event.pull_request.number }}"
# 获取 PR 文件列表
FILES_JSON=$(curl -sSL "${{ github.event.pull_request.url }}/files" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json")
# 提取新增文件(added)
ADDED_FILES=$(echo "$FILES_JSON" | jq -r '[.[] | select(.status=="added") | .filename | select(test("^docs/.*\\.md$"))]')
echo "ADDED_FILES=$ADDED_FILES" >> $GITHUB_ENV
# 提取重命名文件 (renamed),包括旧文件名
RENAMED_PAIRS=$(echo "$FILES_JSON" | jq -c '[.[] | select(.status == "renamed") | {old:.previous_filename, new:.filename}]' || echo '[]')
echo "RENAMED_PAIRS=$RENAMED_PAIRS" >> $GITHUB_ENV
echo "Added files: $ADDED_FILES_JSON"
echo "Renamed files: $RENAMED_PAIRS"
- name: Update schedule JSON
if: ${{ env.ADDED_FILES != '[]' || env.RENAMED_PAIRS != '[]' }}
env:
COMMITTER_NAME: ${{ github.event.pull_request.user.login }}
COMMIT_URL: ${{ github.event.pull_request.html_url }}
run: |
python scripts/update_calendar_on_push.py
- name: Commit & Push
if: ${{ env.ADDED_FILES != '[]' || env.RENAMED_PAIRS != '[]' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add docs/data/calendar.json
git diff --cached --quiet || git commit -m "Update calendar from PR merge"
git push