Skip to content

Commit 977cf28

Browse files
authored
Add option publish-gh-pages-branch. (#93)
1 parent c87c4e3 commit 977cf28

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

.github/workflows/_shared-docs-build-publish-gh-pages.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ on:
2929
required: false
3030
type: string
3131
default: https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}
32+
publish-gh-pages-branch:
33+
description: |
34+
Whether to publish the `gh-pages` branch to GitHub Pages.
35+
required: false
36+
type: boolean
37+
default: false
3238
outputs:
3339
url:
3440
description: The destination path pre-pended with the base-url.
@@ -39,12 +45,17 @@ on:
3945
The token used for publishing to GitHub Pages.
4046
Even when using the workflow token (secrets.GITHUB_TOKEN), it must be passed explicitly.
4147
required: true
48+
concurrency: # Do not run workflow in parallel!
49+
cancel-in-progress: false
50+
group: pages
4251
jobs:
4352
publish-gh-pages:
4453
name: Publish to GitHub Pages
4554
runs-on: ubuntu-latest
4655
permissions:
4756
contents: write
57+
pages: write
58+
id-token: write
4859
outputs:
4960
url: ${{ steps.vars.outputs.url }}
5061
steps:
@@ -100,3 +111,30 @@ jobs:
100111
# NOTE: do not use the force_orphan (keep_history) option.
101112
# It does not yet work correctly with keep_files and destination_dir:
102113
# - https://github.com/peaceiris/actions-gh-pages/issues/455
114+
115+
- name: Checkout repository
116+
if: inputs.publish-gh-pages-branch
117+
uses: actions/checkout@v4
118+
with:
119+
ref: gh-pages
120+
path: gh-pages-checkout
121+
token: ${{ secrets.GH_TOKEN }}
122+
123+
- name: Setup GitHub Pages
124+
if: inputs.publish-gh-pages-branch
125+
uses: actions/configure-pages@v5
126+
with:
127+
token: ${{ secrets.GH_TOKEN }}
128+
129+
- name: Upload gh-pages branch as artifact
130+
if: inputs.publish-gh-pages-branch
131+
uses: actions/upload-pages-artifact@v3
132+
with:
133+
path: gh-pages-checkout
134+
135+
- name: Deploy gh-pages branch to GitHub Pages
136+
if: inputs.publish-gh-pages-branch
137+
id: deployment
138+
uses: actions/deploy-pages@v4
139+
with:
140+
token: ${{ secrets.GH_TOKEN }}

samples/pr-build-and-comment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ jobs:
3636
if: github.repository == 'repo_owner/repo_name'
3737
permissions:
3838
contents: write
39+
pages: write
40+
id-token: write
3941
needs: [build-docs]
4042
name: Publish Ansible Docs
4143
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
4244
with:
4345
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
4446
action: ${{ (github.event.action == 'closed' || needs.build-docs.outputs.changed != 'true') && 'teardown' || 'publish' }}
47+
publish-gh-pages-branch: true
4548
secrets:
4649
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4750

samples/pr-with-publish-to-gh-pages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ jobs:
4040
if: github.repository == 'repo_owner/repo_name'
4141
permissions:
4242
contents: write
43+
pages: write
44+
id-token: write
4345
needs: [build-docs]
4446
name: Publish Ansible Docs
4547
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
4648
with:
4749
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
4850
action: ${{ (github.event.action == 'closed' || needs.build-docs.outputs.changed != 'true') && 'teardown' || 'publish' }}
51+
publish-gh-pages-branch: true
4952
secrets:
5053
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5154

samples/push-with-publish-to-gh-pages.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ jobs:
2626
if: github.repository == 'repo_owner/repo_name'
2727
permissions:
2828
contents: write
29+
pages: write
30+
id-token: write
2931
needs: [build-docs]
3032
name: Publish Ansible Docs
3133
uses: ansible-community/github-docs-build/.github/workflows/_shared-docs-build-publish-gh-pages.yml@main
3234
with:
3335
artifact-name: ${{ needs.build-docs.outputs.artifact-name }}
36+
publish-gh-pages-branch: true
3437
secrets:
3538
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)