Skip to content

Commit

Permalink
IDX-2719 - Move buf breaking from pre-commit to Bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
Enzo Desiage committed Apr 18, 2023
1 parent 51d5e4f commit 301eac0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ repos:
- repo: https://gitlab.com/dfinity-lab/open/pre-commit-tools.git
rev: 17101bf5cebeda988b13764909a6140badc5ef03
hooks:
- id: buf-checks
args: ["--config=buf.yaml"]
exclude: |
(?x)(
)
- id: nixpkgs-fmt
exclude: |
(?x)^(
Expand Down
22 changes: 22 additions & 0 deletions pre-commit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ sh_test(
],
)

sh_test(
name = "buf-breaking",
size = "small",
srcs = ["buf-breaking.sh"],
data = [
"//:WORKSPACE.bazel",
"//:buf.yaml",
"@buf",
],
env = {
# Hack to escape the sandbox and grep on the actual repository
"WORKSPACE": "$(rootpath //:WORKSPACE.bazel)",
"buf_path": "$(rootpath @buf//:buf)",
"buf_config": "$(rootpath //:buf.yaml)",
},
tags = [
"external", # force test to be unconditionally executed.
"local", # precludes the action or test from being remotely cached, remotely executed, or run inside the sandbox.
"smoke", # it should be run before committing code changes into the version control system.
],
)

sh_test(
name = "shellcheck",
size = "small",
Expand Down
22 changes: 22 additions & 0 deletions pre-commit/buf-breaking.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -euxo pipefail

BUF="$(readlink "$buf_path")"
CONF="$(readlink "$buf_config")"
REPO_PATH="$(dirname "$(readlink "$WORKSPACE")")"
cd "$REPO_PATH"

if [[ -n "$(git rev-parse -q --verify MERGE_HEAD)" ]]; then
echo "Currently merging, skipping buf checks"
exit 0
fi

if [[ "${CI:-}" == "true" ]]; then
echo "Fetch the master branch"
git fetch origin master:master
fi

MERGE_BASE="$(git merge-base HEAD master)"

"$BUF" breaking --against ".git#ref=$MERGE_BASE" --config="$CONF" .

0 comments on commit 301eac0

Please sign in to comment.