Skip to content

Commit

Permalink
build: update pre-commit and add pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
snaeil committed May 22, 2024
1 parent a1db383 commit 71b041f
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 25 deletions.
91 changes: 91 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
default:
image: python:3.11

stages:
- commit_msg
- lint
- test
- safety
- docs
- post

before_script:
- python --version
- pip install poetry
- poetry --version
- poetry lock --check
- poetry install --no-root

# TODO: do this with poetry
gitlint:
stage: commit_msg
script:
- git config --global user.name "$GITLAB_USER_NAME"
- git config --global user.email "$GITLAB_USER_EMAIL"
- pip install gitlint==0.19.1
- echo "$CI_COMMIT_MESSAGE" > commit_message.txt
- gitlint --config=.gitlint --msg-filename=commit_message.txt

black:
stage: lint
script:
- poetry run black --check .

pylint:
stage: lint
script:
- poetry run pylint --rcfile=.pylintrc **/*.py

pylint-test:
stage: lint
script:
- poetry run pylint --rcfile=.pylintrc.tests tests

mypy:
stage: lint
script:
- poetry run mypy .

doctests:
stage: test
script:
- poetry run pytest --doctest-modules argparsenv

unittests:
stage: test
script:
- poetry run pytest -v

coverage_report:
stage: test
script:
- poetry run pytest --cov-report html --cov=.

check-tag:
stage: test
image: docker:20
before_script: []
script:
- export CURRENT_VERSION=$(sed -n "s/version = \"\(.*\)\"/\1/p" pyproject.toml)
- '[ "$CI_COMMIT_TAG" = "$CURRENT_VERSION" ] && true || false'
only:
# https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
- /^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
- tags
except:
- branches

safety_check:
stage: safety
script:
- pip install safety==2.3.5
- safety check --full-report
allow_failure: true

bandit_check:
stage: safety
script:
- poetry run bandit -c bandit.yaml -r .
allow_failure: true

# TODO: add changelog
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ repos:
"overrides",
"python-dotenv",
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
- repo: local
hooks:
- id: mypy
args: [--ignore-missing-imports]
additional_dependencies:
[
]
name: mypy
entry: mypy argparsenv
language: system
pass_filenames: false
always_run: true
- repo: local
hooks:
- id: doctests
Expand Down
37 changes: 18 additions & 19 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71b041f

Please sign in to comment.