From 8a24d4872ee00ee332834d04c2c8b9d7b437f7b2 Mon Sep 17 00:00:00 2001 From: Prajwal S N Date: Sat, 1 Jul 2023 13:15:36 +0530 Subject: [PATCH] ci: add workflow to ensure self-contained commits Signed-off-by: Prajwal S N --- .github/workflows/check-commits.yml | 30 +++++++++++++++++++++++++++++ scripts/ci/Makefile | 8 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 .github/workflows/check-commits.yml diff --git a/.github/workflows/check-commits.yml b/.github/workflows/check-commits.yml new file mode 100644 index 000000000..be2fbd285 --- /dev/null +++ b/.github/workflows/check-commits.yml @@ -0,0 +1,30 @@ +name: Verify self-contained commits + +on: pull_request + +# Cancel any preceding run on the pull request +concurrency: + group: commit-test-${{ github.event.pull_request.number }} + +jobs: + build: + runs-on: ubuntu-latest + # Check if pull request does not have label "not-selfcontained-ok" + if: "!contains(github.event.pull_request.labels.*.name, 'not-selfcontained-ok')" + steps: + - uses: actions/checkout@v3 + with: + # Needed to rebase against the base branch + fetch-depth: 0 + # Checkout pull request HEAD commit instead of merge commit + ref: ${{ github.event.pull_request.head.sha }} + - name: Install dependencies + run: sudo apt-get install -y libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler protobuf-compiler python3-protobuf libnl-3-dev libnet-dev libcap-dev + - name: Configure git user details + run: | + git config --global user.email "checkpoint-restore@users.noreply.github.com" + git config --global user.name "checkpoint-restore" + - name: Configure base branch without switching current branch + run: git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} + - name: Build each commit + run: git rebase ${{ github.base_ref }} -x "make -C scripts/ci check-commit" diff --git a/scripts/ci/Makefile b/scripts/ci/Makefile index 30dd9ebeb..5c4579103 100644 --- a/scripts/ci/Makefile +++ b/scripts/ci/Makefile @@ -102,5 +102,13 @@ vagrant-fedora-non-root: setup-vagrant .PHONY: setup-vagrant vagrant-fedora-no-vdso vagrant-fedora-rawhide vagrant-fedora-non-root +check-commit: + ($(MAKE) -j $$(nproc) -C ../.. && \ + echo "Commit $$(git rev-parse --short HEAD) built successfully") || \ + (echo "Build failed for $$(git rev-list -n 1 --pretty HEAD)" && \ + exit 1) + +.PHONY: check-commit + %: $(MAKE) -C ../build $@$(target-suffix)