Skip to content

Commit

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

See merge request it/e3-core!32
  • Loading branch information
leocardao committed Aug 19, 2024
2 parents e30b0bf + 6694e20 commit cf5cfb4
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 103 deletions.
258 changes: 156 additions & 102 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
### GENERAL ###

# Defaults

variables:
GITLAB_REMOTE: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/"
LATEST_PYTHON: py312
GITLAB_REMOTE:
description: "The remote gitlab URL used."
value: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/"
LATEST_PYTHON:
description: "The latest python version used to test this project."
options:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
value: "3.12"

stages:
- Checkstyle
- Tests
- Security
- Documentations

workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- Checks
- Tests Linux
- Tests Windows

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:
- source /it/activate-python ${PYTHON_VERSION:2:1}.${PYTHON_VERSION:3:2}
- mkdir -p "C:/tmp/Trash"
- python -m pip install -U pip

# Common

.tox-common:
before_script:
- python -m pip install --force tox
script:
# Should be quoted using \' to deal with ':' in the command
- 'echo "Tox run environment: ${CI_TOX_ENV:=py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2:2}-cov-xdist}"'
- python -m tox --colored yes -e ${CI_TOX_ENV}

### Linux jobs ###

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

.linux-common:
extends:
- .linux-image
Expand All @@ -58,19 +51,12 @@ default:
- !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 ###
# Stage: Checks

Checkstyle:
stage: Checkstyle
Style:
stage: Checks
extends: .linux-common
needs: []
before_script:
- !reference [.linux-common, before_script]
- git config --global --add
Expand All @@ -87,13 +73,45 @@ Checkstyle:
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: mypy
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

Security:
stage: Checks
needs: []
extends: .linux-common
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: security
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

### LINUX TESTS ###
Documentations:
stage: Checks
needs: ["Style"]
extends: .linux-common
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: docs
only:
refs:
- merge_requests
changes:
- docs/**/*
- pyproject.toml
- setup.cfg
- tox.ini
- .gitlab-ci.yml

# Stage: Tests

.test-linux:
stage: Tests
stage: Tests Linux
extends: .linux-common
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
parallel:
matrix:
- PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12"]
artifacts:
when: always
paths:
Expand All @@ -103,79 +121,115 @@ Checkstyle:
coverage_format: cobertura
path: coverage.xml
junit: pytest-report.xml
variables:
CI_TOX_ENV: ${PYTHON_VERSION}-cov-xdist

Test linux py3.9:
Linux Python:
extends: .test-linux
variables:
PYTHON_VERSION: py39
needs: ["Style"]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

Test linux py3.10:
# A job tiggered by 'Run Linux tests'. This jobs will run without waiting any others
# jobs.
Linux Python (always):
extends: .test-linux
variables:
PYTHON_VERSION: py310
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $CI_MERGE_REQUEST_ID && $CI_PROJECT_NAME == "e3-core" && $ALWAYS_LINUX_TESTS == "y"

Test linux py3.11:
extends: .test-linux
# A manual jobs to run Linux tests even if "Style" jobs has been failed
Run Linux tests:
stage: Tests Linux
needs: []
trigger:
include: .gitlab-ci.yml
strategy: depend
variables:
PYTHON_VERSION: py311
ALWAYS_LINUX_TESTS: "y"
ALWAYS_WINDOWS_TESTS: "n"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
allow_failure: true
# Contrary to what the documentation might suggest, manual_confirmation
# is not currently usable with our gitlab.
# However, when it is, adding a manual confirmation to warn the user that
# this job should only be used when previous steps have failed seems
# useful. Something like:
#
# manual_confirmation: |-
# Are you sure you want to run Linux tests?
#
# This is only useful if the previous stages have failed and you still want to run the tests.

### Windows jobs ###

Test linux py3.12:
extends: .test-linux
variables:
PYTHON_VERSION: py312
.windows-image:
services:
- image:e3-windows-core-2022
- platform:x86_64-windows-2022
- cpu:2
- mem:4
before_script:
- source /it/activate-python ${PYTHON_VERSION}
- mkdir -p "C:/tmp/Trash"
- python -m pip install -U pip

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

.test-windows:
stage: Tests
extends: .windows-common
variables:
CI_TOX_ENV: ${PYTHON_VERSION}-cov-xdist
# Stage: Checks

Test windows py3.9:
extends: .test-windows
variables:
PYTHON_VERSION: py39
#--- Nothing to do during this stage ---#

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

Test windows py3.11:
extends: .test-windows
variables:
PYTHON_VERSION: py311
.test-windows:
stage: Tests Windows
extends: .windows-common
parallel:
matrix:
- PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12"]

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

### OTHERS ###
needs: ["Style"]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"

Security:
stage: Security
extends: .linux-common
# A job tiggered by 'Run Windows tests'. This jobs will run without waiting any others
# jobs.
Windows Python (always):
extends: .test-windows
needs: []
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: security
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $CI_MERGE_REQUEST_ID && $CI_PROJECT_NAME == "e3-core" && $ALWAYS_WINDOWS_TESTS == "y"

Documentations:
stage: Documentations
extends: .linux-common
needs: ["Checkstyle"]
# A manual jobs to run Windows tests even if previous jobs has been failed
Run Windows tests:
stage: Tests Windows
needs: []
trigger:
include: .gitlab-ci.yml
strategy: depend
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: docs
ALWAYS_LINUX_TESTS: "n"
ALWAYS_WINDOWS_TESTS: "y"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- docs/**/*
- pyproject.toml
- setup.cfg
- tox.ini
- .gitlab-ci.yml
when: manual
allow_failure: true
# Contrary to what the documentation might suggest, manual_confirmation
# is not currently usable with our gitlab.
# However, when it is, adding a manual confirmation to warn the user that
# this job should only be used when previous steps have failed seems
# useful. Something like:
#
# manual_confirmation: |-
# Are you sure you want to run Windows tests?
#
# This is only useful if the previous stages have failed and you still want to run the tests.
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 @@ -346,7 +346,7 @@ def test_poll():
)

assert result.poll() is None
time.sleep(2)
time.sleep(5)
assert result.poll() == 0
assert result.out.strip() == "process"

Expand Down

0 comments on commit cf5cfb4

Please sign in to comment.