Skip to content

Update Sitemap Links #397

Update Sitemap Links

Update Sitemap Links #397

name: Update Sitemap Links
on:
schedule:
- cron: "0 0 * * *" # 每天 UTC 00:00 运行
push:
paths:
- "update_sitemap.py"
- "_config.yml"
- "_layouts/default.html"
workflow_dispatch: # 允许手动触发
jobs:
update-and-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- 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
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git diff --quiet && git diff --staged --quiet || (git commit -m "Update sitemap links" && git push)
- name: Create and push tag
if: success()
run: |
VERSION=${{ steps.package-version.outputs.version }}
git tag "v${VERSION}"
git push origin "v${VERSION}"
# NPM 发布步骤
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"
- 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}}