77# Job 2: deploy-dev
88# - Deploys the built site to GitHub Pages for development (pushes to develop/master).
99# Job 3: deploy-prod
10- # - Deploys the built site to gh_pages branch for production (release tags starting with v*).
10+ # - Deploys the built site to gh-pages branch for production (release tags starting with v*).
1111# - This triggers deployment to a custom domain via webhook.
1212#
1313# The action summary page will contain links to the built artifact for downloading
@@ -40,25 +40,51 @@ concurrency:
4040# Set the environment variables to be used in all jobs defined in this workflow
4141env :
4242 # CI_BRANCH - the branch name (used in mkdocs.yml)
43+ # For PRs: github.head_ref is the source branch
44+ # For pushes: github.ref_name is the branch
45+ # For tags: github.ref_name is the tag name
4346 # GITHUB_REPOSITORY - the repository name (used in mkdocs.yml)
4447 # NOTEBOOKS_DIR - the directory containing the Jupyter notebooks (used in mkdocs.yml)
48+ DEFAULT_BRANCH : ${{ github.event.repository.default_branch }}
49+ DEVELOP_BRANCH : develop
4550 CI_BRANCH : ${{ github.head_ref || github.ref_name }}
51+ IS_RELEASE_TAG : ${{ startsWith(github.ref, 'refs/tags/v') }}
4652 GITHUB_REPOSITORY : ${{ github.repository }}
4753 NOTEBOOKS_DIR : tutorials
4854 DEV_DEPLOYMENT_URL :
49- https://easyscience.github.io/${{ github.event.repository.name }}
55+ https://easyscience.github.io/${{ github.event.repository.name }}/dev
5056 PROD_DEPLOYMENT_URL : https://docs.easydiffraction.org/lib
5157
5258jobs :
5359 # Job 1: Build the static files for the documentation site
54- build-docs :
60+ build-deploy- docs :
5561 strategy :
5662 matrix :
5763 os : [macos-14] # Use macOS to switch to dark mode for Plotly charts
5864
5965 runs-on : ${{ matrix.os }}
6066
67+ permissions :
68+ contents : write # required for pushing to gh-pages branch
69+
6170 steps :
71+ # Setting DOCS_VERSION to be used in mkdocs.yml, and then in the
72+ # main.html template. It defines the versioned docs subfolder name
73+ # in the gh-pages branch. If it's a release tag, use the version
74+ # number without the 'v' prefix, otherwise use 'dev'.
75+ - name : Set extra env variables
76+ shell : bash
77+ run : |
78+ if [[ "${IS_RELEASE_TAG}" == "true" ]]; then
79+ RELEASE_VERSION="${GITHUB_REF_NAME}"
80+ DOCS_VERSION="${RELEASE_VERSION#v}"
81+ else
82+ RELEASE_VERSION="${CI_BRANCH}"
83+ DOCS_VERSION="dev"
84+ fi
85+ echo "RELEASE_VERSION=${RELEASE_VERSION}" >> "$GITHUB_ENV"
86+ echo "DOCS_VERSION=${DOCS_VERSION}" >> "$GITHUB_ENV"
87+
6288 - name : Check-out repository
6389 uses : actions/checkout@v5
6490 with :
@@ -67,10 +93,10 @@ jobs:
6793 # Save the latest release version of easyscience/diffraction-lib to RELEASE_VERSION
6894 # RELEASE_VERSION is used in the mkdocs.yml file to set release_version.
6995 # The release_version is then needed to display the latest release version in the index.md file
70- - name : Set RELEASE_VERSION env variable (latest easydiffraction release)
71- run : |
72- git fetch --tags --force
73- echo "RELEASE_VERSION=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
96+ # - name: Set RELEASE_VERSION env variable (latest easydiffraction release)
97+ # run: |
98+ # git fetch --tags --force
99+ # echo "RELEASE_VERSION=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
74100
75101 # Activate dark mode to create documentation with Plotly charts in dark mode
76102 # Need a better solution to automatically switch the chart colour theme based on the mkdocs material switcher
@@ -133,124 +159,40 @@ jobs:
133159 - name : Create mkdocs.yml file
134160 run : pixi run docs-config
135161
136- # Build the static files
162+ # Build the static files for the documentation site for local inspection
137163 # Input: docs/ directory containing the Markdown files
138164 # Output: site/ directory containing the generated HTML files
139- - name : Build site with MkDocs
140- run : |
141- if [[ "${CI_BRANCH}" == "develop" || "${CI_BRANCH}" == "master" || "${CI_BRANCH}" == "main" ]]; then
142- echo "📘 Building production docs for ${CI_BRANCH}"
143- pixi run docs-build
144- else
145- echo "📗 Building local docs for ${CI_BRANCH}"
146- pixi run docs-local
147- fi
165+ - name : Build site for local check
166+ run : pixi run docs-local
148167
149- # Set up the Pages action to configure the static files to be deployed
150- # NOTE: The repository must have GitHub Pages enabled and configured to build using GitHub Actions
151- # This can be done via https://github.com/easyscience/diffraction-lib/settings/pages
152- # Select: Build and deploy - Source - GitHub Actions
153- - name : Setup GitHub Pages
154- uses : actions/configure-pages@v5
155-
156- # Upload the static files from the site/ directory to be used in the next job
157- # This artifact is named github-pages and is a single gzip archive containing a single tar file
158- # The artifact is then used in the next job by actions/deploy-pages to deploy the static files to GitHub Pages
159- # It can also be downloaded using the actions/download-artifact, as the current upload-pages-artifact
160- # is a wrapper which triggers the actions/upload-artifact.
168+ # Upload the static files from the site/ directory to be used for
169+ # local check
161170 - name : Upload built site as artifact
162- uses : actions/upload-pages- artifact@v3
171+ uses : actions/upload-artifact@v4
163172 with :
173+ name : site-local_edl-${{ env.RELEASE_VERSION }}
164174 path : site/
175+ if-no-files-found : ' error'
176+ compression-level : 0
165177
166- # Job 2: Deploy the built static files to GitHub Pages (DEV deployment)
167- deploy-dev :
168- needs : build-docs # previous job 'build-docs' need to be finished first
169-
170- # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
171- permissions :
172- contents : read
173- pages : write # to deploy to Pages
174- id-token : write # to verify the deployment, originates from an appropriate source
175-
176- # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
177- # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
178- concurrency :
179- group : ' pages-dev'
180- cancel-in-progress : false
181-
182- # Deploy to the github-pages environment
183- environment :
184- name : github-pages # Environment name
185- url : ${{ steps.deployment.outputs.page_url }}
186-
187- runs-on : ubuntu-latest
188-
189- # Triggered on push to develop or master branch only
190- if : ${{ github.ref_name == 'develop' || github.ref_name == 'master' }}
191-
192- steps :
193- # Deploy the static files created in the previous job to GitHub Pages
194- # To allow the deployment of the static files to GitHub Pages, no
195- # restrictions on the branch name need to be set for desired branches on
196- # https://github.com/easyscience/diffraction-lib/settings/environments
197- # Deployed pages are available at https://easyscience.github.io/diffraction-lib
198- - name : DEV deployment
199- uses : actions/deploy-pages@v4
200-
201- - name : Add DEV deployment url to summary
202- run :
203- echo "🔗 DEV deployment url [${{ env.DEV_DEPLOYMENT_URL }}](${{
204- env.DEV_DEPLOYMENT_URL }})" >> $GITHUB_STEP_SUMMARY
205-
206- # Job 3: Deploy the built static files to GitHub Pages (PROD deployment)
207- deploy-prod :
208- needs : deploy-dev # previous job 'deploy-dev' needs to be finished first
209-
210- # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
211- permissions :
212- contents : read
213-
214- # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
215- # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
216- concurrency :
217- group : ' pages-prod'
218- cancel-in-progress : false
219-
220- runs-on : ubuntu-latest
221-
222- # Triggered on tagged releases only (tags starting with 'v', e.g., v1.0.3)
223- if : startsWith(github.ref, 'refs/tags/v')
224-
225- steps :
226- # Download built site as artifact from a previous job for gh_pages (tagged release)
227- # This artifact is used to push its content to gh_pages branch for custom domain deployment.
228- - name : Download built site from previous job
229- uses : actions/download-artifact@v4
230- with : # name or path are taken from the upload step of the previous job
231- name : github-pages
232- path : site/ # directory to extract downloaded zipped artifacts
233-
234- # Push the site files created in the previous job to the gh_pages branch
235- # This push happens only for tagged releases (tags starting with 'v'),
236- # which triggers deployment to the custom domain via webhook.
237- #
238- # To be able to push to the gh_pages branch, the personal GitHub API access
239- # token GH_API_PERSONAL_ACCESS_TOKEN must be set for this repository via
240- # https://github.com/easyscience/diffraction-lib/settings/secrets/actions
241- # Then the gh_pages branch is used to deploy the site to the custom domain.
242- # Deploying is done with a webhook added via:
243- # https://github.com/easyscience/diffraction-lib/settings/hooks
244- - name : PROD deployment to gh_pages for custom domain
245- uses : s0/git-publish-subdir-action@develop
246- env :
247- GITHUB_TOKEN : ${{ secrets.GH_API_PERSONAL_ACCESS_TOKEN }}
248- REPO : self
249- BRANCH : gh_pages
250- FOLDER : site
251-
252- - name : Show PROD deployment url
253- if : startsWith(github.ref, 'refs/tags/v')
254- run :
255- echo "🔗 PROD deployment url [${{ env.PROD_DEPLOYMENT_URL }}](${{
256- env.PROD_DEPLOYMENT_URL }})" >> $GITHUB_STEP_SUMMARY
178+ # Publish versioned docs with Mike (dev on branches, prod on tags)
179+ # Configure git for pushing to gh-pages branch
180+ - name : Configure git for pushing
181+ run : |
182+ git config user.name "github-actions[bot]"
183+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
184+
185+ # Publish versioned docs with Mike. The tagged release docs go to
186+ # the versioned prefix, e.g. /v1.2.3/, and also to /latest/.
187+ # All other branches go to /dev/.
188+ # "${RELEASE_VERSION#v}" for v0.8.3.post1 -> 0.8.3.post1
189+ - name : Rebuild and deploy docs with mike
190+ run : |
191+ if [[ "${IS_RELEASE_TAG}" == "true" ]]; then
192+ pixi run docs-deploy "${RELEASE_VERSION#v}" latest
193+ echo "🔗 PROD deployment url [${{ env.PROD_DEPLOYMENT_URL }}](${{ env.PROD_DEPLOYMENT_URL }})" >> $GITHUB_STEP_SUMMARY
194+ else
195+ pixi run docs-deploy dev
196+ echo "🔗 DEV deployment url [${{ env.DEV_DEPLOYMENT_URL }}](${{ env.DEV_DEPLOYMENT_URL }})" >> $GITHUB_STEP_SUMMARY
197+ fi
198+ pixi run docs-set-default latest
0 commit comments