Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: go version unification #88

Merged
merged 9 commits into from
Feb 11, 2025
7 changes: 5 additions & 2 deletions .github/workflows/build-and-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- name: Get Go version from go.mod
id: get_go_version
run: |
go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//')
- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.23.2'
go-version: ${{ steps.get_go_version.outputs.go_version }}
- name: Install Dependencies
run: |
sudo apt update
Expand Down Expand Up @@ -82,4 +86,3 @@ jobs:

- name: Push Docker image to Docker Hub
run: IMAGE_NAME="ghcr.io/alegrey91/harpoon" make push-docker

8 changes: 6 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4
- name: Get Go version from go.mod
id: get_go_version
run: |
go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//')
- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.21.7'
go-version: ${{ steps.get_go_version.outputs.go_version }}
- name: Install BCC Dependencies
run: |
sudo apt update
sudo apt install -y libbpf-dev # Install libbpf dependencies
sudo apt install -y libseccomp-dev # Install Seccomp dependencies
- name: Build and Test
run: |-
make build-gh
make build-gh
23 changes: 17 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4

- name: Get Go version from go.mod
id: get_go_version
run: |
go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//')
ccoVeille marked this conversation as resolved.
Show resolved Hide resolved
- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.21'
go-version: ${{ steps.get_go_version.outputs.go_version }}

- name: Install Dependencies
run: |
Expand Down Expand Up @@ -52,11 +55,15 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # ratchet:actions/checkout@v4

- name: Get Go version from go.mod
id: get_go_version
run: |
go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//')

- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.21'
go-version: ${{ steps.get_go_version.outputs.go_version }}

- name: Install Dependencies
run: |
Expand Down Expand Up @@ -110,10 +117,15 @@ jobs:

ls -lah /tmp/unit-test
ls -lah /tmp/integration-test
- name: Get Go version from go.mod
id: get_go_version
run: |
go_version=$(grep '^toolchain' go.mod | awk '{print $2}' | sed 's/go//')

- name: Set up Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # ratchet:actions/setup-go@v5
with:
go-version: '1.21'
go-version: ${{ steps.get_go_version.outputs.go_version }}

- name: Calculate total coverage
run: |
Expand Down Expand Up @@ -144,6 +156,5 @@ jobs:






2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ COPY --from=builder /workspace/bin/harpoon .
# --pid=host \
# -v /sys/kernel/debug/:/sys/kernel/debug:rw \
# harpoon:latest
ENTRYPOINT ["/bin/bash"]
ENTRYPOINT ["/bin/bash"]
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ BINARY_NAME=harpoon
BINARY_DIR=./bin
OUTPUT_DIR=./output
IMAGE_NAME?=alegrey91/harpoon
GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//')


build-static-libbpfgo:
git clone https://github.com/aquasecurity/libbpfgo.git && \
Expand Down Expand Up @@ -68,18 +70,21 @@ endif
-o ${BINARY_DIR}/${BINARY_NAME} \
.

build-docker:
build-docker: build
ifdef GITHUB_REF_NAME
docker build \
--no-cache \
-t ${IMAGE_NAME}:latest \
-t ${IMAGE_NAME}:${GITHUB_REF_NAME} \
--build-arg GO_VERSION=$(GO_VERSION) \
-t $(IMAGE_NAME):latest \
-t $(IMAGE_NAME):$(GITHUB_REF_NAME) \
.
endif
else
docker build \
--no-cache \
-t ${IMAGE_NAME}:latest \
--build-arg GO_VERSION=$(GO_VERSION) \
-t $(IMAGE_NAME):latest \
.
endif

push-docker:
ifdef GITHUB_REF_NAME
Expand All @@ -99,4 +104,4 @@ install:
clean:
rm -rf ${OUTPUT_DIR}
rm -rf ${BINARY_DIR}
rm -rf ./libbpfgo
rm -rf ./libbpfgo
7 changes: 5 additions & 2 deletions tests/testcases/example-app/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Optionally extract the Go version from go.mod (if a toolchain line exists)
GO_VERSION := $(shell grep '^toolchain' go.mod | awk '{print $$2}' | sed 's/go//')

BINARY_NAME=example-app
BINARY_DIR=bin
UNIT_TEST_DIR=/tmp/unit
Expand All @@ -21,8 +24,8 @@ run:

test: unit-test

# here we are compiling the _test package(s) we want to test,
# so we are able to run manually unsing the `strace` utility.
# Here we are compiling the _test package(s) we want to test,
# so we are able to run manually using the `strace` utility.
unit-test:
rm -rf ${UNIT_TEST_DIR}
mkdir ${UNIT_TEST_DIR}
Expand Down
3 changes: 2 additions & 1 deletion tests/testcases/example-app/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/alegrey91/seccomp-test-coverage

go 1.20
go 1.23
toolchain go1.23.2

require github.com/spf13/cobra v1.7.0

Expand Down