Skip to content

Commit

Permalink
Add option publish-gh-pages-branch. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Jun 29, 2024
1 parent c87c4e3 commit 977cf28
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/_shared-docs-build-publish-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ on:
required: false
type: string
default: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
publish-gh-pages-branch:
description: |
Whether to publish the `gh-pages` branch to GitHub Pages.
required: false
type: boolean
default: false
outputs:
url:
description: The destination path pre-pended with the base-url.
Expand All @@ -39,12 +45,17 @@ on:
The token used for publishing to GitHub Pages.
Even when using the workflow token (secrets.GITHUB_TOKEN), it must be passed explicitly.
required: true
concurrency: # Do not run workflow in parallel!
cancel-in-progress: false
group: pages
jobs:
publish-gh-pages:
name: Publish to GitHub Pages
runs-on: ubuntu-latest
permissions:
contents: write
pages: write
id-token: write
outputs:
url: ${{ steps.vars.outputs.url }}
steps:
Expand Down Expand Up @@ -100,3 +111,30 @@ jobs:
# NOTE: do not use the force_orphan (keep_history) option.
# It does not yet work correctly with keep_files and destination_dir:
# - https://github.com/peaceiris/actions-gh-pages/issues/455

- name: Checkout repository
if: inputs.publish-gh-pages-branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages-checkout
token: ${{ secrets.GH_TOKEN }}

- name: Setup GitHub Pages
if: inputs.publish-gh-pages-branch
uses: actions/configure-pages@v5
with:
token: ${{ secrets.GH_TOKEN }}

- name: Upload gh-pages branch as artifact
if: inputs.publish-gh-pages-branch
uses: actions/upload-pages-artifact@v3
with:
path: gh-pages-checkout

- name: Deploy gh-pages branch to GitHub Pages
if: inputs.publish-gh-pages-branch
id: deployment
uses: actions/deploy-pages@v4
with:
token: ${{ secrets.GH_TOKEN }}
3 changes: 3 additions & 0 deletions samples/pr-build-and-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ jobs:
if: github.repository == 'repo_owner/repo_name'
permissions:
contents: write
pages: write
id-token: write
needs: [build-docs]
name: Publish Ansible Docs
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
with:
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
action: ${{ (github.event.action == 'closed' || needs.build-docs.outputs.changed != 'true') && 'teardown' || 'publish' }}
publish-gh-pages-branch: true
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
3 changes: 3 additions & 0 deletions samples/pr-with-publish-to-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ jobs:
if: github.repository == 'repo_owner/repo_name'
permissions:
contents: write
pages: write
id-token: write
needs: [build-docs]
name: Publish Ansible Docs
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
with:
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
action: ${{ (github.event.action == 'closed' || needs.build-docs.outputs.changed != 'true') && 'teardown' || 'publish' }}
publish-gh-pages-branch: true
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
3 changes: 3 additions & 0 deletions samples/push-with-publish-to-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ jobs:
if: github.repository == 'repo_owner/repo_name'
permissions:
contents: write
pages: write
id-token: write
needs: [build-docs]
name: Publish Ansible Docs
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
with:
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
publish-gh-pages-branch: true
secrets:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 977cf28

Please # to comment.