build(circleci): Run pre-commit within CircleCI (#890)

* Add CircleCI job to run pre-commit on every commit
  * Install pre-commit on cimg/python:node image
  * caches installed packages and pre-commit hooks
* build(circleci): validate circleci configurations via yarn
This commit is contained in:
Iain Sproat
2022-08-05 10:51:31 +01:00
committed by GitHub
parent 39ff677e10
commit 9c2959cf19
2 changed files with 47 additions and 0 deletions
+46
View File
@@ -10,6 +10,7 @@ workflows:
tags:
# run tests for all tags
only: /.*/
- get-version:
filters: &filters-build
tags:
@@ -18,6 +19,12 @@ workflows:
only:
- main
- pre-commit:
cache_prefix: '7'
filters:
tags:
only: /.*/
- docker-build-and-publish-server:
filters: *filters-build
context: &docker-hub-context
@@ -111,6 +118,45 @@ jobs:
paths:
- env-vars
pre-commit:
parameters:
config_file:
default: ./.pre-commit-config.yaml
description: Optional, path to pre-commit config file.
type: string
cache_prefix:
default: ''
description: |
Optional cache prefix to be used on CircleCI. Can be used for cache busting or to ensure multiple jobs use different caches.
type: string
docker:
- image: cimg/python:3.10.6-node
resource_class: large
working_directory: *work-dir
steps:
- checkout
- restore_cache:
keys:
- cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
- run:
name: Install pre-commit
command: pre-commit --version || pip install --progress-bar=off pre-commit
- run:
name: Install pre-commit hooks
command: pre-commit install-hooks --config <<parameters.config_file>>
- save_cache:
key: cache-pre-commit-<<parameters.cache_prefix>>-{{ checksum "<<parameters.config_file>>" }}
paths:
- ~/.cache/pip
- ~/.cache/pre-commit
- run:
name: Run pre-commit
command: pre-commit run --all-files --config <<parameters.config_file>>
- run:
command: git --no-pager diff
name: git diff
when: on_fail
test-server:
docker:
- image: cimg/node:16.15
+1
View File
@@ -14,6 +14,7 @@
"lint": "eslint . --ext .js,.ts,.vue --max-warnings=0",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"circleci:check": "circleci config validate ./.circleci/config.yml",
"dev:docker:up": "docker-compose -f ./docker-compose-deps.yml -f ./docker-compose-dev.yml up -d",
"dev:docker:down": "docker-compose -f ./docker-compose-deps.yml -f ./docker-compose-dev.yml down",
"dev": "yarn workspaces foreach -piv -j unlimited run dev",