1+ # This workflow builds and deploys documentation for the project.
2+ #
3+ # Steps overview:
4+ # Job 1: build-docs
5+ # - Builds documentation (including running Jupyter notebooks to generate output cells).
6+ # - Uploads the built site as a Pages artifact.
7+ # Job 2: deploy-dev
8+ # - Deploys the built site to GitHub Pages for development (pushes to develop/master).
9+ # Job 3: deploy-prod
10+ # - Deploys the built site to gh_pages branch for production (release tags starting with v*).
11+ # - This triggers deployment to a custom domain via webhook.
12+ #
13+ # The action summary page will contain links to the built artifact for downloading
14+ # and inspecting, as well as links to both the development and production versions of
15+ # the deployed documentation site.
16+
117name : Build and deploy docs
218
319on :
20+ # Trigger the workflow on pull request
21+ pull_request :
22+ # Selected branches
23+ branches : [master, develop]
424 # Trigger the workflow on push
525 push :
626 # Selected branches
7- branches : [master, develop, docs, patch ]
27+ branches : [master, develop]
828 # Runs on creating a new tag starting with 'v', e.g. 'v1.0.3'
9- tags :
10- - ' v*'
29+ tags : ['v*']
1130 # Allows you to run this workflow manually from the Actions tab
1231 workflow_dispatch :
1332
4160
4261 steps :
4362 - name : Check-out repository
44- uses : actions/checkout@v4
63+ uses : actions/checkout@v5
4564 with :
4665 fetch-depth : 0 # full history + tags. needed to get the latest release version
4766
@@ -92,6 +111,12 @@ jobs:
92111 - name : Convert tutorial scripts to notebooks
93112 run : pixi run notebook-prepare
94113
114+ # The following step is needed to avoid the following message during the build:
115+ # "Matplotlib is building the font cache; this may take a moment"
116+ - name : Pre-build site step
117+ run : pixi run python -c "import easydiffraction"
118+
119+ # Run the notebooks to generate the output cells using multiple cores
95120 - name : Run notebooks
96121 run : pixi run notebook-exec
97122
@@ -121,26 +146,15 @@ jobs:
121146 # Upload the static files from the site/ directory to be used in the next job
122147 # This artifact is named github-pages and is a single gzip archive containing a single tar file
123148 # The artifact is then used in the next job by actions/deploy-pages to deploy the static files to GitHub Pages
124- # Unfortunately, the artifact is not available for download, so extra steps below are needed to do similar things
125- - name : Upload built site as artifact for DEV deployment (all branches)
149+ # It can also be downloaded using the actions/download-artifact, as the current upload-pages-artifact
150+ # is a wrapper which triggers the actions/upload-artifact.
151+ - name : Upload built site as artifact
126152 uses : actions/upload-pages-artifact@v3
127153 with :
128154 path : site/
129155
130- # Upload the static files from the site/ directory to be used in the next job
131- # This artifact is only uploaded on tagged releases (tags starting with 'v', e.g., v1.0.3)
132- # and is used to push content to gh_pages for custom domain deployment.
133- - name : Upload built site as artifact for PROD deployment (tagged release)
134- if : startsWith(github.ref, 'refs/tags/v')
135- uses : actions/upload-artifact@v4
136- with :
137- name : artifact # name of the artifact (without the extension zip)
138- path : site/
139- if-no-files-found : ' error'
140- compression-level : 0
141-
142- # Job 2: Deploy the static files
143- deploy-docs :
156+ # Job 2: Deploy the built static files to GitHub Pages (DEV deployment)
157+ deploy-dev :
144158 needs : build-docs # previous job 'build-docs' need to be finished first
145159
146160 # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
@@ -152,38 +166,59 @@ jobs:
152166 # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
153167 # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
154168 concurrency :
155- group : ' pages'
169+ group : ' pages-dev '
156170 cancel-in-progress : false
157171
158172 # Deploy to the github-pages environment
159173 environment :
160- name : github-pages # Artifact name
174+ name : github-pages # Environment name
161175 url : ${{ steps.deployment.outputs.page_url }}
162176
163177 runs-on : ubuntu-latest
164178
179+ # Triggered on push to develop or master branch only
180+ if : ${{ github.ref_name == 'develop' || github.ref_name == 'master' }}
181+
165182 steps :
166183 # Deploy the static files created in the previous job to GitHub Pages
167184 # To allow the deployment of the static files to GitHub Pages, no
168185 # restrictions on the branch name need to be set for desired branches on
169186 # https://github.com/easyscience/diffraction-lib/settings/environments
170187 # Deployed pages are available at https://easyscience.github.io/diffraction-lib
171- - name : DEV deployment (all branches)
188+ - name : DEV deployment
172189 uses : actions/deploy-pages@v4
173190
174- - name : Show DEV deployment url (all branches)
191+ - name : Add DEV deployment url to summary
175192 run :
176193 echo "🔗 DEV deployment url [${{ env.DEV_DEPLOYMENT_URL }}](${{
177194 env.DEV_DEPLOYMENT_URL }})" >> $GITHUB_STEP_SUMMARY
178195
196+ # Job 3: Deploy the built static files to GitHub Pages (PROD deployment)
197+ deploy-prod :
198+ needs : deploy-dev # previous job 'deploy-dev' needs to be finished first
199+
200+ # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
201+ permissions :
202+ contents : read
203+
204+ # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
205+ # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
206+ concurrency :
207+ group : ' pages-prod'
208+ cancel-in-progress : false
209+
210+ runs-on : ubuntu-latest
211+
212+ # Triggered on tagged releases only (tags starting with 'v', e.g., v1.0.3)
213+ if : startsWith(github.ref, 'refs/tags/v')
214+
215+ steps :
179216 # Download built site as artifact from a previous job for gh_pages (tagged release)
180- # This artifact is only downloaded on tagged releases (tags starting with 'v', e.g., v1.0.3)
181- # and is used to push content to gh_pages for custom domain deployment.
182- - name : Download built site from previous job (tagged release)
183- if : startsWith(github.ref, 'refs/tags/v')
217+ # This artifact is used to push its content to gh_pages branch for custom domain deployment.
218+ - name : Download built site from previous job
184219 uses : actions/download-artifact@v4
185220 with : # name or path are taken from the upload step of the previous job
186- name : artifact
221+ name : github-pages
187222 path : site/ # directory to extract downloaded zipped artifacts
188223
189224 # Push the site files created in the previous job to the gh_pages branch
@@ -196,16 +231,15 @@ jobs:
196231 # Then the gh_pages branch is used to deploy the site to the custom domain.
197232 # Deploying is done with a webhook added via:
198233 # https://github.com/easyscience/diffraction-lib/settings/hooks
199- - name : PROD deployment to gh_pages for custom domain (tagged release)
200- if : startsWith(github.ref, 'refs/tags/v')
234+ - name : PROD deployment to gh_pages for custom domain
201235 uses : s0/git-publish-subdir-action@develop
202236 env :
203237 GITHUB_TOKEN : ${{ secrets.GH_API_PERSONAL_ACCSESS_TOKEN }}
204238 REPO : self
205239 BRANCH : gh_pages
206240 FOLDER : site
207241
208- - name : Show PROD deployment url (tagged release)
242+ - name : Show PROD deployment url
209243 if : startsWith(github.ref, 'refs/tags/v')
210244 run :
211245 echo "🔗 PROD deployment url [${{ env.PROD_DEPLOYMENT_URL }}](${{
0 commit comments