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
11 changes: 11 additions & 0 deletions .conda/env_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
channels:
- accessnri
- conda-forge
- coecms
- nodefaults

dependencies:
- anaconda-client
- conda-build
- conda-verify
- versioneer
5 changes: 2 additions & 3 deletions environment-dev.yml → .conda/env_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ channels:
- nodefaults
dependencies:
- python >=3.10
- pytest
- xarray
- mule
- numpy < 2
- versioneer
- xarray
- pytest
- hypothesis
- ipykernel
- pytest-cov
- pip

45 changes: 45 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{% set version = load_setup_py_data(setup_file='../setup.py', from_recipe_dir=True).get('version') %}
{% set project = load_file_data('../pyproject.toml', from_recipe_dir=True).get('project') %}

package:
name: {{ project.get('name') }}
version: "{{ version }}"

build:
number: 0
noarch: python
script: "python3 -m pip install . -vv"
entry_points:
{% for name, script in project.get('scripts').items() %}
- {{ name }} = {{ script }}
{% endfor %}

source:
path: ../

requirements:
host:
- python
- pip
- setuptools >=61.0.0
- versioneer
run:
{% for dep in project.get('dependencies') %}
- {{ dep }}
{% endfor %}

test:
imports:
- umfile_utils
commands:
{% for name, script in project.get('scripts').items() %}
- {{ name }} --help
{% endfor %}

about:
home: {{ project.get('urls').get('Repository') }}
license: Apache Software
license_file: LICENSE
summary: {{ project.get('description') }}
license_family: Apache

168 changes: 168 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
name: CD

on:
push:
tags:
- '**'
env:
RELEASE_TAG_REGEX: ^[0-9]+\.[0-9]+\.[0-9]+$

