Skip to content

Commit e1c6afe

Browse files
Update tutorials, workflows, and project configuration (#60)
* Removes branch selection when downloading data * Generates the notebooks from scripts * Auto-rename all cell ids using nbstripout * Update project version to 0.6.0 and adjust dependencies * Renames GitHub workflows for clarity * Adds workflow to delete old GitHub Actions runs * Add GitHub actions for automated release drafting * Add workflow to perform security scanning * Add workflow to enforce PR label verification * Add GitHub Actions workflow for PyPI publishing * Enhances project configuration in pyproject.toml * Applies ruff linting * Apply ruff linting with --unsafe-fixes * Fixes dependency installation * Fixes install command spacing in workflows * Adds YAPF for code formatting and updates Ruff config * Applies ruff formatting * Apply more ruff formatting * Apply prettier formatting * Enhances CI/CD with testing workflow and notebook conversion * Refines workflow scripts for improved readability * Refactors notebook handling in CI workflow * Adds Jupytext to documentation dependencies * Updates workflows to enhance package testing * Standardizes workflow job names and increases timeout * Refines tutorial parameters for performance * Refines Jupyter notebook conversion in workflow * Refines CI workflow naming and formatting * Updates workflow job names and adds shell specifications * Reformats YAML for improved readability * Reorganizes Python setup in GitHub workflow * Adds Windows-specific conda setup to CI workflow * Try fixing Unicode issues on Windows * Enhances CI workflows and separates tutorial testing * Refines workflows and dependencies handling * Adds file overwrite option to download utility * Updates tutorials * Restricts security scan trigger and updates Python matrix * Adds SPDX headers to all source files * Updates copyright information * Add contributing and development guidelines * Corrects GitHub URL in SPDX headers * Update tools/update_spdx-headers.py [ci skip] Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 80c1d50 commit e1c6afe

File tree

161 files changed

+24823
-40683
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+24823
-40683
lines changed

.github/release-drafter.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file is used to configure the Release Drafter GitHub Action
2+
# https://github.com/marketplace/actions/release-drafter
3+
4+
name-template: 'easydiffraction $RESOLVED_VERSION'
5+
tag-template: 'v$RESOLVED_VERSION'
6+
categories:
7+
- title: 'Added'
8+
labels: # Labels to use to categorize a pull request as a feature
9+
- '[scope] significant'
10+
- '[scope] enhancement'
11+
- '[scope] documentation'
12+
- title: 'Fixed'
13+
labels: # Labels to use to categorize a pull request as a bug fix
14+
- '[scope] bug'
15+
- title: 'Changed'
16+
labels: # Labels to use to categorize a pull request as a maintenance task
17+
- '[scope] maintenance'
18+
change-template: '- $TITLE (#$NUMBER)'
19+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
20+
version-resolver:
21+
major:
22+
labels:
23+
- '[scope] significant'
24+
minor:
25+
labels:
26+
- '[scope] enhancement'
27+
patch:
28+
labels:
29+
- '[scope] bug'
30+
- '[scope] maintenance'
31+
- '[scope] documentation'
32+
default: patch
33+
template: |
34+
$CHANGES

.github/workflows/building-deploying-docs.yml renamed to .github/workflows/build-docs.yml

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
name: Building and deploying docs
1+
name: Build and deploy docs
22

33
on:
44
# Trigger the workflow on push
55
push:
6-
# To the develop and master branches
7-
branches: [develop, master, docs, d-spacing]
8-
6+
# Selected branches
7+
branches: [develop, master, docs]
98
# Allows you to run this workflow manually from the Actions tab
109
workflow_dispatch:
1110

11+
# Allow only one concurrent workflow, skipping runs queued between the run
12+
# in-progress and latest queued. And cancel in-progress runs.
13+
concurrency:
14+
group:
15+
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+
cancel-in-progress: true
17+
1218
env:
1319
# Set the environment variables to be used in all jobs defined in this workflow
1420
# Set the CI_BRANCH environment variable to be the branch name
@@ -18,25 +24,25 @@ env:
1824

1925
jobs:
2026
# Job 1: Build the static files for the documentation site
21-
building-docs:
22-
runs-on: macos-14 # Use macOS to switch to dark mode for Plotly charts
27+
build-docs:
28+
strategy:
29+
matrix:
30+
os: [macos-14] # Use macOS to switch to dark mode for Plotly charts
31+
python-version: ['3.13']
2332

24-
steps:
25-
- name: Cancel previous workflow runs
26-
uses: n1hility/cancel-previous-runs@v2
27-
with:
28-
token: ${{ secrets.GITHUB_TOKEN }}
33+
runs-on: ${{ matrix.os }}
2934

35+
steps:
3036
# Without this step, GITHUB_REPOSITORY is not accessible from mkdocs.yml
3137
- name: Get GitHub repository
3238
run: echo "GITHUB_REPOSITORY=$GITHUB_REPOSITORY" >> $GITHUB_ENV
3339

34-
# Save the latest release version of easyscience/EasyDiffractionLib to RELEASE_VERSION
40+
# Save the latest release version of easyscience/diffraction-lib to RELEASE_VERSION
3541
# RELEASE_VERSION is used in the mkdocs.yml file to set release_version.
3642
# The release_version is then needed to display the latest release version in the index.md file
37-
- name: Get the latest release version of EasyDiffraction Library
43+
- name: Get the latest release version of easydiffraction library
3844
run: |
39-
git clone --depth 1 https://github.com/easyscience/EasyDiffractionLib .
45+
git clone --depth 1 https://github.com/easyscience/${{ github.event.repository.name }} .
4046
git fetch --tags
4147
echo "RELEASE_VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
4248
@@ -54,18 +60,19 @@ jobs:
5460
- name: Check-out repository
5561
uses: actions/checkout@v4
5662

57-
- name: Set up Python environment
63+
- name: Set up Python ${{ matrix.python-version }}
5864
uses: actions/setup-python@v5
5965
with:
60-
python-version: '3.12'
66+
python-version: ${{ matrix.python-version }}
6167

6268
- name: Upgrade package installer for Python
69+
shell: bash
6370
run: python -m pip install --upgrade pip
6471

6572
# Install EasyDiffraction Library to run Jupyter notebooks
66-
# Install with the 'charts' and 'docs' extras
73+
# Install with the 'docs' and 'visualization' extras
6774
- name: Install EasyDiffraction Library and its dependencies
68-
run: python -m pip install .
75+
run: python -m pip install .'[dev,docs,visualization]'
6976

7077
# Clone assets extra from:
7178
# - easyscience/assets-docs
@@ -96,19 +103,23 @@ jobs:
96103
cp ../assets-branding/easydiffraction/icons/bw.svg overrides/.icons/easydiffraction.svg
97104
cp ../assets-branding/easyscience-org/icons/eso-icon_bw.svg overrides/.icons/easyscience.svg
98105
99-
# Copy Jupyter notebooks from the project to the docs folder
106+
# Convert python scripts in the notebooks directory to Jupyter notebooks
107+
# Strip output from the notebooks and simpify cell ids
100108
# The notebooks are used to generate the documentation
101-
- name: Convert ${{ env.NOTEBOOKS_DIR }}/*.py to docs/${{env.NOTEBOOKS_DIR }}/*.ipynb
109+
- name:
110+
Convert ${{ env.NOTEBOOKS_DIR }}/*.py to docs/${{env.NOTEBOOKS_DIR
111+
}}/*.ipynb
102112
run: |
103113
cp -R ${{ env.NOTEBOOKS_DIR }}/data docs/${{ env.NOTEBOOKS_DIR }}/
104114
jupytext ${{ env.NOTEBOOKS_DIR }}/*.py --from py:percent --to ipynb
115+
nbstripout ${{ env.NOTEBOOKS_DIR }}/*.ipynb
105116
mv ${{ env.NOTEBOOKS_DIR }}/*.ipynb docs/${{ env.NOTEBOOKS_DIR }}/
106117
107118
# The following step is needed to avoid the following message during the build:
108119
# "Matplotlib is building the font cache; this may take a moment"
109120
- name: Pre-build site step
110121
run: |
111-
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
122+
export PYTHONPATH="$(pwd)/src${PYTHONPATH:+:$PYTHONPATH}"
112123
python -c "import easydiffraction"
113124
114125
# Create the mkdocs.yml configuration file
@@ -125,7 +136,7 @@ jobs:
125136
run: |
126137
export JUPYTER_PLATFORM_DIRS=1
127138
export PYTHONWARNINGS="ignore::RuntimeWarning"
128-
export PYTHONPATH=$(pwd)/src:$PYTHONPATH
139+
export PYTHONPATH="$(pwd)/src${PYTHONPATH:+:$PYTHONPATH}"
129140
mkdocs build
130141
131142
# Set up the Pages action to configure the static files to be deployed
@@ -140,17 +151,16 @@ jobs:
140151
# The artifact is then used in the next job by actions/deploy-pages to deploy the static files to GitHub Pages
141152
# Unfortunately, the artifact is not available for download, so extra steps below are needed to do similar things
142153
- name:
143-
Upload built site as artifact for
144-
easyscience.github.io/EasyDiffractionLib (all branches)
154+
Upload built site as artifact for easyscience.github.io/${{
155+
github.event.repository.name }} (all branches)
145156
uses: actions/upload-pages-artifact@v3
146157
with:
147158
path: site/
148159

149160
# Upload the static files from the site/ directory to be used in the next job
150161
# This extra step is needed to allow the download of the artifact in the next job
151162
# for pushing its content to the branch named 'gh_pages'
152-
- name:
153-
Upload built site as artifact for gh_pages (master branch)
163+
- name: Upload built site as artifact for gh_pages (master branch)
154164
if: ${{ env.CI_BRANCH == 'master' }}
155165
uses: actions/upload-artifact@v4
156166
with:
@@ -160,8 +170,8 @@ jobs:
160170
compression-level: 0
161171

162172
# Job 2: Deploy the static files
163-
deploying-docs:
164-
needs: building-docs # previous job 'build-docs' need to be finished first
173+
deploy-docs:
174+
needs: build-docs # previous job 'build-docs' need to be finished first
165175

166176
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
167177
permissions:
@@ -189,7 +199,9 @@ jobs:
189199
# https://github.com/easyscience/diffraction-lib/settings/environments
190200
# Currently, only develop and master branches are allowed to deploy to GitHub Pages
191201
# Deployed pages are available at https://easyscience.github.io/diffraction-lib
192-
- name: Deploy to easyscience.github.io/diffraction-lib (all branches)
202+
- name:
203+
Deploy to easyscience.github.io/${{ github.event.repository.name }}
204+
(all branches)
193205
uses: actions/deploy-pages@v4
194206

195207
# Download built site as artifact from a previous job for gh_pages (master branch)
@@ -209,7 +221,8 @@ jobs:
209221
# https://github.com/easyscience/diffraction-lib/settings/hooks
210222
# This is done for the gh_pages branch when the site is tested with a step above
211223
- name:
212-
Deploy to gh_pages branch to trigger deployment to custom domain (master branch)
224+
Deploy to gh_pages branch to trigger deployment to custom domain
225+
(master branch)
213226
if: ${{ env.CI_BRANCH == 'master' }}
214227
uses: s0/git-publish-subdir-action@develop
215228
env:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# This workflow will delete old workflow runs based on the input
2+
# parameters.
3+
# https://github.com/Mattraks/delete-workflow-runs
4+
5+
name: Delete old workflow runs
6+
7+
on:
8+
# Run monthly, at 00:00 on the 1st day of month.
9+
schedule:
10+
- cron: '0 0 1 * *'
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
inputs:
15+
days:
16+
description: 'Number of days.'
17+
required: true
18+
default: 30
19+
minimum_runs:
20+
description: 'The minimum runs to keep for each workflow.'
21+
required: true
22+
default: 6
23+
delete_workflow_pattern:
24+
description:
25+
'The name or filename of the workflow. if not set then it will target
26+
all workflows.'
27+
required: false
28+
delete_workflow_by_state_pattern:
29+
description:
30+
'Remove workflow by state: active, deleted, disabled_fork,
31+
disabled_inactivity, disabled_manually'
32+
required: true
33+
default: 'All'
34+
type: choice
35+
options:
36+
- 'All'
37+
- active
38+
- deleted
39+
- disabled_inactivity
40+
- disabled_manually
41+
delete_run_by_conclusion_pattern:
42+
description:
43+
'Remove workflow by conclusion: action_required, cancelled, failure,
44+
skipped, success'
45+
required: true
46+
default: 'All'
47+
type: choice
48+
options:
49+
- 'All'
50+
- action_required
51+
- cancelled
52+
- failure
53+
- skipped
54+
- success
55+
dry_run:
56+
description: 'Only log actions, do not perform any delete operations.'
57+
required: false
58+
59+
jobs:
60+
del-runs:
61+
runs-on: ubuntu-latest
62+
63+
permissions:
64+
actions: write
65+
66+
steps:
67+
- name: Delete workflow runs
68+
uses: Mattraks/delete-workflow-runs@v2
69+
with:
70+
token: ${{ github.token }}
71+
repository: ${{ github.repository }}
72+
retain_days: ${{ github.event.inputs.days }}
73+
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
74+
delete_workflow_pattern:
75+
${{ github.event.inputs.delete_workflow_pattern }}
76+
delete_workflow_by_state_pattern:
77+
${{ github.event.inputs.delete_workflow_by_state_pattern }}
78+
delete_run_by_conclusion_pattern:
79+
${{ github.event.inputs.delete_run_by_conclusion_pattern }}
80+
dry_run: ${{ github.event.inputs.dry_run }}

.github/workflows/publish-pypi.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Builds a Python package and publish it to PyPI when a new tag is
2+
# created.
3+
4+
name: Publish to PyPI
5+
6+
on:
7+
# Runs on creating a new tag starting with 'v', e.g. 'v1.0.3'
8+
push:
9+
tags:
10+
- 'v*'
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
jobs:
15+
pypi-publish:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Check-out repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: '0' # full history with tags to get the version number by versioningit
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: '3.12'
28+
29+
- name: Upgrade package installer for Python
30+
run: pip install --upgrade pip
31+
32+
- name: Install Python dependencies
33+
run: pip install '.[dev]'
34+
35+
- name: Create Python package
36+
run: python -m build
37+
38+
- name: Publish distribution 📦 to PyPI
39+
uses: pypa/gh-action-pypi-publish@release/v1
40+
with:
41+
password: ${{ secrets.PYPI_PASSWORD }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Integrates a collection of open source static analysis tools with
2+
# GitHub code scanning.
3+
# https://github.com/github/ossar-action
4+
5+
name: Scan security (static analysis)
6+
7+
on:
8+
# Trigger the workflow on pull request
9+
pull_request:
10+
branches:
11+
- '**'
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
scan-security-ossar:
17+
# OSSAR runs on windows-latest.
18+
# ubuntu-latest and macos-latest support coming soon
19+
runs-on: windows-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
with:
25+
# We must fetch at least the immediate parents so that if this is
26+
# a pull request then we can checkout the head.
27+
fetch-depth: 2
28+
29+
# If this run was triggered by a pull request event, then checkout
30+
# the head of the pull request instead of the merge commit.
31+
- run: git checkout HEAD^2
32+
if: ${{ github.event_name == 'pull_request' }}
33+
34+
- name: Run open source static analysis tools
35+
uses: github/ossar-action@main
36+
id: ossar
37+
38+
- name: Upload results to Security tab
39+
uses: github/codeql-action/upload-sarif@v3
40+
with:
41+
sarif_file: ${{ steps.ossar.outputs.sarifFile }}

0 commit comments

Comments
 (0)