Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(ci): add script to validate each commit in PR #1955

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci-validate-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Validate Commits

on:
pull_request:
branches: [main]

jobs:
validate-commits:
name: Check if KubeArmor compiles for every commit
runs-on: ubuntu-20.04
timeout-minutes: 60
steps:
- name: Configure git
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "github-actions@users.noreply.github.com"

- name: Install Go
uses: actions/setup-go@v3
with:
go-version-file: 'KubeArmor/go.mod'

- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Validate each commit
run: |
# Loop through each commit in the PR from oldest to newest
for commit in $(git rev-list --reverse ${{ github.event.pull_request.base.sha }}..${{ github.sha }}); do
echo "========================================="
echo "Checking out commit $commit..."
git checkout $commit

# Attempt to build the project
cd KubeArmor
echo "Building KubeArmor for commit $commit..."
if make build; then
echo "✅ Commit $commit compiled successfully."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also recommend showing the error in the logs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub Actions captures all logs from make build, do we need to add manual logs?
for example, here's the log from GH action when i was testing manually:

Error: ./main.go:40:68: syntax error: unexpected newline in argument list; possibly missing comma or )
Error: ./main.go:41:4: syntax error: unexpected return at end of statement
make: *** [Makefile:26: build] Error 1
❌ Commit e52b12d577936188e5b7aea2c9ddb30fb6b60b17 failed to compile!
=========================================
Error: Process completed with exit code 1.

else
echo "❌ Commit $commit failed to compile!"
echo "========================================="
exit 1
fi
cd -
echo "========================================="
done