jobs:
check-release-tag:
name: Check release tag
runs-on: ubuntu-latest
outputs:
is_release_tag: ${{ steps.check-tag.outputs.is_release_tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true

- name: Check tag
id: check-tag
run: |
is_release_tag=true
tag='${{ github.ref_name }}'
if [[ ! "$tag" =~ ${{ env.RELEASE_TAG_REGEX }} ]]; then
echo "::warning::The tag '$tag' was not recognised as a release tag (MAJOR.MINOR.PATCH format). Therefore, no release was created."
is_release_tag=false
fi
echo "is_release_tag=$is_release_tag" >> $GITHUB_OUTPUT

version-sanity-check:
name: Version sanity check
needs: [check-release-tag]
if: ${{ needs.check-release-tag.outputs.is_release_tag == 'true' }}
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true

- name: Version sanity check
run: |
# Don't allow smaller new versions or jumping versions in the MAJOR.MINOR.PATCH format
old_tag_name=$(git tag --list --sort=-version:refname | grep -E '${{ env.RELEASE_TAG_REGEX }}' | sed -n '2p')
if [ -z "$old_tag_name" ]; then
echo "No previous version found. Skipping version sanity check."
exit 0
fi
new_tag_name='${{ github.ref_name }}'
read -r old_major old_minor old_patch <<< $(echo $old_tag_name | tr '.' ' ')
read -r new_major new_minor new_patch <<< $(echo $new_tag_name | tr '.' ' ')
Comment thread
atteggiani marked this conversation as resolved.
error_msg="Version tag inconsistent!\nVersion '$new_tag_name' cannot come after version '$new_tag_name' (latest released version)."
Comment thread
jo-basevi marked this conversation as resolved.
# Check MAJOR
# - New major version cannot be smaller than previous
# - Major version can only be incremented by 1 at a time
if (( new_major < old_major || new_major > old_major + 1 )); then
echo -e "$msg"
exit 1
fi
# Check MINOR
# - New minor version cannot be smaller than previous if major version is same
# - New minor version can only be 0 if major version is incremented
# - New minor version can only be incremented by 1 at a time
if (( (new_major == old_major && new_minor < old_minor) || (new_major > old_major && new_minor != 0) || (new_minor > old_minor + 1) )); then
echo -e "$msg"
exit 1
fi
# Check PATCH
# - New patch version must be bigger than previous if minor version is same
# - New patch version can only be 0 if minor version is incremented
# - New patch version can only be incremented by 1 at a time
if (( (new_minor == old_minor && new_patch <= old_patch) || (new_minor > old_minor && new_patch != 0) || (new_patch > old_patch + 1) )); then
echo -e "$msg"
exit 1
fi

get-package-name:
name: Get package name
needs: [check-release-tag]
if: ${{ needs.check-release-tag.outputs.is_release_tag == 'true' }}
runs-on: ubuntu-latest
outputs:
package-name: ${{ steps.get-package-name.outputs.package-name }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Get name
id: get-package-name
run: |
echo "package-name=$(yq '.project.name' pyproject.toml)" >> $GITHUB_OUTPUT

release-conda-package:
name: Build with conda and release
runs-on: ubuntu-latest
needs: [check-release-tag, version-sanity-check, get-package-name]
if: ${{ needs.check-release-tag.outputs.is_release_tag == 'true' }}
env:
BUILD_FOLDER: ${{github.workspace}}/build
permissions:
contents: write
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0

- name: Set package path
id: set-package-path
run: |
echo "package-path=${{env.BUILD_FOLDER}}/noarch/*${{vars.PACKAGE_FORMAT}}" >> $GITHUB_OUTPUT

- name: Setup conda build environment
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
miniconda-version: "latest"
python-version: ${{ vars.PY_VERSION }}
environment-file: .conda/env_build.yml
auto-activate-base: false
auto-update-conda: false
show-channel-urls: true

- name: Build conda package
shell: bash -el {0}
run: |
conda build . --no-anaconda-upload --output-folder=${{env.BUILD_FOLDER}} -c accessnri -c conda-forge -c coecms --package-format ${{vars.PACKAGE_FORMAT}}

- name: Upload conda package to Anaconda.org
shell: bash -el {0}
run: |
anaconda -t ${{ secrets.ANACONDA_TOKEN }} upload --user ${{ secrets.ANACONDA_USER_NAME }} ${{steps.set-package-path.outputs.package-path}}
Comment thread
jo-basevi marked this conversation as resolved.

- name: Create Release
uses: softprops/action-gh-release@c062e08bd532815e2082a85e87e3ef29c3e6d191 #v2.0.8
with:
tag_name: ${{ github.ref_name }}
name: ${{needs.get-package-name.outputs.package-name}} ${{ github.ref_name }}
generate_release_notes: true
fail_on_unmatched_files: true
files: |
${{steps.set-package-path.outputs.package-path}}

cleanup-tag-on-failure:
name: Cleanup tag
needs: [check-release-tag, version-sanity-check, get-package-name, release-conda-package]
# Run this job if the tag is a release tag and any of the previous jobs failed (and don't skip if any of the needed jobs is skipped)
if: ${{ always() && failure() && needs.check-release-tag.outputs.is_release_tag == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-tags: true

- name: Delete tag
run: |
git push origin :${{ github.ref }}
echo "A job in the current workflow failed. Tag '${{ github.ref_name }}' was deleted."

140 changes: 106 additions & 34 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,110 @@ on:
workflow_dispatch:

jobs:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup conda environment
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
environment-file: environment-dev.yml
auto-activate-base: false
activate-environment: umfile-utils-dev
auto-update-conda: false
show-channel-urls: true
# JOB to run change in the build files
changes:
runs-on: ubuntu-latest
# Required permissions
permissions:
pull-requests: read
# Set job outputs to values from filter step
outputs:
files: ${{ steps.filter.outputs.files }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install source
shell: bash -l {0}
run: python -m pip install --no-deps --no-build-isolation -e .

- name: List installed packages
shell: bash -l {0}
run: conda list

- name: Run tests
shell: bash -l {0}
run: python -m pytest

- name: Filter files
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 #v3.0.2
id: filter
with:
filters: |
files:
- 'setup.py'
- 'pyproject.toml'
- '.conda/env_build.yml'
- '.conda/meta.yml'

verify-conda-build:
name: Conda Build
runs-on: ubuntu-latest
needs: changes
# Only run if there are changes in the build files
if: ${{ needs.changes.outputs.files == 'true' }}
env:
BUILD_FOLDER: ${{github.workspace}}/build
steps:
- uses: actions/checkout@v4

- name: Set package path
id: set-package-path
run: |
echo "package-path=${{env.BUILD_FOLDER}}/noarch/*${{vars.PACKAGE_FORMAT}}" >> $GITHUB_OUTPUT

- name: Setup conda build environment
uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
with:
miniconda-version: "latest"
python-version: ${{ vars.PY_VERSION }}
environment-file: .conda/env_build.yml
auto-activate-base: false
auto-update-conda: false
show-channel-urls: true

- name: Verify conda recipe
shell: bash -el {0}
run: conda-verify .conda --ignore C2105,C2122
# C2105: invalid package version for ...
# (there is no git tag in this test so versioneer outputs a
# version that conda-verify recognizes as 'invalid')
# C2122: invalid license family
# Reference --> https://github.com/conda/conda-verify?tab=readme-ov-file#checks

- name: Build conda package
shell: bash -el {0}
run: conda build . --no-anaconda-upload --output-folder=${{env.BUILD_FOLDER}} -c accessnri -c conda-forge -c coecms --package-format ${{vars.PACKAGE_FORMAT}}

- name: Verify conda package
shell: bash -el {0}
run: conda-verify ${{steps.set-package-path.outputs.package-path}} --ignore C1105,C1115,C1141
# C1105: invalid version number for ...
# (there is no git tag in this test so versioneer outputs a
# version that conda-verify recognizes as 'invalid')
# C1115: Found invalid license
# C1141: Found python file without a corresponding pyc file
# Reference --> https://github.com/conda/conda-verify?tab=readme-ov-file#checks

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Setup conda environment
uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
python-version: ${{ matrix.python-version }}
environment-file: .conda/env_dev.yml
auto-activate-base: false
activate-environment: umfile-utils-dev
auto-update-conda: false
show-channel-urls: true

- name: Install source
shell: bash -l {0}
run: python -m pip install --no-deps --no-build-isolation -e .

- name: List installed packages
shell: bash -l {0}
run: conda list

- name: Run tests
shell: bash -l {0}
run: python -m pytest

1 change: 0 additions & 1 deletion .github/workflows/unit_testing_umfile_utils.yml

This file was deleted.

Loading
Loading