Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • EOLE/infra/ci-tools
  • daniel.dehennin/ci-tools
2 results
Show changes
Commits on Source (21)
......@@ -7,12 +7,23 @@ ARG SEMAINTIC_GITLAB_VERSION=7
ARG SEMAINTIC_CHANGELOG_VERSION=6
ARG SEMAINTIC_EXEC_VERSION=6
ARG SEMAINTIC_GIT_VERSION=10
ARG SEMANTIC_PYPI_VERSION=2
RUN apk add --no-cache git \
ca-certificates
ca-certificates \
py3-mock \
py3-pip \
py3-setuptools \
py3-twine \
py3-wheel \
python3
# semantic-release-pypi requires the `python` binary
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN npm install -g semantic-release@${SEMAINTIC_RELEASE_VERSION} \
@semantic-release/gitlab@${SEMAINTIC_GITLAB_VERSION} \
@semantic-release/changelog@${SEMAINTIC_CHANGELOG_VERSION} \
@semantic-release/exec@${SEMAINTIC_EXEC_VERSION} \
@semantic-release/git@${SEMAINTIC_GIT_VERSION}
@semantic-release/git@${SEMAINTIC_GIT_VERSION} \
semantic-release-pypi@${SEMANTIC_PYPI_VERSION}
# CI tools
# Tools for the Gitlab CI
Tools for the Gitlab CI
This project provides several YAML files to be
[included](https://docs.gitlab.com/ee/ci/yaml/#include) in your
project [.gitlab-ci.yml](https://docs.gitlab.com/ee/ci/yaml/) file.
[[_TOC_]]
## Features
The CI tools:
- supports up to 3 branches in a release cycles
- provides YAML templates to
- [validate commit message formatting](docs/GETTING-STARTED.md#validate-commit-messages)
- [build and tag docker images](docs/GETTING-STARTED.md#build-and-tag-docker-images)
- [publish releases automatically on push to `$STABLE_BRANCH`](docs/GETTING-STARTED.md#generate-release-with-semantic-version-scheme)
```mermaid
graph LR
%% User working branch
Branch([CONTRIB BRANCH])
BranchCI{{CI}}
BranchCommitLint(commitlint)
BranchDockerImage((image))
BranchDockerTag>docker:git-$CI_COMMIT_SHORT_SHA]
%% Project `dev` branch
Dev([DEV])
DevCI{{CI}}
DevCommitLint(commitlint)
DevDockerImage((image))
DevDockerTag>docker:dev]
%% Project `testing` branch for prerelease
Testing([TESTING])
TestingCI{{CI}}
TestingCommitLint(commitlint)
TestingDockerImage((image))
TestingDockerTag>docker:testing]
%% Project `stable` branch
Stable([STABLE])
StableCI{{CI}}
%% Project `release` tag
Release>release/x.y.z]
ReleaseCI{{CI}}
ReleaseDockerTag{{docker:x.y.z}}
MajorDockerTag{{docker:x}}
MinorDockerTag{{docker:x.y}}
StableDockerTag{{docker:stable}}
LatestDockerTag{{docker:latest}}
Branch -->|push| BranchCI
BranchCI -->|lint| BranchCommitLint
BranchCI -->|build| BranchDockerImage
BranchCI -->|release| BranchDockerTag
BranchDockerTag -.- BranchDockerImage
Branch -->|merge| Dev
Dev -->|push| DevCI
DevCI -->|lint| DevCommitLint
DevCI -->|build| DevDockerImage
DevCI -->|release| DevDockerTag
DevDockerTag -.- DevDockerImage
Dev -->|merge| Testing
Testing -->|push| TestingCI
TestingCI -->|lint| TestingCommitLint
TestingCI -->|build| TestingDockerImage
TestingCI -->|release| TestingDockerTag
TestingDockerTag -.- TestingDockerImage
Testing -->|merge| Stable
Stable -->|push| StableCI
StableCI -->|release| Release
Release -->|push| ReleaseCI
ReleaseCI -->|release| ReleaseDockerTag
ReleaseCI -->|release| MajorDockerTag
ReleaseCI -->|release| MinorDockerTag
ReleaseCI -->|release| StableDockerTag
ReleaseCI -->|release| LatestDockerTag
```
## Use the ci-tools to setup a new CI
There is a dedicated [documentation to start using the `ci-tools`
templates](docs/GETTING-STARTED.md) in your project.
## Contributing to this project
......
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [2, 'always', 120],
'footer-max-line-length': [2, 'always', 120],
'header-max-length': [2, 'always', 72],
},
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [2, 'always', 120],
'footer-max-line-length': [2, 'always', 120],
'header-max-length': [2, 'always', 72],
},
};
# Changelog
# [1.3.0](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/compare/release/1.2.1...release/1.3.0) (2022-01-11)
### Bug Fixes
* **semantic-release:** the branch must be `stable` ([4b9152d](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/4b9152dcae29a8cd792de452041d47da6bf6807c))
### Code Refactoring
* **commitlint:** the upstream extra repository is useless ([cdff4ab](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/cdff4abd8af608b8ab31398c0a6703a50eae0e08))
### Documentation
* **commitlint:** describe usage of the commitlint job ([8b3749f](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/8b3749f044227c390e15480c63f125c24e99767a))
* **getting-started:** quick setup and detailed explanations ([007aa21](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/007aa2195252d8140d8ecd4438f231a973aa30e9))
* **readme:** demonstrate a possible release cycle ([8d02a0c](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/8d02a0cf712cb590cfc3a65d7231a9157bcbbbb6))
### Features
* **commitlint:** users can configure image with `$COMMITLINT_IMAGE` ([bc7f19c](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/bc7f19c3be02a00e03a39ffe31b4fecbd5454964))
* **commitlint:** users can configure the base branch ([612dc3e](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/612dc3ea47080f3213cc6610ec321b4c57fa8e72))
* **docker:** .build-docker-image must accept kaniko arguments ([bd5c77e](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/bd5c77eabbc03fec73b9405ef392197a5029ae29))
* **semantic-release:** don't build changelog on prerelease branches ([5a02f5d](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/5a02f5d23aca195cb18f2e0d865eaf4c13b7351f))
* **semantic-release:** manage python projects releases ([9794bcb](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/9794bcb0b7d427af10e99a65723456953f575182))
### Styles
* **js:** js configuration files do not pass eslint ([5874dca](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/commit/5874dca35effe04f82ff848918706a15012dcf73))
## [1.2.1](https://gitlab.mim-libre.fr/EOLE/infra/ci-tools/compare/release/1.2.0...release/1.2.1) (2021-12-09)
......
This diff is collapsed.
......@@ -3,16 +3,16 @@
//
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
module.exports = [
{breaking: true, release: 'major'},
{ breaking: true, release: 'major' },
// {type: 'build', release: 'patch'},
// {type: 'chore', release: 'patch'},
// {type: 'ci', release: 'patch'},
{type: 'docs', release: 'patch'},
{type: 'feat', release: 'minor'},
{type: 'fix', release: 'patch'},
{type: 'perf', release: 'patch'},
{type: 'refactor', release: 'patch'},
{type: 'revert', release: 'patch'},
{type: 'style', release: 'patch'},
{type: 'test', release: 'patch'},
{ type: 'docs', release: 'patch' },
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
{ type: 'refactor', release: 'patch' },
{ type: 'revert', release: 'patch' },
{ type: 'style', release: 'patch' },
{ type: 'test', release: 'patch' },
];
module.exports = {
// Build the configuration depending of the environnement
// When using prerelease branches, we don't want changelog to be generated
// See https://github.com/semantic-release/changelog/issues/51#issuecomment-682609394
// Gitlab reference name
const branch = process.env.CI_COMMIT_REF_NAME;
const gitAssets = [];
const config = {
branches: 'stable',
/* eslint no-template-curly-in-string: "off" */
tagFormat: 'release/${version}',
plugins: [
['@semantic-release/commit-analyzer', {
[
'@semantic-release/commit-analyzer',
{
preset: 'angular',
releaseRules: './release-rules.js',
}],
'@semantic-release/release-notes-generator',
['@semantic-release/changelog', {
changelogFile: 'docs/CHANGELOG.md',
changelogTitle: '# Changelog',
}],
['@semantic-release/git', {
assets: ['docs'],
message: 'chore(release): ${nextRelease.version}\n\n${nextRelease.notes}'
}],
'@semantic-release/gitlab',
],
generateNotes: {
preset: 'angular',
writerOpts: {
// Required due to upstream bug preventing all types being displayed.
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
transform: (commit, context) => {
const issues = []
commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`
})
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
if (commit.type === `feat`) {
commit.type = `Features`
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`
} else if (commit.type === `revert`) {
commit.type = `Reverts`
} else if (commit.type === `docs`) {
commit.type = `Documentation`
} else if (commit.type === `style`) {
commit.type = `Styles`
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`
} else if (commit.type === `test`) {
commit.type = `Tests`
} else if (commit.type === `build`) {
commit.type = `Build System`
// } else if (commit.type === `chore`) {
// commit.type = `Maintenance`
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`
} else {
return
}
if (commit.scope === `*`) {
commit.scope = ``
}
if (typeof commit.hash === `string`) {
commit.shortHash = commit.hash.substring(0, 7)
}
if (typeof commit.subject === `string`) {
let url = context.repository
? `${context.host}/${context.owner}/${context.repository}`
: context.repoUrl
if (url) {
url = `${url}/issues/`
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue)
return `[#${issue}](${url}${issue})`
})
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`
}
return `[@${username}](${context.host}/${username})`
})
}
}
// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.issue) === -1) {
return true
}
return false
})
return commit
},
],
'@semantic-release/release-notes-generator',
],
};
if (
!Array.isArray(config.branches) ||
config.branches.some((it) => it === branch || (it.name === branch && !it.prerelease))
) {
// Generate changelog for release branch
config.plugins.push([
'@semantic-release/changelog',
{
changelogFile: 'docs/CHANGELOG.md',
changelogTitle: '# Changelog',
},
]);
gitAssets.push('docs/CHANGELOG.md');
}
// // We need to update package*.json
// // Make sure to modify pkgRoot and gitAssets lines for your needs
// config.plugins.push(
// [
// '@semantic-release/npm',
// {
// npmPublish: false,
// tarballDir: 'dist',
// pkgRoot: 'app',
// },
// ]
// );
// gitAssets.push('app/package*.json');
// // We need to update setup.py
// config.plugins.push(
// [
// 'semantic-release-pypi',
// {
// setupPy: 'setup.py',
// pypiPublish: false,
// },
// ]
// );
// gitAssets.push('setup.cfg');
// Commit changes and create release on Gitlab
config.plugins.push(
[
'@semantic-release/git',
{
assets: gitAssets,
message: 'chore(release): ${nextRelease.version}\n\n${nextRelease.notes}',
},
],
'@semantic-release/gitlab',
);
config.generateNotes = {
preset: 'angular',
writerOpts: {
// Required due to upstream bug preventing all types being displayed.
// Bug: https://github.com/conventional-changelog/conventional-changelog/issues/317
// Fix: https://github.com/conventional-changelog/conventional-changelog/pull/410
/* eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["commit", "note"] }] */
transform: (commit, context) => {
const issues = [];
commit.notes.forEach((note) => {
note.title = `BREAKING CHANGES`;
});
// NOTE: Any changes here must be reflected in `CONTRIBUTING.md`.
if (commit.type === `feat`) {
commit.type = `Features`;
} else if (commit.type === `fix`) {
commit.type = `Bug Fixes`;
} else if (commit.type === `perf`) {
commit.type = `Performance Improvements`;
} else if (commit.type === `revert`) {
commit.type = `Reverts`;
} else if (commit.type === `docs`) {
commit.type = `Documentation`;
} else if (commit.type === `style`) {
commit.type = `Styles`;
} else if (commit.type === `refactor`) {
commit.type = `Code Refactoring`;
} else if (commit.type === `test`) {
commit.type = `Tests`;
} else if (commit.type === `build`) {
commit.type = `Build System`;
// } else if (commit.type === `chore`) {
// commit.type = `Maintenance`
} else if (commit.type === `ci`) {
commit.type = `Continuous Integration`;
} else {
return null;
}
if (commit.scope === `*`) {
commit.scope = ``;
}
if (typeof commit.hash === `string`) {
commit.shortHash = commit.hash.substring(0, 7);
}
if (typeof commit.subject === `string`) {
let url = context.repository ? `${context.host}/${context.owner}/${context.repository}` : context.repoUrl;
if (url) {
url = `${url}/issues/`;
// Issue URLs.
commit.subject = commit.subject.replace(/#([0-9]+)/g, (_, issue) => {
issues.push(issue);
return `[#${issue}](${url}${issue})`;
});
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`;
}
return `[@${username}](${context.host}/${username})`;
});
}
}
// remove references that already appear in the subject
commit.references = commit.references.filter((reference) => {
if (issues.indexOf(reference.issue) === -1) {
return true;
}
return false;
});
return commit;
},
},
};
module.exports = config;
......@@ -29,6 +29,7 @@
# - to `Dockerfile.${IMAGE_NAME}` if the file exists
# - to `Dockerfile` if the file exists
# - `IMAGE_TAG`: defaults to `git-${CI_COMMIT_SHORT_SHA}`
# - `KANIKO_ARGS`: arguments to pass to kaniko executor command, empty by default
#
# USED CI VARIABLES
# =================
......@@ -44,6 +45,8 @@
image:
name: gcr.io/kaniko-project/executor:v1.7.0-debug
entrypoint: [""]
variables:
KANIKO_ARGS: ''
script:
- export IMAGE_NAME=${IMAGE_NAME:-${CI_JOB_NAME%-docker-build*}}
- test -f Dockerfile.${IMAGE_NAME} && export DOCKERFILE=${DOCKERFILE:-Dockerfile.${IMAGE_NAME}} || true
......@@ -51,7 +54,7 @@
- export IMAGE_TAG=${IMAGE_TAG:-git-${CI_COMMIT_SHORT_SHA}}
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(echo -n ${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD} | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context ${CI_PROJECT_DIR} --dockerfile $CI_PROJECT_DIR/${DOCKERFILE} --destination ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}
- /kaniko/executor ${KANIKO_ARGS} --context ${CI_PROJECT_DIR} --dockerfile $CI_PROJECT_DIR/${DOCKERFILE} --destination ${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}
# Define `.tag-docker-image` template used by `*-docker-tag` jobs
# It tag the `${IMAGE_NAME}:${SOURCE_TAG}` with the tag `${IMAGE_TAG}`
......
# -*- coding: utf-8 -*-
# vim: ft=yaml
#
# Verify formatting of all commit messages in the range
# `$BASE_BRANCH..$CI_COMMIT_SHA`.
#
# USAGE
# =====
#
# include:
# - project: EOLE/infra/ci-tools
# ref: stable
# file: /templates/Rules.yaml
# - project: EOLE/infra/ci-tools
# ref: stable
# file: /templates/Lint/Commitlint.yaml
#
# stages:
# - lint
#
# OPTIONAL VARIABLES
# ==================
#
# - `BASE_BRANCH`: name of the referrence branch, defaults to
# `${CI_DEFAULT_BRANCH}`
# - `COMMITLINT_IMAGE`: name of the `commitlint` docker image to use
#
# REQUIREMENTS
# ============
#
# - The `.not-on-stable` rules template
# - A `lint` stage must be present in your pipeline or it must be
# overriden by the extending job to feet your need.
#
# USED CI VARIABLES
# =================
#
# - `CI_COMMIT_SHA`
# - `CI_DEFAULT_BRANCH`
# - `CI_REPOSITORY_URL`
#
---
commitlint:
stage: lint
extends: .not-on-stable
image: 'hub.eole.education/eole/commitlint:latest'
before_script:
# Add `upstream` remote to get access to `upstream/master`
- "git remote show upstream 2> /dev/null || git remote add upstream ${CI_REPOSITORY_URL}"
- 'git fetch --all'
after_script:
# Remove `upstream` to avoid caching `CI_JOB_TOKEN`
- "git remote remove upstream"
image: "$COMMITLINT_IMAGE"
variables:
COMMITLINT_IMAGE: 'hub.eole.education/eole/commitlint:latest'
BASE_BRANCH: "${CI_DEFAULT_BRANCH}"
script:
- 'git fetch --all'
# Set default commit hashes for `--from` and `--to`
- 'export COMMITLINT_FROM="$(git merge-base upstream/${CI_DEFAULT_BRANCH} HEAD)"'
- 'export COMMITLINT_FROM="$(git merge-base origin/${BASE_BRANCH} HEAD)"'
- 'export COMMITLINT_TO="${CI_COMMIT_SHA}"'
# Run `commitlint`
- 'commitlint --from "${COMMITLINT_FROM}"
......