Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option publish-gh-pages-branch #93

Merged
merged 1 commit into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}