-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CI] GitHub Actions workflows and GitLab CI example script
- Loading branch information
Showing
6 changed files
with
317 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
## Disclaimer - This GitHub Actions workflow runs all the tests for changed pipelines. | ||
|
||
# Name the workflow | ||
name: pipeline_tests | ||
|
||
# Define when it runs (on PR when code for a pipeline changes) | ||
on: | ||
pull_request: | ||
paths: | ||
- 'narps_open/pipelines/**' | ||
|
||
# Jobs that define the workflow | ||
jobs: | ||
|
||
# A job to list the tests to be run | ||
identify-tests: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tests: ${{ steps.identify.outputs.tests }} | ||
steps: | ||
- name: Checkout main branch for comparison | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: main | ||
fetch-depth: 0 | ||
|
||
- name: Checkout current branch | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Create a list of tests for changed pipelines | ||
id: identify | ||
run: | | ||
# Loop through modified files | ||
for file in $(git diff --name-only remotes/origin/main...$GITHUB_SHA) | ||
do | ||
# List team id corresponding to team_* files | ||
if [[ "$file" =~ .*"narps_open/pipelines/team_".* ]]; then | ||
echo "Modified pipeline = $file" | ||
tmp=${file#*"team_"} # remove prefix ending in "team_" | ||
team_id=${tmp%".py"*} # remove suffix starting with ".py" | ||
# Populate the list of test files | ||
test_files="$test_files tests/pipelines/test_team_$team_id.py" | ||
fi | ||
done | ||
# Send the test list as job output | ||
echo "tests=$test_files" >> $GITHUB_OUTPUT | ||
# A job to run the identified tests | ||
pytest: | ||
needs: identify-tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install . | ||
- name: Collect tests with pytest | ||
run: pytest --collect-only -q ${{ needs.identify-tests.outputs.tests }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Disclaimer - This GitHub Actions workflow runs all the changed tests for the project. | ||
|
||
# Name the workflow | ||
name: test_changes | ||
|
||
# Define when it runs (on PR when a test changes) | ||
on: | ||
pull_request: | ||
paths: | ||
- 'tests/**' | ||
|
||
# Jobs that define the workflow | ||
jobs: | ||
|
||
# A job to list the tests to be run | ||
pytest: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout main branch for comparison | ||
uses: actions/checkout@v3 | ||
with: | ||
ref: main | ||
fetch-depth: 0 | ||
|
||
- name: Checkout current branch | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Create a list of tests for changed tests | ||
id: identify | ||
run: | | ||
echo "tests=$(git diff --name-only remotes/origin/main...$GITHUB_SHA)" >> $GITHUB_OUTPUT | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install . | ||
- name: Collect tests with pytest | ||
run: pytest --collect-only -q ${{ steps.identify.outputs.tests }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
## Disclaimer - This GitHub Actions workflow runs all the unit tests for the project. | ||
|
||
# Name the workflow | ||
name: unit_testing | ||
|
||
# Define when it runs (on PR when narps_open files change) | ||
on: | ||
pull_request: | ||
paths: | ||
- 'narps_open/**' | ||
- '!narps_open/pipelines/**' | ||
|
||
# Jobs that define the workflow | ||
jobs: | ||
# Name of the job running unit tests | ||
pytest: | ||
|
||
# Define the runner for this job | ||
runs-on: ubuntu-latest | ||
|
||
# Steps that define the job | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install . | ||
- name: Collect tests with pytest | ||
run: | | ||
pytest --collect-only -q --ignore=tests/pipelines/ tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
## Disclaimer - This GitLab CI script allow contributors to perform CI on | ||
|
||
# We assume the runner uses Docker as executor | ||
# We assume that the following images are available on the system : | ||
# - elodiegermani/open_pipeline | ||
|
||
default: | ||
# Run all scripts in a docker container based on this image | ||
image: elodiegermani/open_pipeline | ||
|
||
before_script: | ||
# Activate conda virtual environment | ||
- source activate neuro | ||
|
||
# Install the narps_open python package from the source code | ||
- pip install . | ||
|
||
stages: | ||
- code_quality | ||
- testing | ||
|
||
# Static analysis of the project's code | ||
pylint_job: | ||
stage: code_quality | ||
script: | ||
# Install pylint | ||
- pip install pylint | ||
|
||
# Run pylint | ||
- pylint --exit-zero narps_open > pylint_report_narps_open.txt | ||
- pylint --exit-zero tests > pylint_report_tests.txt | ||
|
||
artifacts: | ||
when: always | ||
paths: | ||
- pylint_report_narps_open.txt | ||
- pylint_report_tests.txt | ||
- todos_narps_open.txt | ||
- todos_tests.txt | ||
|
||
# Running tests for narps_open (except pipelines) | ||
unit_tests-job: | ||
stage: testing | ||
script: | ||
# Install pytest & coverage | ||
- pip install pytest pytest-cov | ||
|
||
# Run tests and produce reports | ||
- coverage run -m pytest --junit-xml=pytest_report.xml --ignore=tests/pipelines/ tests/ | ||
- coverage report | ||
- coverage xml | ||
|
||
artifacts: | ||
when: on_success | ||
reports: | ||
junit: pytest_report.xml | ||
coverage_report: | ||
coverage_format: cobertura | ||
path: coverage.xml | ||
|
||
rules: | ||
# If something changed in narps_open (except in narps_open/pipelines) | ||
- if: $CI_COMMIT_BRANCH | ||
changes: | ||
compare_to: 'refs/heads/main' | ||
paths: | ||
- 'narps_open/(?!pipelines)*' | ||
|
||
# Running tests for pipelines | ||
pipeline_tests-job: | ||
stage: testing | ||
variables: | ||
PIPELINES_TEST_FILES : "" | ||
#GIT_STRATEGY: clone # So that we can access the main branch for git diff purpose | ||
script: | ||
# Install pytest & coverage | ||
- pip install pytest pytest-cov | ||
|
||
- git switch main | ||
- git switch $CI_COMMIT_BRANCH | ||
|
||
# List test files corresponding to modified files | ||
- | | ||
for file in $(git diff --name-only origin/main...$CI_COMMIT_BRANCH) | ||
do | ||
if [[ "$file" =~ .*"pipeline".* ]]; then | ||
echo "Modified pipeline = $file" | ||
tmp=${file#*"team_"} # remove prefix ending in "team_" | ||
team_id=${tmp%".py"*} # remove suffix starting with ".py" | ||
PIPELINES_TEST_FILES="$PIPELINES_TEST_FILES tests/pipelines/test_team_$team_id.py" | ||
fi | ||
done | ||
- echo "$PIPELINES_TEST_FILES" | ||
|
||
# Run tests and produce reports | ||
- coverage run -m pytest --junit-xml=pytest_report.xml "$PIPELINES_TEST_FILES" | ||
- coverage report | ||
- coverage xml | ||
|
||
artifacts: | ||
when: on_success | ||
reports: | ||
junit: pytest_report.xml | ||
coverage_report: | ||
coverage_format: cobertura | ||
path: coverage.xml | ||
|
||
rules: | ||
# If something changed in narps_open/pipelines | ||
- if: $CI_COMMIT_BRANCH | ||
changes: | ||
compare_to: 'refs/heads/main' | ||
paths: | ||
- 'narps_open/pipelines*' | ||
|
||
# Running tests that changed | ||
test_changes-job: | ||
stage: testing | ||
variables: | ||
TEST_FILES : "" | ||
#GIT_STRATEGY: clone # So that we can access the main branch for git diff purpose | ||
script: | ||
# Install pytest & coverage | ||
- pip install pytest pytest-cov | ||
|
||
- git switch main | ||
- git switch $CI_COMMIT_BRANCH | ||
|
||
# List test files corresponding to modified files | ||
- TEST_FILES=$(git diff --name-only origin/main...$CI_COMMIT_BRANCH) | ||
|
||
# Run tests and produce reports | ||
- coverage run -m pytest --junit-xml=pytest_report.xml "$TEST_FILES" | ||
- coverage report | ||
- coverage xml | ||
|
||
artifacts: | ||
when: on_success | ||
reports: | ||
junit: pytest_report.xml | ||
coverage_report: | ||
coverage_format: cobertura | ||
path: coverage.xml | ||
|
||
rules: | ||
# If something changed in narps_open/pipelines | ||
- if: $CI_COMMIT_BRANCH | ||
changes: | ||
compare_to: 'refs/heads/main' | ||
paths: | ||
- 'tests/*' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters