Skip to content

Commit

Permalink
👷Add CI infrastructure files to run notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnel committed Jun 7, 2024
1 parent 3be8727 commit 01f05a5
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 1 deletion.
21 changes: 20 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ outputs:
example-list:
description: "List of all possible example names to be used in a workflow matrix."
value: ${{ steps.example-run.outputs.example-list }}
notebook-path:
description: "Path to evaluated notebook after running the example"
value: ${{ steps.example-notebook-run.outputs.notebook-path }}

runs:
using: "composite"
Expand Down Expand Up @@ -58,11 +61,12 @@ runs:
echo "Installing with pyglotaran_extras"
pip install wheel
pip install -r pyglotaran-examples/requirements.txt
pip install -r pyglotaran-examples/.github/requirements_ci.txt
fi
echo "::endgroup::"
shell: bash

- name: Run example
- name: Run example scripts
id: example-run
run: |
echo "::group:: Running ${{ inputs.example_name }}"
Expand All @@ -78,6 +82,21 @@ runs:
echo "::endgroup::"
shell: bash

- name: Run example notebooks
id: example-notebook-run
run: |
echo "::group:: Running ${{ inputs.example_name }}"
if [ '${{ inputs.set_example_list }}' = 'false' ]
then
python pyglotaran-examples/scripts/run_examples_notebooks.py ${{ inputs.example_name }} 2>&1
else
pip install yaargh papermill
python pyglotaran-examples/scripts/run_examples_notebooks.py set-gha-example-list-output
fi
echo "::endgroup::"
shell: bash

- name: Save Examples commit sha
if: inputs.set_example_list == 'false'
run: |
Expand Down
7 changes: 7 additions & 0 deletions pyglotaran_examples/.github/requirements_ci.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

pyglotaran>=0.3.0
jupyterlab>=3.0.0
matplotlib>=3.3.0

yaargh>=0.28.0
papermill>=2.3.4
199 changes: 199 additions & 0 deletions pyglotaran_examples/.github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
name: "Run Examples"

on:
push:
tags:
- v**
pull_request:
workflow_dispatch:
inputs:
pyglotaran_branch:
description: "pyglotaran branch/tag to run the examples against"
required: true
default: "main"
pyglotaran_examples_branch:
description: "pyglotaran-examples branch/tag to use"
required: true
default: "main"

jobs:
create-example-list:
name: Create Example List
runs-on: ubuntu-latest
outputs:
example-list: ${{ steps.create-example-list.outputs.example-list }}
steps:
- name: Cloning pyglotaran-examples
if: ${{ github.event.inputs.pyglotaran_examples_branch }} == ""
uses: actions/checkout@v4
with:
path: pyglotaran-examples
- name: Set example list output
id: create-example-list
uses: ./pyglotaran-examples
with:
example_name: set example list
set_example_list: true

run-examples:
name: "Run Example: "
runs-on: ubuntu-latest
needs: [create-example-list]
strategy:
matrix:
example_name: ${{fromJson(needs.create-example-list.outputs.example-list)}}
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
repository: "glotaran/pyglotaran"
# If not provided (push and pull_request event) it uses the main branch
ref: ${{ github.event.inputs.pyglotaran_branch != '' && github.event.inputs.pyglotaran_branch || 'main'}}
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install pyglotaran
run: |
pip install wheel
pip install .
- name: Cloning pyglotaran-examples
if: ${{ github.event.inputs.pyglotaran_examples_branch }} == ""
uses: actions/checkout@v4
with:
path: pyglotaran-examples
- id: example-run
uses: ./pyglotaran-examples
with:
example_name: ${{ matrix.example_name }}
examples_branch: ${{ github.event.inputs.pyglotaran_examples_branch }}

- name: Upload Example Plots Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: example-notebooks-${{ matrix.example_name }}
path: ${{ steps.example-run.outputs.notebook-path }}

- name: Upload Example Results
uses: actions/upload-artifact@v4
with:
name: example-results-${{ matrix.example_name }}
path: ~/pyglotaran_examples_results

collect-artifacts:
if: always()
name: "Collect artifacts and reupload as bundel"
runs-on: ubuntu-latest
needs: [run-examples]
steps:
- name: Download Notebooks Artifacts
uses: actions/download-artifact@v4
with:
path: example-notebooks
pattern: example-notebooks-*
merge-multiple: true

- name: Upload Example Notebooks Artifact
uses: actions/upload-artifact@v4
with:
name: example-notebooks
path: example-notebooks
overwrite: true

- name: Delete Intermediate Notebooks artifacts
uses: GeekyEggo/delete-artifact@v5
with:
name: example-notebooks-*

- name: Download Result Artifacts
uses: actions/download-artifact@v4
with:
path: example-results
pattern: example-results-*
merge-multiple: true

- name: Upload Example Result Artifact
uses: actions/upload-artifact@v4
with:
name: example-results
path: example-results
overwrite: true

- name: Delete Intermediate Result artifacts
uses: GeekyEggo/delete-artifact@v5
with:
name: example-results-*

compare-results:
name: Compare Results
runs-on: ubuntu-latest
needs: [collect-artifacts]
steps:
- name: Checkout compare results
uses: actions/checkout@v4
with:
repository: "glotaran/pyglotaran-examples"
ref: comparison-results
path: comparison-results

- name: Download result artifact
uses: actions/download-artifact@v4
with:
name: example-results
path: comparison-results-current

- name: Show used versions for result creation
run: |
echo "::group:: ✔️ Compare-Results"
echo "✔️ pyglotaran-examples commit: $(< comparison-results/example_commit_sha.txt)"
echo "✔️ pyglotaran commit: $(< comparison-results/pyglotaran_commit_sha.txt)"
echo "::endgroup::"
echo "::group:: ♻️ Current-Results"
echo "♻️ pyglotaran-examples commit: $(< comparison-results-current/example_commit_sha.txt)"
echo "::endgroup::"
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Run result validator
uses: glotaran/pyglotaran-validation@main
with:
validation_name: pyglotaran-examples

create-release:
name: "🚀 Create release assets and tag comparison-results branch"
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
runs-on: ubuntu-latest
needs: [compare-results]
steps:
- name: ⏬ Checkout compare results
uses: actions/checkout@v4
with:
repository: "glotaran/pyglotaran-examples"
ref: comparison-results

- name: Get tag name
id: tag
uses: devops-actions/[email protected]

- name: 📦 Create release asset
run: zip -r comparison-results-${{steps.tag.outputs.tag}}.zip . -x ".git/*"

- name: 🚀⬆️ Upload Release Asset
uses: softprops/action-gh-release@v1
with:
files: comparison-results-${{steps.tag.outputs.tag}}.zip
generate_release_notes: true
append_body: true

- name: 📦 Create comparison-results tag
run: |
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
git config user.name 'github-actions[bot]'
NEW_VERSION="comparison-results-${{steps.tag.outputs.tag}}"
git tag -a $NEW_VERSION -m "Comparison results used with release ${{steps.tag.outputs.tag}}"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git push origin $NEW_VERSION
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-r .github/requirements_ci.txt

yaargh
git+https://github.com/glotaran/pyglotaran-extras.git
Loading

0 comments on commit 01f05a5

Please sign in to comment.