Skip to content

Commit daf8566

Browse files
Improve CI workflows and fix documentation deployment (#117)
* Serializes docs deploy; fetches gh-pages branch * Clarifies docs CI and versioned deploy with mike * Includes pytest.ini in PyPI test workflow * Removes PyPI extras install from test workflow * Updates CI to use new tutorials download command * Replaces PR backmerge with direct merge on tags * Update .github/workflows/backmerge.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/docs.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update .github/workflows/backmerge.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 56b35da commit daf8566

4 files changed

Lines changed: 117 additions & 121 deletions

File tree

.github/workflows/backmerge-pr.yaml

Lines changed: 0 additions & 81 deletions
This file was deleted.

.github/workflows/backmerge.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This workflow automatically merges `master` into `develop` whenever a new version tag is pushed (v*).
2+
#
3+
# Key points:
4+
# - Directly merges master into develop without creating a PR.
5+
# - Skips CI on the merge commit using [skip ci] in the commit message.
6+
# - The code being merged has already been tested as part of the release process.
7+
# - This ensures develop stays up-to-date with release changes (version bumps, etc.).
8+
#
9+
# Required repo config:
10+
# https://github.com/organizations/easyscience/settings/secrets/actions
11+
# https://github.com/organizations/easyscience/settings/variables/actions
12+
# - Actions secret: BACKMERGE_PRIVATE_KEY (GitHub App private key PEM)
13+
# - Actions variable: BACKMERGE_APP_ID (GitHub App ID)
14+
# The GitHub App must be added to the develop branch ruleset bypass list.
15+
16+
name: Backmerge (master -> develop)
17+
18+
on:
19+
push:
20+
tags: ['v*']
21+
22+
permissions:
23+
contents: write
24+
25+
jobs:
26+
backmerge:
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Create GitHub App installation token
31+
id: app-token
32+
uses: actions/create-github-app-token@v2
33+
with:
34+
app-id: ${{ vars.BACKMERGE_APP_ID }}
35+
private-key: ${{ secrets.BACKMERGE_PRIVATE_KEY }}
36+
37+
- name: Checkout repository
38+
uses: actions/checkout@v5
39+
with:
40+
fetch-depth: 0
41+
token: ${{ steps.app-token.outputs.token }}
42+
43+
- name: Configure git
44+
run: |
45+
git config user.name "es-backmerge[bot]"
46+
git config user.email "${{ vars.BACKMERGE_APP_ID }}+es-backmerge[bot]@users.noreply.github.com"
47+
48+
- name: Merge master into develop
49+
run: |
50+
set -euo pipefail
51+
52+
TAG='${{ github.ref_name }}'
53+
54+
# Ensure local develop branch exists and is up-to-date with origin
55+
git fetch origin develop:develop
56+
# Switch to develop branch
57+
git checkout develop
58+
59+
# Merge master into develop (no fast-forward to preserve history)
60+
# Use [skip ci] to avoid triggering CI - the code was already tested on master
61+
git merge origin/master --no-ff -m "Backmerge: ${TAG} from master into develop [skip ci]"
62+
63+
# Push the merge commit to develop
64+
git push origin develop
65+
66+
echo "✅ Successfully merged master (${TAG}) into develop"

.github/workflows/docs.yaml

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
# This workflow builds and deploys documentation for the project.
22
#
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.
3+
# Overview:
4+
# - Converts tutorial Python scripts to Jupyter notebooks and executes them.
5+
# - Builds the documentation site using MkDocs with the Material theme.
6+
# - Uploads the built site as an artifact for local inspection.
7+
# - Deploys versioned documentation to the gh-pages branch using Mike:
8+
# - For release tags (v*): deploys to a versioned folder (e.g., /0.9.1/) and updates /latest/.
9+
# - For branches: deploys to /dev/.
1210
#
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.
11+
# The action summary page will contain a link to the built artifact for downloading
12+
# and inspecting, as well as a link to the deployed documentation site.
1613

1714
name: Docs build and deployment
1815

@@ -30,12 +27,12 @@ on:
3027
# Allows you to run this workflow manually from the Actions tab
3128
workflow_dispatch:
3229

33-
# Allow only one concurrent workflow, skipping runs queued between the run
34-
# in-progress and latest queued. And cancel in-progress runs.
30+
# Allow only one concurrent deployment to gh-pages at a time.
31+
# All docs workflows share the same concurrency group to prevent race conditions
32+
# when multiple branches/tags trigger simultaneous deployments.
3533
concurrency:
36-
group:
37-
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
38-
cancel-in-progress: true
34+
group: docs-gh-pages-deploy
35+
cancel-in-progress: false
3936

4037
# Set the environment variables to be used in all jobs defined in this workflow
4138
env:
@@ -53,16 +50,17 @@ env:
5350
NOTEBOOKS_DIR: tutorials
5451

5552
jobs:
56-
# Job 1: Build the static files for the documentation site
53+
# Single job that builds and deploys documentation.
54+
# Uses macOS runner for consistent Plotly chart rendering.
5755
build-deploy-docs:
5856
strategy:
5957
matrix:
60-
os: [macos-14] # Use macOS to switch to dark mode for Plotly charts
58+
os: [macos-14]
6159

6260
runs-on: ${{ matrix.os }}
6361

6462
permissions:
65-
contents: write # required for pushing to gh-pages branch
63+
contents: write # Required for pushing to the gh-pages branch
6664

6765
steps:
6866
# Setting DOCS_VERSION to be used in mkdocs.yml, and then in the
@@ -87,10 +85,10 @@ jobs:
8785
echo "DOCS_VERSION=${DOCS_VERSION}" >> "$GITHUB_ENV"
8886
echo "DEPLOYMENT_URL=https://easyscience.github.io/${{ github.event.repository.name }}/${DOCS_VERSION}" >> "$GITHUB_ENV"
8987
88+
# Check out the repository source code.
89+
# Note: The gh-pages branch is fetched separately later for mike deployment.
9090
- name: Check-out repository
9191
uses: actions/checkout@v5
92-
with:
93-
fetch-depth: 0 # full history with tags; needed for mike to push/deploy docs
9492

9593
# Activate dark mode to create documentation with Plotly charts in dark mode
9694
# Need a better solution to automatically switch the chart colour theme based on the mkdocs material switcher
@@ -103,6 +101,8 @@ jobs:
103101
# dark-mode on
104102
# dark-mode status
105103

104+
# Set up the pixi package manager and install dependencies from pixi.toml.
105+
# Uses frozen lockfile to ensure reproducible builds.
106106
- name: Set up pixi
107107
uses: prefix-dev/setup-pixi@v0.9.0
108108
with:
@@ -113,37 +113,43 @@ jobs:
113113
cache: false
114114
post-cleanup: false
115115

116+
# Install additional development dependencies (e.g., pre-commit hooks, dev tools).
116117
- name: Install and setup development dependencies
117118
shell: bash
118119
run: pixi run dev
119120

121+
# Clone shared documentation assets and branding resources from external repositories.
122+
# These contain common MkDocs configuration, templates, stylesheets, and images.
120123
- name: Clone easyscience/assets-docs and easyscience/assets-branding
121124
run: |
122125
cd ..
123126
git clone https://github.com/easyscience/assets-docs.git
124127
git clone https://github.com/easyscience/assets-branding.git
125128
129+
# Copy assets from the cloned repositories into the docs/ directory.
130+
# This includes stylesheets, images, templates, and other shared resources.
126131
- name: Add files from cloned repositories
127132
run: pixi run docs-assets
128133

129-
# Convert python scripts in the notebooks directory to Jupyter notebooks
130-
# Strip output from the notebooks
131-
# Prepare the notebooks for documentation (add colab cell, etc.)
132-
# Run the notebooks to generate the output cells using multiple cores
133-
# The notebooks are then used to build the documentation site
134+
# Convert Python scripts in the tutorials/ directory to Jupyter notebooks.
135+
# This step also strips any existing output from the notebooks and prepares
136+
# them for documentation.
134137
- name: Convert tutorial scripts to notebooks
135138
run: pixi run notebook-prepare
136139

137-
# The following step is needed to avoid the following message during the build:
138-
# "Matplotlib is building the font cache; this may take a moment"
140+
# Pre-import the main package to trigger Matplotlib font cache building.
141+
# This avoids "Matplotlib is building the font cache" messages during notebook execution.
139142
- name: Pre-build site step
140143
run: pixi run python -c "import easydiffraction"
141144

142-
# Run the notebooks to generate the output cells using multiple cores
145+
# Execute all Jupyter notebooks to generate output cells (plots, tables, etc.).
146+
# Uses multiple cores for parallel execution to speed up the process.
143147
- name: Run notebooks
144148
# if: false # Temporarily disabled to speed up the docs build
145149
run: pixi run notebook-exec
146150

151+
# Move the executed notebooks to docs/tutorials/ directory
152+
# so they can be included in the documentation site.
147153
- name: Move notebooks to docs/tutorials
148154
run: pixi run docs-notebooks
149155

@@ -170,17 +176,24 @@ jobs:
170176
if-no-files-found: 'error'
171177
compression-level: 0
172178

173-
# Publish versioned docs with Mike (dev on branches, prod on tags)
174-
# Configure git for pushing to gh-pages branch
179+
# Configure git user for mike to commit and push to gh-pages branch.
175180
- name: Configure git for pushing
176181
run: |
177182
git config user.name "github-actions[bot]"
178183
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
179184
180-
# Publish versioned docs with Mike. The tagged release docs go to
181-
# the versioned prefix, e.g. /v1.2.3/, and also to /latest/.
182-
# All other branches go to /dev/.
183-
# "${RELEASE_VERSION#v}" for v0.8.3.post1 -> 0.8.3.post1
185+
# Fetch the gh-pages branch to ensure mike has the latest remote state.
186+
# This is required because the checkout step only fetches the source branch,
187+
# not the gh-pages branch that mike needs to update.
188+
- name: Fetch gh-pages branch
189+
run: |
190+
git fetch origin gh-pages:gh-pages 2>/dev/null || true
191+
192+
# Deploy versioned documentation using mike (MkDocs plugin for versioning).
193+
# - For release tags (v*): deploys to versioned folder (e.g., /0.9.1/) and aliases to /latest/.
194+
# - For branches: deploys to /dev/.
195+
# The "${RELEASE_VERSION#v}" syntax strips the 'v' prefix (v0.9.1 -> 0.9.1).
196+
# Also sets 'latest' as the default version for the version selector.
184197
- name: Rebuild and deploy docs with mike
185198
run: |
186199
if [[ "${IS_RELEASE_TAG}" == "true" ]]; then

.github/workflows/pypi-test.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ jobs:
5050
unzip ${DEFAULT_BRANCH}.zip -d .
5151
mkdir -p tests
5252
cp -r diffraction-lib-${DEFAULT_BRANCH}/tests/* tests/
53+
cp diffraction-lib-${DEFAULT_BRANCH}/pytest.ini .
5354
rm -rf ${DEFAULT_BRANCH}.zip diffraction-lib-${DEFAULT_BRANCH}
5455
5556
- name: Create the environment and install dependencies
5657
run: pixi install
5758

58-
- name: Install package from PyPI with all extras
59-
run: pixi add --pypi "easydiffraction[all]"
60-
6159
- name: Run unit tests to verify the installation
6260
run: pixi run unit-tests
6361

@@ -71,7 +69,7 @@ jobs:
7169
run: |
7270
pixi run easydiffraction --version
7371
pixi run easydiffraction list-tutorials
74-
pixi run easydiffraction fetch-tutorials
72+
pixi run easydiffraction download-all-tutorials
7573
7674
- name: Test tutorials as notebooks
7775
run: pixi run notebook-tests

0 commit comments

Comments
 (0)