From 73235c6160a278602439a1627003bd204a8d95d8 Mon Sep 17 00:00:00 2001 From: ramin Date: Fri, 9 Aug 2024 12:16:02 +0100 Subject: [PATCH] misc(ci): detect breaking change to any .proto files or config fields in nodebuilder/**/config.go and add kind:break! (#3568) --- .github/workflows/labels.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 26 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml index b9d4351bbd..9f531e0d61 100644 --- a/.github/workflows/labels.yml +++ b/.github/workflows/labels.yml @@ -17,3 +17,33 @@ jobs: mode: minimum count: 1 labels: "kind:fix, kind:misc, kind:break!, kind:refactor, kind:feat, kind:deps, kind:docs, kind:ci, kind:chore, kind:testing" # yamllint disable-line rule:line-length + + # will attempt to apply a breaking label + # on opening the PR but not enforce it on repeated changes + # so we don't get trapped by false positives (for now) + # we can expand to all cases after + apply-breaking: + runs-on: ubuntu-latest + if: ${{ github.event.action == 'opened' && github.actor != 'dependabot[bot]' }} + permissions: + pull-requests: write + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Run check for breaking + id: breaking_change + run: | + git fetch origin main + make detect-breaking + + - name: Add label if breaking changes detected + if: failure() + run: gh issue edit "$NUMBER" --add-label "$LABELS" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + NUMBER: ${{ github.event.pull_request.number }} + LABELS: kind:break! diff --git a/Makefile b/Makefile index ceb4f3e244..dc4b06392b 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,32 @@ goreleaser-release: goreleaser release --clean --fail-fast --skip-publish .PHONY: goreleaser-release +# detect changed files and parse output +# to inspect changes to nodebuilder/**/config.go fields +CHANGED_FILES = $(shell git diff --name-only origin/main...HEAD) +detect-breaking: + @BREAK=false + @for file in ${CHANGED_FILES}; do \ + if echo $$file | grep -qE '\.proto$$'; then \ + BREAK=true; \ + fi; \ + if echo $$file | grep -qE 'nodebuilder/.*/config\.go'; then \ + DIFF_OUTPUT=$$(git diff origin/main...HEAD $$file); \ + if echo "$$DIFF_OUTPUT" | grep -qE 'type Config struct|^\s+\w+\s+Config'; then \ + BREAK=true; \ + fi; \ + fi; \ + done; \ + if [ "$$BREAK" = true ]; then \ + echo "break detected"; \ + exit 1; \ + else \ + echo "no break detected"; \ + exit 0; \ + fi +.PHONY: detect-breaking + + # Copied from https://github.com/dgraph-io/badger/blob/main/Makefile USER_ID = $(shell id -u) HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc")