diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 59ac730..7919294 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,8 +2,6 @@ on: workflow_call jobs: deploy: runs-on: ubuntu-latest - permissions: - contents: write steps: - uses: actions/checkout@v4 @@ -134,13 +132,24 @@ jobs: $asset_name \ $full_asset_name - - name: Switch to gh-pages and empty it - run: | - git reset --hard - git clean -fdx - git fetch origin gh-pages - git checkout -b gh-pages origin/gh-pages - git rm -r . --quiet + - run: | + git config --global user.name "${{ github.event.head_commit.committer.name }}" + git config --global user.email "${{ github.event.head_commit.committer.email }}" + + - name: Prepare gh-pages branch + run: > + git reset --hard ; + git clean -fdx ; + git ls-remote --exit-code --heads origin refs/heads/gh-pages && + ( + git fetch origin gh-pages ; + git checkout -b gh-pages origin/gh-pages ; + git rm -r . --quiet || true + ) || ( + git checkout --orphan gh-pages ; + git reset --hard ; + git commit -m "empty" --allow-empty + ) - uses: actions/download-artifact@v4 with: @@ -154,8 +163,6 @@ jobs: - name: Commit gh-pages run: | git add . >> /dev/null - git config --global user.name "${{ github.event.head_commit.committer.name }}" - git config --global user.email "${{ github.event.head_commit.committer.email }}" git commit -m "deploy: ${GITHUB_SHA}" --allow-empty diff --git a/.github/workflows/top-level.yml b/.github/workflows/top-level.yml index 144947c..eb1c5ef 100644 --- a/.github/workflows/top-level.yml +++ b/.github/workflows/top-level.yml @@ -21,3 +21,5 @@ jobs: uses: ./.github/workflows/deploy.yml needs: [build-doc, tests] secrets: inherit + permissions: + contents: write diff --git a/docs/ci.rst b/docs/ci.rst index 3f72f18..ee996af 100644 --- a/docs/ci.rst +++ b/docs/ci.rst @@ -148,13 +148,30 @@ With GitHub Actions, the following workflow file is recommended: if: github.ref == 'refs/heads/main' steps: + - run: | + git config --global user.name "${{ github.event.head_commit.committer.name }}" + git config --global user.email "${{ github.event.head_commit.committer.email }}" + + - uses: actions/checkout@v4 + - name: Create gh-pages branch + run: > + git ls-remote --exit-code --heads origin refs/heads/gh-pages || + ( + git reset --hard ; + git clean -fdx ; + git checkout --orphan gh-pages ; + git reset --hard; + git commit -m "empty" --allow-empty ; + git push origin gh-pages:gh-pages + ) + - uses: actions/checkout@v4 with: ref: 'gh-pages' - name: Empty gh-pages run: | - git rm -r . --quiet + git rm -r . --quiet || true - uses: actions/download-artifact@v4 with: @@ -168,8 +185,6 @@ With GitHub Actions, the following workflow file is recommended: - name: Commit gh-pages run: | git add . >> /dev/null - git config --global user.name "${{ github.event.head_commit.committer.name }}" - git config --global user.email "${{ github.event.head_commit.committer.email }}" git commit -m "deploy: ${GITHUB_SHA}" --allow-empty - name: Push to gh-pages