From 72017cc5a482c0f95ee7d0aa70e389a02a06d3c7 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Thu, 1 Dec 2022 12:07:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7(circle)=20setup=20circle=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add circleci configuration. Add jobs and workflows. --- .circleci/config.yml | 176 +++++++++++++++++++++++++++++++++++++++ .gitlint | 78 +++++++++++++++++ gitlint/gitlint_emoji.py | 37 ++++++++ 3 files changed, 291 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .gitlint create mode 100644 gitlint/gitlint_emoji.py diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..fd17544 --- /dev/null +++ b/.circleci/config.yml @@ -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 diff --git a/.gitlint b/.gitlint new file mode 100644 index 0000000..f7373b6 --- /dev/null +++ b/.gitlint @@ -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 diff --git a/gitlint/gitlint_emoji.py b/gitlint/gitlint_emoji.py new file mode 100644 index 0000000..89b5702 --- /dev/null +++ b/gitlint/gitlint_emoji.py @@ -0,0 +1,37 @@ +""" +Gitlint extra rule to validate that the message title is of the form +"() " +""" +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 "() " + 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 "() "' + return [RuleViolation(self.id, violation_msg, title)]