From 2a7b00d00cf4526380710b23afc07972eade4412 Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Tue, 20 Aug 2024 16:14:13 +0200 Subject: [PATCH 1/5] Add initial gitlab-ci workflow file --- template/.gitlab-ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 template/.gitlab-ci.yml diff --git a/template/.gitlab-ci.yml b/template/.gitlab-ci.yml new file mode 100644 index 00000000..a83c184d --- /dev/null +++ b/template/.gitlab-ci.yml @@ -0,0 +1,30 @@ +# Change pip's cache directory to be inside the project directory since we can +# only cache local items. +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + +cache: + paths: + - .cache/pip + +test: + stage: test + image: "python:$VERSION" + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + parallel: + matrix: + - VERSION: ['3.8', '3.9', '3.10', '3.11', '3.12'] + before_script: + # Python info + - which python + - python --version + # Install dependencies + - python -m pip install --upgrade pip setuptools + - python -m pip install --editable ".[dev]" + script: + # Run pytest + - python -m pytest -v --durations=0 From be1ef448bbdfb0f44b8bfa31ac760a9628327c6c Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Tue, 20 Aug 2024 16:42:20 +0200 Subject: [PATCH 2/5] Add cffconvert job to .gitlab-ci --- template/.gitlab-ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/template/.gitlab-ci.yml b/template/.gitlab-ci.yml index a83c184d..a4fd9b45 100644 --- a/template/.gitlab-ci.yml +++ b/template/.gitlab-ci.yml @@ -28,3 +28,19 @@ test: script: # Run pytest - python -m pytest -v --durations=0 + +cffconvert: + stage: test + image: + name: "citationcff/cffconvert:2.0.0" + entrypoint: [""] + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + changes: + - CITATION.cff + script: + # Check whether the citation metadata from CITATION.cff is valid + - cffconvert --validate From b643c4557869d46138c9fc76135f4cc2d374b52c Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Tue, 20 Aug 2024 16:59:50 +0200 Subject: [PATCH 3/5] add markdown link checker job to gitlab-ci --- template/.gitlab-ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/template/.gitlab-ci.yml b/template/.gitlab-ci.yml index a4fd9b45..ba185287 100644 --- a/template/.gitlab-ci.yml +++ b/template/.gitlab-ci.yml @@ -44,3 +44,16 @@ cffconvert: script: # Check whether the citation metadata from CITATION.cff is valid - cffconvert --validate + +markdown-link-check: + stage: test + image: + name: "lycheeverse/lychee" + entrypoint: [""] + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + script: + - lychee . From 6aadc2d21efd5df4f4fc926a3c47af4bf6298d9e Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Wed, 21 Aug 2024 08:59:07 +0200 Subject: [PATCH 4/5] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e06afa..5b73e500 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -71,6 +71,7 @@ Released on August 15, 2024 ### Added +* Added `gitlab-ci.yml` file for GitLab alternative to GitHub Actions [#452](https://github.com/NLeSC/python-template/issues/452) * Added Python 3.12 support [#356](https://github.com/NLeSC/python-template/issues/356) * Template unit tests for documentation generation, linting and version bumping * Docstring for function From 09a1afaf028a2ce1a980b3e1f853573696b9a52e Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Thu, 21 Aug 2025 17:05:45 +0200 Subject: [PATCH 5/5] WIP --- template/.gitlab-ci.yml | 73 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/template/.gitlab-ci.yml b/template/.gitlab-ci.yml index ba185287..2b6e3d86 100644 --- a/template/.gitlab-ci.yml +++ b/template/.gitlab-ci.yml @@ -1,5 +1,11 @@ # Change pip's cache directory to be inside the project directory since we can # only cache local items. + +stages: + - lint # Fastest check first + - test # Then test + - build # build package and documentation when verified correct + variables: PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" @@ -24,13 +30,13 @@ test: - python --version # Install dependencies - python -m pip install --upgrade pip setuptools - - python -m pip install --editable ".[dev]" + - python -m pip install --editable .[dev] script: # Run pytest - python -m pytest -v --durations=0 cffconvert: - stage: test + stage: lint image: name: "citationcff/cffconvert:2.0.0" entrypoint: [""] @@ -46,7 +52,7 @@ cffconvert: - cffconvert --validate markdown-link-check: - stage: test + stage: lint image: name: "lycheeverse/lychee" entrypoint: [""] @@ -57,3 +63,64 @@ markdown-link-check: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH script: - lychee . + +lint: + stage: lint + image: "python:3.12" + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + before_script: + # Python info + - which python + - python --version + # Install dependencies + - python -m pip install ruff + script: + # Run pytest + - ruff check + - ruff format --check + +build: + stage: build + image: "python:$VERSION" + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + parallel: + matrix: + - VERSION: ['3.8', '3.9', '3.10', '3.11', '3.12'] + before_script: + # Python info + - which python + - python --version + # Install dependencies + - python -m pip install --upgrade pip setuptools + - python -m pip install --editable .[publishing] + script: + # Run pytest + - python -m build + +documentation: + stage: build + image: "python:3.12" + rules: + # Run on a Merge Request to the default branch + - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH + # Run on new commits to the default branch + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + before_script: + # Python info + - which python + - python --version + # Install dependencies + - python -m pip install .[docs] + - sudo apt install pandoc + script: + # Run pytest + - cd docs + - make coverage doctest html