How to force GitHub Pages build?

前端 未结 9 1640
天涯浪人
天涯浪人 2020-12-12 14:41

Every GitHub repository can have (or be) a GitHub Pages website, that can be built with Jekyll. GitHub builds the site every time you push a new commit.
Is there a way t

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-12 15:15

    Now that GitHub Actions are available, this is trivial to do:

    # File: .github/workflows/refresh.yml
    name: Refresh
    
    on:
      schedule:
        - cron:  '0 3 * * *' # Runs every day at 3am
    
    jobs:
      refresh:
        runs-on: ubuntu-latest
        steps:
          - name: Trigger GitHub pages rebuild
            run: |
              curl --fail --request POST \
                --url https://api.github.com/repos/${{ github.repository }}/pages/builds \
                --header "Authorization: Bearer $USER_TOKEN"
            env:
              # You must create a personal token with repo access as GitHub does
              # not yet support server-to-server page builds.
              USER_TOKEN: ${{ secrets.USER_TOKEN }}
    

    Sample repo that does this: https://github.com/SUPERCILEX/personal-website/actions

    Pages API: https://developer.github.com/v3/repos/pages/#request-a-page-build

提交回复
热议问题