Skip to content
Commits on Source (2)
...@@ -3,18 +3,17 @@ ...@@ -3,18 +3,17 @@
# SAFETY_API_KEY: # SAFETY_API_KEY:
# Set to your API key for accessing up-to-date package security information # Set to your API key for accessing up-to-date package security information
stages:
- build
- test
- publish
workflow: workflow:
rules: rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event" - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
- if: $CI_OPEN_MERGE_REQUESTS
when: never when: never
- when: always - if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$$/
variables:
PUSH_PACKAGE: "true"
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+/
- if: $CI_COMMIT_BRANCH
.python: .python:
...@@ -44,7 +43,6 @@ Pin: ...@@ -44,7 +43,6 @@ Pin:
# Pin dependencies in requirements.txt for reproducing pipeline results # Pin dependencies in requirements.txt for reproducing pipeline results
stage: test stage: test
extends: [.python] extends: [.python]
needs: []
script: script:
- pip install --prefer-binary -e . - pip install --prefer-binary -e .
- pip freeze --exclude-editable | tee requirements.txt - pip freeze --exclude-editable | tee requirements.txt
...@@ -62,7 +60,7 @@ Dependency Check: ...@@ -62,7 +60,7 @@ Dependency Check:
Code Checks: Code Checks:
stage: test stage: .pre
image: docker.kodo.org.uk/ci-images/pre-commit:2.15.0-1 image: docker.kodo.org.uk/ci-images/pre-commit:2.15.0-1
needs: [] needs: []
variables: variables:
...@@ -84,10 +82,12 @@ Unit Tests: ...@@ -84,10 +82,12 @@ Unit Tests:
extends: [.python] extends: [.python]
needs: [Pin] needs: [Pin]
script: script:
- pip install -r requirements.txt -e . coverage[toml] nose - pip install -r requirements.txt -e .
- coverage run -m nose tests coverage[toml]
pytest
- coverage run -m pytest tests
--verbose --verbose
--with-xunit --xunit-file=results/xunit.xml --junit-xml=results/xunit.xml
after_script: after_script:
- coverage report - coverage report
- coverage json - coverage json
...@@ -108,7 +108,7 @@ Check Tag: ...@@ -108,7 +108,7 @@ Check Tag:
extends: [.python] extends: [.python]
needs: ["Build Package"] needs: ["Build Package"]
rules: rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]/ - if: $CI_COMMIT_TAG
script: script:
- pip install packaging pkginfo - pip install packaging pkginfo
- | - |
...@@ -119,16 +119,17 @@ Check Tag: ...@@ -119,16 +119,17 @@ Check Tag:
wheel_path = glob("dist/*.whl")[0] wheel_path = glob("dist/*.whl")[0]
wheel = Wheel(wheel_path) wheel = Wheel(wheel_path)
assert Version("$CI_COMMIT_TAG") == Version(wheel.version) assert Version("$CI_COMMIT_TAG").release == Version(wheel.version).release, \
f"Pkg version {wheel.version} does not match tag"
END END
Upload Package: Upload Package (Test):
stage: publish stage: deploy
extends: [.python] extends: [.python]
needs: ["Build Package"] dependencies: ["Build Package"]
rules: rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]/ - if: $CI_COMMIT_TAG
script: script:
- pip install twine - pip install twine
- TWINE_USERNAME=gitlab-ci-token - TWINE_USERNAME=gitlab-ci-token
...@@ -138,3 +139,20 @@ Upload Package: ...@@ -138,3 +139,20 @@ Upload Package:
--non-interactive --non-interactive
--repository-url $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/pypi --repository-url $CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/pypi
dist/* dist/*
Upload Package (PyPI):
stage: deploy
extends: [.python]
dependencies: ["Build Package"]
rules:
- if: $PYPI_TOKEN && $PUSH_PACKAGE
when: manual
script:
- pip install twine
- TWINE_USERNAME=__token__
TWINE_PASSWORD=$PYPI_TOKEN
twine upload
--verbose
--non-interactive
dist/*