Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/check_app_manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Check App Centre manifest

# Checks labconstrictor-app.yaml (the description of the app for the LabConstrictor App Centre).
# A missing file is a warning, an invalid file fails this check. It never blocks building installers:
# it runs on its own, also when a release is published.
on:
pull_request:
paths:
- labconstrictor-app.yaml
- .tools/schema/**
- .tools/python/check_app_manifest.py
- .github/workflows/check_app_manifest.yml
push:
branches:
- main
paths:
- labconstrictor-app.yaml
- .tools/schema/**
- .tools/python/check_app_manifest.py
- .github/workflows/check_app_manifest.yml
release:
types:
- published
workflow_dispatch:

permissions:
contents: read

jobs:
check:
name: Check labconstrictor-app.yaml
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
with:
python-version: '3.11'

- name: Install requirements
run: pip install pyyaml==6.0.2 jsonschema==4.23.0

- name: Check the manifest
run: python .tools/python/check_app_manifest.py
79 changes: 79 additions & 0 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Publish the Python package to PyPI

# Publishes the app's own Python code (the package in src/) on PyPI at each release, with the version of the release: the same
# moment and the same version as the installers (release_constructor.yml).
#
# OFF BY DEFAULT: both jobs are skipped unless the repository variable PYPI_PUBLISH is
# true -> publish on PyPI (pypi.org)
# testpypi -> publish on TestPyPI (test.pypi.org), a trial
# No secret or token: PyPI trusted publishing. One-time setup (a pending trusted publisher on pypi.org for this workflow file and the
# environment "pypi", then the variable): .tools/docs/external_code_upload.md. To turn it off, delete the variable.

on:
release:
types:
- published

permissions:
contents: read

jobs:
build:
name: Build the package of src/
if: vars.PYPI_PUBLISH == 'true' || vars.PYPI_PUBLISH == 'testpypi'
runs-on: ubuntu-latest
outputs:
url: ${{ steps.build.outputs.url }}
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
with:
python-version: '3.11'

- name: Install requirements
run: pip install -r .tools/requirements.txt build==1.3.0

# The tag (v1.2.3 or 1.2.3) without the v. The checkout is the tagged commit, before the "Update version" commit of
# release_constructor.yml: pypi_package.py writes this version into setup.py itself (not committed).
- name: Build and check the package (nothing is uploaded yet)
id: build
env:
TAG: ${{ github.event.release.tag_name }}
PYPI_PUBLISH: ${{ vars.PYPI_PUBLISH }}
run: python .tools/python/pypi_package.py --version "${TAG#v}" --index "$PYPI_PUBLISH" --outdir dist --github-output "$GITHUB_OUTPUT"

- name: Store the distributions
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: python-package-distributions
path: dist/
if-no-files-found: error

publish:
name: Upload to ${{ vars.PYPI_PUBLISH == 'testpypi' && 'TestPyPI' || 'PyPI' }}
needs: build
if: vars.PYPI_PUBLISH == 'true' || vars.PYPI_PUBLISH == 'testpypi'
runs-on: ubuntu-latest
# The environment named in the trusted publisher on pypi.org (and test.pypi.org). GitHub creates it on the first run; protection
# rules added to it (Settings > Environments > pypi), such as required reviewers, then apply to every upload.
environment:
name: pypi
url: ${{ needs.build.outputs.url }}
permissions:
id-token: write # trusted publishing: PyPI accepts a short-lived token that GitHub signs for this workflow and environment
steps:
- name: Download the distributions
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: python-package-distributions
path: dist/

- name: Upload
uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3
with:
repository-url: ${{ vars.PYPI_PUBLISH == 'testpypi' && 'https://test.pypi.org/legacy/' || 'https://upload.pypi.org/legacy/' }}
220 changes: 220 additions & 0 deletions .github/workflows/release_constructor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
name: Build Release Installers

on:
release:
types:
- published
workflow_dispatch:
inputs:
version:
description: "Version to package (e.g. 0.0.4). Defaults to release tag when empty."
required: false

# This enables to run a single workflow at a time
concurrency:
group: notebooks-global-lock-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: write

jobs:
bump-version:
name: Bump version on main branch
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Determine release version
id: version
run: |
set -euxo pipefail
RAW="${{ github.event.release.tag_name }}"
# The tag as typed (v1.0.0 or 1.0.0): bump_version.py points the download links to it.
echo "RELEASE_TAG=$RAW" >> "$GITHUB_ENV"
RAW="${RAW#v}"
echo "release_version=$RAW" >> "$GITHUB_OUTPUT"
echo "RELEASE_VERSION=$RAW" >> "$GITHUB_ENV"

- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
with:
python-version: '3.11'

- name: Install requirements
run: pip install -r .tools/requirements.txt

- name: Sync versioned files
run: |
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"bump_version.py" \
.tools/python/bump_version.py \
python .tools/python/bump_version.py "${RELEASE_VERSION}"
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"bump_constructor.py" \
.tools/python/bump_constructor.py \
python .tools/python/bump_constructor.py
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"bump_Welcome_notebook.py" \
.tools/python/bump_Welcome_notebook.py \
python .tools/python/bump_Welcome_notebook.py "${{ github.repository_owner }}" "${{ github.event.repository.name }}"
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"check_placeholders.py" \
.tools/python/check_placeholders.py \
python .tools/python/check_placeholders.py
bash .tools/bash/run_with_context.sh \
artifacts/error_log_document.log \
"merge_requirements.py --check" \
.tools/python/merge_requirements.py \
python .tools/python/merge_requirements.py --source-dir notebooks --output requirements.txt --check


- name: Commit updated versioned files
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5
with:
branch: main
commit_message: GitHub Action - Update version to ${{ github.event.release.tag_name }}

- name: Upload diagnostics
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: release-bump-version-logs
path: artifacts/error_log_document.log
if-no-files-found: ignore
archive: false

platforms:
name: Installers to build
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
with:
python-version: '3.11'

- name: Install requirements
run: pip install -r .tools/requirements.txt

- name: Read distribution.platforms of labconstrictor-app.yaml
id: matrix
run: python .tools/python/release_platforms.py --github-output "$GITHUB_OUTPUT"

build-installers:
name: Build installers (${{ matrix.os_name }})
runs-on: ${{ matrix.runner }}
needs: [bump-version, platforms]
strategy:
fail-fast: false
# One build per system of distribution.platforms in labconstrictor-app.yaml (every system without it), from the platforms job.
matrix: ${{ fromJSON(needs.platforms.outputs.matrix) }}
defaults:
run:
shell: bash -l {0}
env:
CONSTRUCTOR_ENV: constructor-env
OUTPUT_DIR: dist/${{ matrix.os_name }}
steps:
- name: Checkout repository
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Determine release version
id: version
run: |
set -euxo pipefail
if [ "${{ github.event_name }}" = "release" ]; then
RAW="${{ github.event.release.tag_name }}"
else
RAW="${{ inputs.version }}"
fi

if [ -z "$RAW" ]; then
echo "Version is required when running manually." >&2
exit 1
fi

# The tag as typed (v1.0.0 or 1.0.0): bump_version.py points the download links to it.
echo "RELEASE_TAG=$RAW" >> "$GITHUB_ENV"
RAW="${RAW#v}"
echo "release_version=$RAW" >> "$GITHUB_OUTPUT"
echo "RELEASE_VERSION=$RAW" >> "$GITHUB_ENV"

- name: Set up Python
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4
with:
python-version: '3.11'

- name: Install requirements
run: pip install -r .tools/requirements.txt

- name: Sync versioned files and populate Welcome notebook
run: |
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document.log" \
"bump_version.py" \
.tools/python/bump_version.py \
python .tools/python/bump_version.py "${RELEASE_VERSION}"
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document.log" \
"bump_constructor.py" \
.tools/python/bump_constructor.py \
python .tools/python/bump_constructor.py
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document.log" \
"bump_Welcome_notebook.py" \
.tools/python/bump_Welcome_notebook.py \
python .tools/python/bump_Welcome_notebook.py "${{ github.repository_owner }}" "${{ github.event.repository.name }}"
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document.log" \
"check_placeholders.py" \
.tools/python/check_placeholders.py \
python .tools/python/check_placeholders.py

- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@fc2d68f6413eb2d87b895e92f8584b5b94a10167 # v3
with:
auto-activate: true
miniforge-version: latest
use-mamba: true

- name: Create constructor environment
run: |
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document_${{ matrix.os_name }}.log" \
"create_constructor_environment.sh" \
.tools/bash/create_constructor_environment.sh \
bash .tools/bash/create_constructor_environment.sh

- name: Build installer with constructor
run: |
bash .tools/bash/run_with_context.sh \
"artifacts/error_log_document_${{ matrix.os_name }}.log" \
"build_installer_with_constructor.sh" \
.tools/bash/build_installer_with_constructor.sh \
bash .tools/bash/build_installer_with_constructor.sh

- name: Upload diagnostics
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
with:
name: build-installers-${{ matrix.os_name }}-logs
path: artifacts/error_log_document_${{ matrix.os_name }}.log
if-no-files-found: ignore
archive: false

- name: Upload installers to release
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2
with:
files: dist/${{ matrix.os_name }}/*
fail_on_unmatched_files: true
Loading
Loading