Skip to content

Update Sitemap Links #507

Update Sitemap Links

Update Sitemap Links #507

name: Update Sitemap Links
on:
schedule:
- cron: "0 0 * * *" # 每天 UTC 00:00 运行
push:
branches:
- master
paths:
- "update_sitemap.py"
- "_config.yml"
- "_layouts/default.html"
workflow_dispatch: # 允许手动触发
jobs:
update-and-publish:
runs-on: ubuntu-latest
steps:
- name: Create GitHub App token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ secrets.GH_CLIENT_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
owner: labex-labs
- uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: ${{ github.ref_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Update sitemap links
run: python update_sitemap.py
env:
LABEX_X_AUTH: ${{ secrets.LABEX_X_AUTH }}
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
- name: Get version from package.json
id: package-version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Commit and push if changed
id: commit-changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "Update sitemap links"
git push origin "HEAD:${GITHUB_REF_NAME}"
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Create and push tag
if: steps.commit-changes.outputs.changed == 'true'
run: |
VERSION=${{ steps.package-version.outputs.version }}
git tag "v${VERSION}"
git push origin "v${VERSION}"
- name: Verify version
run: echo "Publishing version $(node -p "require('./package.json').version")"
- name: Publish to NPM
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}