matrix-alertbot/.gitlab-ci.yml

118 lines
2.3 KiB
YAML

workflow:
rules:
- if: $CI_MERGE_REQUEST_IID
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
VIRTUAL_ENV: "$CI_PROJECT_DIR/.venv"
FF_USE_FASTZIP: "true"
stages:
- install
- quality
- test
- publish
.pip template:
image: python:3.10-alpine
before_script:
- export PATH="${VIRTUAL_ENV}/bin:$PATH"
cache:
key:
files:
- setup.py
- requirements.txt
paths:
- .cache/pip
- ${VIRTUAL_ENV}
interruptible: true
allow_failure: false
install:
extends: .pip template
stage: install
script:
- apk add --no-cache gcc g++ yaml-dev python3-dev
- python3 -m venv "${VIRTUAL_ENV}"
- pip install -r requirements.txt
- pip install .
- pip install -U build twine
cache:
policy: pull-push
needs: []
linting:
extends: .pip template
stage: quality
script:
- isort -c --df .
- flake8 --count --show-source --statistics .
- black --check --diff .
cache:
policy: pull
needs:
- job: install
artifacts: false
tests:
extends: .pip template
stage: test
script:
- apk add --no-cache libstdc++
- coverage run --source matrix_alertbot -m pytest --junitxml=report.xml
- coverage report --precision 2
- coverage xml -o coverage.xml
cache:
policy: pull
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: report.xml
coverage: '/^TOTAL\s+\d+\s+\d+\s+(\d+\.\d+\%)$/'
needs:
- job: linting
artifacts: false
publish test:
extends: .pip template
stage: publish
script:
- python -m build
- twine upload --repository testpypi ./dist/*
cache:
policy: pull
artifacts:
name: $CI_JOB_NAME
paths:
- dist
expire_in: 1 week
rules:
- if: $CI_DEFAULT_BRANCH == CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
environment:
name: test
url: https://test.pypi.org/project/matrix-alertbot
needs:
- job: tests
artifacts: false
publish prod:
extends: .pip template
stage: publish
script:
- twine upload ./dist/*
cache:
policy: pull
rules:
- if: $CI_COMMIT_TAG
when: manual
environment:
name: prod
url: https://pypi.org/project/matrix-alertbot
needs:
- job: publish test
artifacts: true