👷(circle) setup circle ci

Add circleci configuration. Add jobs and workflows.
This commit is contained in:
Nathan Vasse
2022-12-01 12:07:19 +01:00
committed by NathanVss
parent 77c2188bad
commit 72017cc5a4
3 changed files with 291 additions and 0 deletions

176
.circleci/config.yml Normal file
View File

@@ -0,0 +1,176 @@
version: 2.1
aliases:
- &checkout_cunningham
checkout:
path: ~/cunningham
- &restore_node_modules
restore_cache:
name: Restore node_modules cache
keys:
- v1-front-dependencies-{{ checksum "~/cunningham/yarn.lock" }}
jobs:
lint-git:
docker:
- image: cimg/python:3.11
working_directory: ~/cunningham
steps:
- checkout:
path: ~/cunningham
- run:
name: Check absence of fixup commits
command: |
! git log origin/main..HEAD | grep 'fixup!'
- run:
name: Install gitlint
command: |
pip install --user requests gitlint
- run:
name: lint commit messages added to main
command: |
~/.local/bin/gitlint --commits origin/main..HEAD
# Check that the CHANGELOG has been updated in the current branch
check-changelog:
docker:
- image: cimg/base:2022.11
working_directory: ~/cunningham
steps:
- checkout:
path: ~/cunningham
- run:
name: Check that the CHANGELOG has been modified in the current branch
command: |
git whatchanged --name-only --pretty="" origin..HEAD | grep CHANGELOG
# Check that the CHANGELOG max line length does not exceed 80 characters
lint-changelog:
docker:
- image: debian:stretch
working_directory: ~/cunningham
steps:
- checkout:
path: ~/cunningham
- run:
name: Check CHANGELOG max line length
command: |
# Get the longuest line width (ignoring release links)
test $(cat CHANGELOG.md | grep -Ev "^\[.*\]: https://github.com/openfun" | wc -L) -le 80
# Check that renovate configuration file is valid
check-renovate-configuration:
docker:
- image: renovate/renovate
auth:
username: $DOCKER_USER
password: $DOCKER_PASS
working_directory: ~/cunningham
steps:
- *checkout_cunningham
- run:
name: Run renovate-config-validator command
command: renovate-config-validator
# ---- Codebase -----
build:
docker:
- image: cimg/node:16.18
working_directory: ~/cunningham
steps:
- *checkout_cunningham
- *restore_node_modules
# If the yarn.lock file is not up-to-date with the package.json file,
# using the --frozen-lockfile should fail.
- run:
name: Install dependencies
command: yarn install --frozen-lockfile
- run:
name: Build packages
command: yarn build
- persist_to_workspace:
root: ~/cunningham
paths:
- apps/demo/dist
- packages/tokens/dist
- packages/react/dist
- save_cache:
paths:
- ./node_modules
- ./apps/demo/node_modules
- ./packages/eslint-config-custom/node_modules
- ./packages/react/node_modules
- ./packages/tokens/node_modules
key: v1-front-dependencies-{{ checksum "yarn.lock" }}
lint:
docker:
- image: cimg/node:16.18
working_directory: ~/cunningham
steps:
- *checkout_cunningham
- *restore_node_modules
- run:
name: Run linter over all workspaces
command: yarn lint
test:
docker:
- image: cimg/node:16.18
working_directory: ~/cunningham
steps:
- *checkout_cunningham
- *restore_node_modules
- run:
name: Run test suites over all workspaces
command: yarn test
workflows:
version: 2.1
cunningham:
jobs:
# Git jobs
#
# Check validity of git history
- lint-git:
filters:
tags:
only: /.*/
# Check CHANGELOG update
- check-changelog:
filters:
branches:
ignore: main
tags:
only: /(?!^v).*/
- lint-changelog:
filters:
branches:
ignore: main
tags:
only: /.*/
# Check Renovate
- check-renovate-configuration:
filters:
tags:
only: /.*/
# ---- Codebase ----
- build:
filters:
tags:
only: /.*/
- lint:
filters:
tags:
only: /.*/
requires:
- build
- test:
filters:
tags:
only: /.*/
requires:
- build
- lint

