Skip to content
Snippets Groups Projects
Commit 12ee296d authored by Daniel Dehennin's avatar Daniel Dehennin
Browse files

Merge branch 'testing' into 'stable'

Publish a new release

See merge request !25
parents f7e749e8 a2b2177c
No related branches found
No related tags found
No related merge requests found
......@@ -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],
},
};
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 = {
branches: 'stable',
// 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: 'master',
/* 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}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment