ci-templates
Ready to include templates for common CI jobs.
Contents
Usage
Autopep8
By including this template in your project, its Python files will be linted with autopep8 for each Merge Request:
- Only the changed files will be checked with black.
- If they are not properly formatted according to black, the CI will fail.
- An assist-MR will be created to automatically fix the formatting.
- Upon merging this assist-MR, the changed files are checked again and the CI should pass.
To use the autopep8 CI template, follow these steps:
-
Add CI Bot as a member to your project in at least the Developer role.
-
Lastly, include the following snippet in your
.gitlab-ci.yml
file:include: - project: 'omegacen/ci-templates' ref: v5 file: '/templates/autoformat/autopep8.yml'
The variables that can be changed are:
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
AUTOPEP8_SELECT | No | No | E101,E121,E123,E125,E131,E133,E201,E202,E21,E22,E23,E24,E25,E27,E3,E502,W2,W3 | The pycodestyle codes to fix. |
AUTOPEP8_IGNORE | No | No | E203,E26 | The pycodestyles to explicitly not fix. |
This CI template cannot be used together with the black CI template.
Black
By including this template in your project, its Python files will be linted with black 19.10b0 for each Merge Request:
- Only the changed files will be checked with black.
- If they are not properly formatted according to black, the CI will fail.
- An assist-MR will be created to automatically fix the formatting.
- Upon merging this assist-MR, the changed files are checked again and the CI should pass.
The default line length is 120, although this can be changed via the
BLACK_LINE_LENGTH
variable.
To use the black CI template, follow these steps:
-
Add CI Bot as a member to your project in at least the Developer role.
-
Lastly, include the following snippet in your
.gitlab-ci.yml
file:include: - project: 'omegacen/ci-templates' ref: v5 file: '/templates/autoformat/black.yml'
The variables that can be changed are:
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
BLACK_LINE_LENGTH | No | No | 120 | How many characters per line black allows. |
This CI template cannot be used together with the autopep8 CI template.
Conda
By including this template, the CI will automatically build one or more conda recipes in the repository and upload the built package our conda channel, https://conda.astro-wise.org.
The following jobs are added to the CI pipeline by including this template
- conda_build, which builds the package.
- conda_test, which tests the built package.
- conda_upload, which upload the package to the conda channel.
All jobs are run for MRs, tags, master, develop, and the default branch. The conda_upload job is only run for tags, and for the master, develop, release branches and the default branch. For conda_upload, the branch or job needs to be protected.
To use this template, do the following.
First, include one or more conda recipes in your repository. For a repository
that produces a single conda package, the file name of the recipe should be
conda-recipes/meta.yaml
. For more information on how to make a conda recipe,
see the conda-wise documentation.
Next, include the following snippet in your .gitlab-ci.yml
file:
include:
- project: 'omegacen/ci-templates'
ref: v5
file: '/templates/conda/all.yml'
The complete list of variables is given below.
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
CONDA_BUILD_EXTRA_ARGS | No | No | Optional extra arguments to conda-build. | |
CONDA_BUILD_COMMAND | No | No | build | Specify 'mambabuild' to use alternative build command from boa. |
CONDARC | No | No | ${CI_PROJECT_DIR}/.condarc | Location of conda config file. |
CONDA_RECIPE_DIR | No | No | conda-recipe | Directory containing package recipe(s). |
CONDA_OUTPUT_FOLDER | No | No | .conda-bld | Directory where built package(s) are stored. |
CONDA_PACKAGE_VERSION | No | No | ${CI_COMMIT_REF_NAME} | Can be used for the conda package version via Jinja2 templating. |
CONDA_BUILD_RUN_JOB | No | No | Triggering conda build and test in scheduled pipelines. |
If set, $CONDA_PACKAGE_VERSION
has to be used as the version of the conda package.
The conda_build job exposes the following environment variables to all subsequent CI jobs:
$CONDA_PACKAGE_NAME
$CONDA_PACKAGE_VERSION
$CONDA_PACKAGE_BUILD_STRING
If the conda_build job builds multiple conda packages, the above variables refer to the first conda package built.
It can take long to resolve the dependencies when creating the environment for
the conda_test job, especially for packages with many dependencies. The resolve
can be sped up by using the solver from mamba, either by using mamba directly
by setting CONDA_BUILD_COMMAND
to mambabuild
or by using the
experimental conda feature by setting CONDA_BUILD_EXTRA_ARGS
to
--experimental-solver=libmamba
.
Conda build
It is possible to only include the template for the build stage, in case you do
not want to automatically upload your build recipe but only want to test it.
In that case, you must include the conda-build.yml
template instead of
conda.yml
:
include:
- project: 'omegacen/ci-templates'
ref: v5
file: '/templates/conda/build.yml'
Monthly Merge
This template performs an automatic release merge and tag based on a schedule (usually monthly). It performs the following steps:
- Merge the
develop
branch into themaster
branch, - Bump the version in specified files according to CalVer
YYYY.MM.MICRO
, - Create a tag on the
master
branch.
To use it, follow these steps:
-
Include the following snippet in your
.gitlab-ci.yml
file:include: - project: 'omegacen/ci-templates' ref: v5 file: '/templates/monthlymerge.yml'
-
Next, create a pipeline schedule in your project. Set it to the first of the month. This pipeline schedule should ideally be owned by CI Bot. This user should a maintainer in your repository (ask a GitLab admin to do this for you after you've created the pipeline schedule). Also add a variable called
MM_RUN_JOB
with a value of1
to the pipeline schedule. -
Next, protect the tags created by this template via a wildcard (
20*
will do). -
Lastly, add the private key of CI Bot to the CI variables as a protected variable called
MM_PRIVATE_KEY
.
The complete list of variables is given below.
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
MM_PRIVATE_KEY | Yes | Yes | The private SSH key of the user that own the pipeline schedule. | |
MM_RUN_JOB | Yes | No | Must be set for the job to run. Add this to the schedule variables. | |
MM_SOURCE | No | No | develop | The source branch to be merged into the target branch. |
MM_TARGET | No | No | master | The target branch into which the source branch will be merged. |
MM_BUMP_FILES | No | No | __init__.py conda-recipe/meta.yaml | A space delimited list of files whose versions will be bumped. |
SonarQube
By including this template, SonarQube source code analysis will automatically be run on the default branch and on merge requests.
To use it, follow these steps:
-
Add CI Bot as a member to your project in at least the Developer role.
-
Lastly, include the following snippet in your
.gitlab-ci.yml
file:include: - project: 'omegacen/ci-templates' ref: v5 file: '/templates/sonarqube.yml'
-
Optionally, you can add one or more Project badges. In your GitLab project, go to Settings -> General -> Badges. Then add the following:
- Name:
Quality Gate Status
- Link:
https://sonar.astro-wise.org/dashboard?id=%{project_path}
- Badge image URL:
https://sonar.astro-wise.org/api/project_badges/measure?project=%{project_path}&metric=alert_status
This adds a Quality Gate badge. There are more metric available; go to the SonarQube project page and click "Get project badges" for a list.
- Name:
The complete list of variables for this CI template is given below.
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
SONAR_SOURCES | No | No | . | Setting the root folder(s) for source files (comma separated). |
SONAR_INCLUSIONS | No | No | **/*.py, **/*.html, **/*.tmpl, **/*.js, **/*.ts, **/*.css | Explicitly including files by patterns (comma separated). |
SONAR_EXCLUSIONS | No | No | Explicitly excluding files by patterns (comma separated). | |
SONAR_SCANNER_EXTRA_ARGS | No | No | Adding extra parameters to Sonar Scanner command line. | |
SONAR_PYLINT_RULES | No | No | C0326:MINOR:1,C0328:MINOR:1,[...],W0703:MINOR:20 | Comma-separated list of <pylint_rule_id>:<severity>:<effort> |
LaTeX
This template builds a pdf file from latex sources. For feature branches and merge requests it will also generate a pdf that highlights the differences with the default branch.
To use it, include the following snippet in your .gitlab-ci.yml
file:
include:
- project: 'omegacen/ci-templates'
ref: v5
file: '/templates/latex.yml'
The filename of the main tex file is determined automatically. This can be
overruled by specifying the FILENAME_TEX
variable.
The complete list of variables for this CI template is given below.
Name | Required | Protected | Default value | Purpose |
---|---|---|---|---|
FILENAME_TEX | No | No | automatically determined | Manual specification of main tex file. |
Controlling when jobs runs
By including a CI template, the jobs in it get automatically run under the right circumstances. E.g., by including the conda template, a conda package is build and tested for each MR to the main branches, and for each commit on the main branches a conda packages is build, tested, and released.
However, if you want more control over when a particular job runs, you can use the
CI_AWE_RUN_<JOBNAME>
and CI_AWE_SKIP_<JOBNAME>
variables to run or to skip
a job, respectively. The full list of variables is as follows:
The latest version of the CI templates is in the master
branch. In addition
there are release branches with naming convention v<X>
. The master
branch is always merged into the latest release branch.
Breaking changes increase the version number of the release branch. So backwards
compatibility is guaranteed when you include a template from a release branch.
However, including a template from the master
branch might lead to breaking
changes every now and then.