Skip to content

Commit

Permalink
ci: set up pre-commit (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunet authored Aug 10, 2022
1 parent ca3923a commit a796676
Show file tree
Hide file tree
Showing 20 changed files with 201 additions and 237 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab

[*.{js,json,ts,tsx,yaml}]
indent_style = space
indent_size = 2

[*.sh]
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
go-version-file: .go-version
check-latest: true

- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
with:
name: parca-dist-container
path: dist
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: pre-commit

on:
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true

env:
# renovate: datasource=pypi depName=pre-commit versioning=pep440
PRE_COMMIT_VERSION: 2.20.0

jobs:
pre-commit:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # tag=v3.0.2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a # tag=v3.2.1
with:
go-version-file: .go-version

- name: Set up pre-commit
run: pipx install "pre-commit==${PRE_COMMIT_VERSION}"

- name: Set PY_HASH
run: echo "PY_HASH=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

- name: Set up pre-commit cache
uses: actions/cache@0865c47f36e68161719c5b124609996bb5c40129 # tag=v3.0.5
with:
path: ~/.cache/pre-commit
key: pre-commit-${{ env.PY_HASH }}-${{ hashFiles('.pre-commit-config.yaml') }}

- name: Run pre-commit
run: |
declare -a EXTRA_ARGS=()
if [[ "${GITHUB_EVENT_NAME}" == 'pull_request' ]]; then
EXTRA_ARGS=(--from-ref "origin/${GITHUB_BASE_REF}" --to-ref "${GITHUB_SHA}")
fi
pre-commit run --show-diff-on-failure --color=always "${EXTRA_ARGS[@]}"
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
go-version-file: .go-version
check-latest: true

- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
with:
name: parca-dist-release
path: dist
Expand Down Expand Up @@ -192,7 +192,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
with:
name: parca-dist-release
path: dist
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/snap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
with:
name: parca-dist-release
path: dist
Expand Down Expand Up @@ -184,7 +184,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3
- uses: actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
with:
name: parca-dist-release
path: dist
Expand Down
65 changes: 65 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
exclude: ^ui/packages/shared/client/
- id: trailing-whitespace
exclude: ^ui/packages/shared/client/
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.3.0
hooks:
- id: insert-license
name: Insert license in comments (Go)
args:
- --license-filepath=scripts/LICENSE.txt
- --comment-style=//
- --fuzzy-match-generates-todo
exclude: \.pb(?:\.gw)?\.go$
types: [go]
- id: insert-license
name: Insert license in comments (Shell)
args:
- --license-filepath=scripts/LICENSE.txt
- --comment-style=#
- --fuzzy-match-generates-todo
types: [shell]
- repo: https://github.com/bufbuild/buf
rev: v1.7.0
hooks:
- id: buf-lint
- id: buf-format
- id: buf-breaking
args:
- --against=https://github.com/parca-dev/parca.git#branch=main,ref=HEAD~1,subdir=proto
- repo: https://github.com/golangci/golangci-lint
rev: v1.48.0
hooks:
- id: golangci-lint
- repo: https://github.com/hadolint/hadolint
rev: v2.10.0
hooks:
- id: hadolint-docker
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.8.0
hooks:
- id: shellcheck
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.5.1-1
hooks:
- id: shfmt
# Google-style w/ 4-space indent
args:
- --write
- --indent=4
- --case-indent
- --binary-next-line
- repo: https://github.com/google/go-jsonnet
rev: v0.18.0
hooks:
- id: jsonnet-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
files: \.(?:[jt]sx?|md|html|s?css)$
2 changes: 1 addition & 1 deletion ui/.prettierignore → .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ out/
coverage/

# Exclude protobuf generated files
packages/shared/client
ui/packages/shared/client
File renamed without changes.
2 changes: 1 addition & 1 deletion env-jsonnet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#!/usr/bin/env bash
set -euo pipefail

# renovate: datasource=go depName=github.com/brancz/gojsontoyaml
Expand Down
2 changes: 1 addition & 1 deletion env-proto.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#!/usr/bin/env bash
set -euo pipefail

BIN_DIR=${BIN_DIR:-/usr/local/bin}
Expand Down
2 changes: 1 addition & 1 deletion env.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env bash
#!/usr/bin/env bash
set -euo pipefail

# renovate: datasource=go depName=github.com/campoy/embedmd
Expand Down
1 change: 1 addition & 0 deletions pkg/prober/grpc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP LICENSE INSERTION
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

Expand Down
1 change: 1 addition & 0 deletions pkg/prober/prober.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SKIP LICENSE INSERTION
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

Expand Down
5 changes: 5 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
"description": "Group grpc-health-probe packages",
"matchSourceUrls": ["https://github.com/grpc-ecosystem/grpc-health-probe"],
"groupName": "grpc-health-probe"
},
{
"description": "Group prettier packages",
"matchPackageNames": ["pre-commit/mirrors-prettier", "prettier"],
"groupName": "prettier"
}
],
"regexManagers": [
Expand Down
12 changes: 12 additions & 0 deletions scripts/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Copyright 2022 The Parca Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
15 changes: 15 additions & 0 deletions snap/hooks/configure
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/usr/bin/env bash

# Copyright 2022 The Parca Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

# On Fedora $SNAP is under /var and there is some magic to map it to /snap.
# We need to handle that case and reset $SNAP
SNAP="${SNAP//\/var\/lib\/snapd/}"
Expand Down
15 changes: 15 additions & 0 deletions snap/parca-wrapper
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
#!/usr/bin/env bash

# Copyright 2022 The Parca Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -euo pipefail

# Run the configure hook which sets defaults for any config options
"${SNAP}"/snap/hooks/configure

Expand Down
4 changes: 0 additions & 4 deletions ui/.husky/pre-commit

This file was deleted.

7 changes: 0 additions & 7 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"fix": "eslint --fix --ext .ts,.tsx,.js packages/*",
"test": "jest --coverage --config jest.config.js",
"export": "rm -rf .next && next build && next export -o dist",
"prepare": "cd .. && husky install ui/.husky",
"pre-commit": "lint-staged",
"bootstrap": "lerna bootstrap",
"publish:ci": "lerna publish --yes --no-verify-access"
},
Expand Down Expand Up @@ -67,12 +65,10 @@
"eslint-plugin-standard": "5.0.0",
"fs-extra": "10.1.0",
"globby": "13.1.2",
"husky": "8.0.1",
"identity-obj-proxy": "3.0.0",
"internal-ip": "7.0.0",
"jest": "27.5.1",
"lerna": "5.3.0",
"lint-staged": "13.0.3",
"local-web-server": "5.2.1",
"next-transpile-modules": "9.0.0",
"plop": "3.1.1",
Expand All @@ -91,8 +87,5 @@
"ts-node": "10.9.1",
"typescript": "4.7.4",
"webpack": "5.74.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx,md,html,css,scss}": "prettier --write"
}
}
Loading

0 comments on commit a796676

Please sign in to comment.