diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e06af..5b73e50 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 diff --git a/template/.gitlab-ci.yml b/template/.gitlab-ci.yml new file mode 100644 index 0000000..2b6e3d8 --- /dev/null +++ b/template/.gitlab-ci.yml @@ -0,0 +1,126 @@ +# 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" + +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 + +cffconvert: + stage: lint + 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 + +markdown-link-check: + stage: lint + 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 . + +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