Search Engine Indexing Submit #233
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Search Engine Indexing Submit | |
| on: | |
| # 每次部署后自动提交变更页面 | |
| workflow_run: | |
| workflows: ["Deploy MkDocs to GitHub Pages"] | |
| types: [completed] | |
| # 每天定时提交(消化 Google 积压的未索引页面) | |
| schedule: | |
| - cron: '0 16 * * *' # UTC 16:00 = 北京时间 0:00 | |
| # 手动触发 | |
| workflow_dispatch: | |
| inputs: | |
| limit: | |
| description: 'Google 本次提交上限' | |
| required: false | |
| default: '200' | |
| changed_only: | |
| description: '仅提交变更页面' | |
| required: false | |
| type: boolean | |
| default: false | |
| engine: | |
| description: '提交引擎' | |
| required: false | |
| type: choice | |
| options: | |
| - both | |
| - bing-only | |
| - google-only | |
| default: 'both' | |
| index_pages: | |
| description: '同时提交索引页(主页/会议/领域索引)' | |
| required: false | |
| type: boolean | |
| default: true | |
| env: | |
| INDEXNOW_KEY: 'afab7697-0632-4c75-a61c-17ca32070d60' | |
| jobs: | |
| submit: | |
| runs-on: ubuntu-latest | |
| # 仅在部署成功后运行(workflow_run 触发时) | |
| if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} | |
| env: | |
| HAS_GOOGLE_KEY: ${{ secrets.GOOGLE_INDEXING_SA_KEY != '' }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 2 # 需要 HEAD~1 用于 git diff | |
| - uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.11' | |
| - name: Install Google API dependencies | |
| if: ${{ github.event.inputs.engine != 'bing-only' && env.HAS_GOOGLE_KEY == 'true' }} | |
| run: pip install google-auth google-auth-httplib2 google-api-python-client | |
| - name: Write service account credentials | |
| if: ${{ github.event.inputs.engine != 'bing-only' && env.HAS_GOOGLE_KEY == 'true' }} | |
| run: echo '${{ secrets.GOOGLE_INDEXING_SA_KEY }}' > /tmp/sa_key.json | |
| - name: Submit index pages (homepage/conference/domain indexes) | |
| if: ${{ github.event_name == 'workflow_run' || github.event_name == 'schedule' || github.event.inputs.index_pages == 'true' }} | |
| run: | | |
| python scripts/indexing_submit.py --bing-key $INDEXNOW_KEY --bing-only --index-pages | |
| - name: Submit paper pages to search engines | |
| run: | | |
| ARGS="--bing-key $INDEXNOW_KEY" | |
| # Google credentials (optional) | |
| ENGINE="${{ github.event.inputs.engine }}" | |
| if [ "$ENGINE" = "bing-only" ]; then | |
| ARGS="$ARGS --bing-only" | |
| elif [ -f /tmp/sa_key.json ]; then | |
| ARGS="$ARGS --credentials /tmp/sa_key.json" | |
| if [ "$ENGINE" = "google-only" ]; then | |
| ARGS="$ARGS --google-only" | |
| fi | |
| else | |
| ARGS="$ARGS --bing-only" | |
| fi | |
| # Changed-only mode | |
| if [ "${{ github.event_name }}" = "workflow_run" ]; then | |
| ARGS="$ARGS --changed-only" | |
| elif [ "${{ github.event.inputs.changed_only }}" = "true" ]; then | |
| ARGS="$ARGS --changed-only" | |
| fi | |
| # Limit (Google only) | |
| if [ -n "${{ github.event.inputs.limit }}" ]; then | |
| ARGS="$ARGS --limit ${{ github.event.inputs.limit }}" | |
| fi | |
| python scripts/indexing_submit.py $ARGS | |
| - name: Save progress | |
| if: always() | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: indexing-progress | |
| path: logs/indexing_progress.json | |
| if-no-files-found: ignore | |
| retention-days: 90 | |
| - name: Cleanup credentials | |
| if: always() | |
| run: rm -f /tmp/sa_key.json |