78
.gitlint Normal file
View File

@@ -0,0 +1,78 @@
# All these sections are optional, edit this file as you like.
[general]
# Ignore certain rules, you can reference them by their id or by their full name
# ignore=title-trailing-punctuation, T3
# verbosity should be a value between 1 and 3, the commandline -v flags take precedence over this
# verbosity = 2
# By default gitlint will ignore merge commits. Set to 'false' to disable.
# ignore-merge-commits=true
# By default gitlint will ignore fixup commits. Set to 'false' to disable.
# ignore-fixup-commits=true
# By default gitlint will ignore squash commits. Set to 'false' to disable.
# ignore-squash-commits=true
# Enable debug mode (prints more output). Disabled by default.
# debug=true
# Set the extra-path where gitlint will search for user defined rules
# See http://jorisroovers.github.io/gitlint/user_defined_rules for details
extra-path=gitlint/
# [title-max-length]
# line-length=80
[title-must-not-contain-word]
# Comma-separated list of words that should not occur in the title. Matching is case
# insensitive. It's fine if the keyword occurs as part of a larger word (so "WIPING"
# will not cause a violation, but "WIP: my title" will.
words=wip
#[title-match-regex]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit-msg title must be matched to.
# Note that the regex can contradict with other rules if not used correctly
# (e.g. title-must-not-contain-word).
#regex=
# [B1]
# B1 = body-max-line-length
# line-length=120
# [body-min-length]
# min-length=5
# [body-is-missing]
# Whether to ignore this rule on merge commits (which typically only have a title)
# default = True
# ignore-merge-commits=false
# [body-changed-file-mention]
# List of files that need to be explicitly mentioned in the body when they are changed
# This is useful for when developers often erroneously edit certain files or git submodules.
# By specifying this rule, developers can only change the file when they explicitly reference
# it in the commit message.
# files=gitlint/rules.py,README.md
# [author-valid-email]
# python like regex (https://docs.python.org/2/library/re.html) that the
# commit author email address should be matched to
# For example, use the following regex if you only want to allow email addresses from foo.com
# regex=[^@]+@foo.com
[ignore-by-title]
# Allow empty body & wrong title pattern only when bots (pyup/greenkeeper)
# upgrade dependencies
regex=^(⬆️.*|Update (.*) from (.*) to (.*)|(chore|fix)\(package\): update .*)$
ignore=B6,UC1
# [ignore-by-body]
# Ignore certain rules for commits of which the body has a line that matches a regex
# E.g. Match bodies that have a line that that contain "release"
# regex=(.*)release(.*)
#
# Ignore certain rules, you can reference them by their id or by their full name
# Use 'all' to ignore all rules
# ignore=T1,body-min-length

37
gitlint/gitlint_emoji.py Normal file
View File

@@ -0,0 +1,37 @@
"""
Gitlint extra rule to validate that the message title is of the form
"<gitmoji>(<scope>) <subject>"
"""
from __future__ import unicode_literals
import re
import requests
from gitlint.rules import CommitMessageTitle, LineRule, RuleViolation
class GitmojiTitle(LineRule):
"""
This rule will enforce that each commit title is of the form "<gitmoji>(<scope>) <subject>"
where gitmoji is an emoji from the list defined in https://gitmoji.carloscuesta.me and
subject should be all lowercase
"""
id = "UC1"
name = "title-should-have-gitmoji-and-scope"
target = CommitMessageTitle
def validate(self, title, _commit):
"""
Download the list possible gitmojis from the project's github repository and check that
title contains one of them.
"""
gitmojis = requests.get(
"https://raw.githubusercontent.com/carloscuesta/gitmoji/master/src/data/gitmojis.json"
).json()["gitmojis"]
emojis = [item["emoji"] for item in gitmojis]
pattern = r"^({:s})\(.*\)\s[a-z].*$".format("|".join(emojis))
if not re.search(pattern, title):
violation_msg = 'Title does not match regex "<gitmoji>(<scope>) <subject>"'
return [RuleViolation(self.id, violation_msg, title)]