Skip to content

Commit 0da2530

Browse files
authored
De-couple build workflow from GitHub Pages publication (#3404)
1 parent 3126449 commit 0da2530

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

.github/workflows/github_pages.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Workflow for publishing to GitHub Pages.
1+
# Workflow for building the site and (optionally) publishing it to GitHub Pages.
22
name: Deploy to GitHub Pages
33
on:
44
workflow_call:
@@ -37,13 +37,15 @@ on:
3737
default: ""
3838
description: "The domain to be prepended to feed URLs (Pelican's FEED_DOMAIN setting). If not passed this will default to the URL of your GitHub Pages site, which is correct in most cases."
3939
type: string
40+
deploy:
41+
required: false
42+
default: true
43+
description: "Whether to deploy the site. If true then build the site and deploy it. If false then just test that the site builds successfully but don't deploy anything."
44+
type: boolean
4045
permissions:
4146
contents: read
4247
pages: write
4348
id-token: write
44-
concurrency:
45-
group: "pages"
46-
cancel-in-progress: false
4749
jobs:
4850
build:
4951
runs-on: ubuntu-latest
@@ -88,6 +90,10 @@ jobs:
8890
with:
8991
path: ${{ inputs.output-path }}
9092
deploy:
93+
concurrency:
94+
group: "pages"
95+
cancel-in-progress: false
96+
if: ${{ inputs.deploy }}
9197
environment:
9298
name: github-pages
9399
url: ${{ steps.deployment.outputs.page_url }}

docs/tips.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,52 @@ Here's the complete list of workflow inputs:
246246
| | | your GitHub Pages site, which is correct | | |
247247
| | | in most cases. | | |
248248
+------------------+----------+--------------------------------------------+--------+---------------+
249+
| ``deploy`` | No | This is used to determine whether you will | bool | ``true`` |
250+
| | | deploy the site or not to GitHub Pages. | | |
251+
| | | This is most useful if you want to test a | | |
252+
| | | change to your website in a pull request | | |
253+
| | | before deploying those change. | | |
254+
+------------------+----------+--------------------------------------------+--------+---------------+
255+
256+
Testing Your Build in a GitHub Pull Request
257+
"""""""""""""""""""""""""""""""""""""""""""
258+
259+
If you want to test your build in a pull request before deploying to GitHub, your workflow might look something like this:
260+
261+
.. code-block:: yaml
249262
263+
name: Build and Deploy Site
264+
on:
265+
push:
266+
branches: ["main"]
267+
pull_request:
268+
branches: ["main"]
269+
workflow_dispatch:
270+
inputs:
271+
deploy:
272+
required: false
273+
default: true
274+
description: "Whether to deploy the site. If checked, then build the site and deploy it. If not checked, then just test that the site builds successfully but don't deploy anything."
275+
type: boolean
276+
jobs:
277+
deploy:
278+
uses: "getpelican/pelican/.github/workflows/github_pages.yml@main"
279+
permissions:
280+
id-token: write
281+
contents: read
282+
pages: write
283+
with:
284+
settings: "publishconf.py"
285+
requirements: "-r requirements.txt"
286+
deploy: ${{ (github.event_name == 'workflow_dispatch' && inputs.deploy == true) || (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == github.event.repository.default_branch) }}
287+
288+
The ``on`` section of the workflow defines the events that will trigger the workflow. In this example, the workflow will run on pushes to the main branch, pull requests to the main branch, and manual runs of the workflow.
289+
290+
``workflow_dispatch`` defines the deploy boolean to be true by default. This means that if you run the workflow manually, it will deploy the site.
291+
292+
The ``deploy`` input for the job is using a set of standard GitHub workflow variables to control when ``deploy`` will either be true or false (you can customize this to your needs).
293+
294+
In this example, the ``deploy`` will be true if the event is a push to the main branch (or merging into main from a PR) or a manual run of the workflow. If the event is a pull request, the ``deploy`` will be false and it will only build an artifact for the site.
250295

251296
"Insecure content" warnings from browsers
252297
"""""""""""""""""""""""""""""""""""""""""

0 commit comments

Comments
 (0)