Skip to content

Commit

Permalink
Merge branch 'mr/cardao/add-gitlab-ci' into 'master'
Browse files Browse the repository at this point in the history
Add .gitlab-ci.yml

See merge request it/e3-core!1
  • Loading branch information
leocardao committed Jul 11, 2024
2 parents b7c0073 + 1f67abd commit 0cbf30b
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 5 deletions.
195 changes: 195 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
### GENERAL ###

# Defaults

variables:
GITLAB_REMOTE: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/"
LATEST_PYTHON: py312

stages:
- Checkstyle
- Linux
- Windows
- Security
- Documentations

workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

default:
services:
- run_as_root:false
interruptible: true


# Images

.linux-image:
services:
- image:all-pythons
- cpu:4
before_script:
- source /it/activate-${PYTHON_VERSION}
- python -m pip install -U pip

.windows-image:
services:
- image:e3-windows-core-2022
- platform:x86_64-windows-2022
- cpu:2
- mem:4
before_script:
- export CI_WIN_PYTHON=${PYTHON_VERSION:2:1}.${PYTHON_VERSION:3:2}
- mkdir -p /it/python/$CI_WIN_PYTHON
- cd /it/python/$CI_WIN_PYTHON
- e3-cathod components --component=python$CI_WIN_PYTHON --platform=x86_64-windows64 --setup=thirdparties --build-date=all --as-name=python$CI_WIN_PYTHON --download
- tar -xzf python$CI_WIN_PYTHON.tar.gz --strip-components=1
- rm -f python$CI_WIN_PYTHON.tar.gz
- cd -
- export PATH="/it/python/$CI_WIN_PYTHON:/it/python/$CI_WIN_PYTHON/Scripts:$PATH"
- unset CI_WIN_PYTHON
- mkdir -p "C:/tmp/Trash"
- python -m pip install -U pip


# Common

.tox-common:
before_script:
- python -m pip install --force tox
script:
- python -m tox --colored yes -e ${CI_TOX_ENV}

.linux-common:
extends:
- .linux-image
- .tox-common
before_script:
- !reference [.linux-image, before_script]
- !reference [.tox-common, before_script]

.windows-common:
extends:
- .windows-image
- .tox-common
before_script:
- !reference [.windows-image, before_script]
- !reference [.tox-common, before_script]


### CHECKSTYLE ###

Checkstyle:
stage: Checkstyle
extends: .linux-common
before_script:
- !reference [.linux-common, before_script]
- git config --global --add
url."${GITLAB_REMOTE}/it/black.git".insteadOf
https://github.com/ambv/black
- git config --global --add
url."${GITLAB_REMOTE}/it/flake8.git".insteadOf
https://github.com/pycqa/flake8
- python -m pip install pre-commit
- pre-commit install
script:
- pre-commit run -a --show-diff-on-failure
- !reference [.linux-common, script]
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: mypy


### LINUX TESTS ###

.test-linux:
stage: Linux
extends: .linux-common
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
paths:
- pytest-report.xml
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: pytest-report.xml
variables:
CI_TOX_ENV: ${PYTHON_VERSION}-cov-xdist

Test linux py3.9:
extends: .test-linux
variables:
PYTHON_VERSION: py39

Test linux py3.10:
extends: .test-linux
variables:
PYTHON_VERSION: py310

Test linux py3.11:
extends: .test-linux
variables:
PYTHON_VERSION: py311

Test linux py3.12:
extends: .test-linux
variables:
PYTHON_VERSION: py312


### WINDOWS TESTS ###

.test-windows:
stage: Windows
extends: .windows-common
variables:
CI_TOX_ENV: ${PYTHON_VERSION}-cov-xdist

Test windows py3.9:
extends: .test-windows
variables:
PYTHON_VERSION: py39

Test windows py3.10:
extends: .test-windows
variables:
PYTHON_VERSION: py310

Test windows py3.11:
extends: .test-windows
variables:
PYTHON_VERSION: py311

Test windows py3.12:
extends: .test-windows
variables:
PYTHON_VERSION: py312


### OTHERS ###

Security:
stage: Security
extends: .linux-common
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: security

Documentations:
stage: Documentations
extends: .linux-common
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: security
only:
refs:
- merge_requests
changes:
- docs/**/*
- pyproject.toml
- setup.cfg
- tox.ini
- .gitlab-ci.yml
5 changes: 5 additions & 0 deletions tests/tests_e3/anod/checkout_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import logging
import os
import pytest
Expand Down Expand Up @@ -42,6 +43,10 @@ class TestCheckout:
repo_data = os.path.join(os.path.dirname(__file__), "vcs_data")
repo_data2 = os.path.join(os.path.dirname(__file__), "vcs_data2")

@pytest.mark.skipif(
sys.platform == "win32",
reason="test using SVN: not available in our windows CI image at the moment.",
)
@pytest.mark.parametrize("compute_changelog", [True, False])
@pytest.mark.parametrize("e3_feature", ["", "git_shallow_fetch"])
def test_svn_checkout(self, svn, compute_changelog, e3_feature):
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_e3/os/process/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run_test():
"print('hello'); import sys; sys.stdout.flush(); "
"import time; time.sleep(10); print('world')",
],
timeout=1,
timeout=3,
)
assert "hello" in p.out
assert "world" not in p.out
Expand Down
4 changes: 4 additions & 0 deletions tests/tests_e3/vcs/svn/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def file_url(path, unix=False):
return "file://" + path


@pytest.mark.skipif(
sys.platform == "win32",
reason="test using SVN: not available in our windows CI image at the moment.",
)
def test_svn_repo(svn):
cwd = os.getcwd()

Expand Down
15 changes: 11 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ commands=
cov: --cov={envsitepackagesdir}/e3 --cov-branch \
[]

[testenv:check]
# Run mypy, pip audit, and bandit
[testenv:mypy]
# Run mypy
extras =
config
check
commands =
mypy -- {toxinidir}/src


[testenv:security]
# Run pip audit, and bandit
extras =
config
check
Expand All @@ -33,8 +42,6 @@ commands =
# environment variable. Don't check for that.
# B202: should be investigated see https://github.com/AdaCore/e3-core/issues/694
bandit -r src/e3 -ll -ii -s B102,B108,B202,B301,B303,B506
pip-audit --desc on {toxinidir}
mypy -- {toxinidir}/src

[testenv:docs]
deps =
Expand Down

0 comments on commit 0cbf30b

Please sign in to comment.