diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 000000000..3c186a80e --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,56 @@ +name: Codecov + +on: [push, pull_request] + +jobs: + build: + if: ${{ github.repository == 'checkpoint-restore/go-criu' }} + runs-on: ubuntu-latest + name: Code coverage + steps: + + - name: Checkout + uses: actions/checkout@v4 + with: + # needed for codecov + fetch-depth: 0 + + - name: Build CRIU criu-dev + 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 curl unzip + git clone --depth=1 --single-branch -b criu-dev https://github.com/checkpoint-restore/criu.git + make -j"$(nproc)" -C criu + sudo make -C criu install-criu PREFIX=/usr + + - name: Install Go 1.22.x + uses: actions/setup-go@v5 + with: + go-version: 1.22.x + + - name: Install protoc-gen-go + run: sudo env "GOBIN=/usr/bin" go install google.golang.org/protobuf/cmd/protoc-gen-go@latest + + - name: Run tests and collect coverage + run: | + sudo -E make test + sudo -E make -C scripts/magic-gen test + # First update protobuf. It is too old in the Ubuntu image. + curl -Lo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v23.4/protoc-23.4-linux-x86_64.zip + sudo unzip -o protoc.zip -d /usr + # We need to use the protobuf definitions from the criu-dev + # branch as it might have changed. + sudo -E make -C scripts/proto-gen proto-update GIT_BRANCH=criu-dev + sudo -E make -C scripts/proto-gen + sudo -E make -C crit clean bin/crit + sudo -E make -C crit unit-test + sudo -E make -C test crit-test + # Run actual test as root as it uses CRIU. + sudo -E make coverage + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + with: + fail_ci_if_error: true + file: test/.coverage/coverage.out + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 70a5bca1e..705633451 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,9 +20,6 @@ jobs: - name: Checkout uses: actions/checkout@v4 - with: - # needed for codecov - fetch-depth: 0 - name: Build CRIU ${{ matrix.criu_branch }} run: | @@ -62,11 +59,3 @@ jobs: fi sudo -E make -C crit unit-test sudo -E make -C test crit-test - - - name: Check code coverage - if: matrix.go-version == '1.20.x' && matrix.criu_branch == 'criu-dev' - run: | - # Run actual test as root as it uses CRIU. - sudo -E make coverage - # Upload coverage results to codecov - sudo -E make codecov diff --git a/Makefile b/Makefile index 6aacde06e..12e064237 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,6 @@ test: build coverage: $(MAKE) -C test coverage -codecov: - $(MAKE) -C test codecov - rpc/rpc.proto: curl -sSL https://raw.githubusercontent.com/checkpoint-restore/criu/master/images/rpc.proto -o $@ @@ -42,4 +39,4 @@ clean: $(MAKE) -C crit/ clean $(MAKE) -C test/ clean -.PHONY: build test lint vendor coverage codecov clean +.PHONY: build test lint vendor coverage clean diff --git a/test/Makefile b/test/Makefile index 8d1d122a6..ea23c6bb3 100644 --- a/test/Makefile +++ b/test/Makefile @@ -12,12 +12,6 @@ TEST_PAYLOAD := piggie/piggie TEST_BINARIES := test $(TEST_PAYLOAD) phaul/phaul COVERAGE_BINARIES := test.coverage phaul/phaul.coverage crit/crit-test.coverage -GO_MAJOR_VER = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) -GO_MINOR_VER = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) -MIN_GO_MAJOR_VER = 1 -MIN_GO_MINOR_VER = 20 -GO_VALIDATION_ERR = Go version is not supported. Please update to at least $(MIN_GO_MAJOR_VER).$(MIN_GO_MINOR_VER) - all: $(TEST_BINARIES) phaul-test mkdir -p image PID=$$(piggie/piggie) && \ @@ -26,17 +20,6 @@ all: $(TEST_BINARIES) phaul-test ./test restore image rm -rf image -check-go-version: - @if [ $(GO_MAJOR_VER) -gt $(MIN_GO_MAJOR_VER) ]; then \ - exit 0 ;\ - elif [ $(GO_MAJOR_VER) -lt $(MIN_GO_MAJOR_VER) ]; then \ - echo '$(GO_VALIDATION_ERR)';\ - exit 1; \ - elif [ $(GO_MINOR_VER) -lt $(MIN_GO_MINOR_VER) ] ; then \ - echo '$(GO_VALIDATION_ERR)';\ - exit 1; \ - fi - piggie/piggie: piggie/piggie.c $(CC) $^ -o $@ @@ -55,17 +38,17 @@ phaul-test: $(TEST_BINARIES) crit-test: $(MAKE) -C crit -test.coverage: check-go-version *.go +test.coverage: *.go $(GO) build \ -cover \ -o $@ main.go -phaul/phaul.coverage: check-go-version phaul/*.go +phaul/phaul.coverage: phaul/*.go $(GO) build \ -cover \ -o $@ phaul/main.go -crit/crit-test.coverage: check-go-version crit/*.go +crit/crit-test.coverage: crit/*.go # Re-build the crit binary, so that test coverage # works even if we run `make test` before that. $(MAKE) -C ../crit clean @@ -75,7 +58,7 @@ crit/crit-test.coverage: check-go-version crit/*.go -cover \ -o $@ crit/main.go -coverage: check-go-version $(COVERAGE_BINARIES) $(TEST_PAYLOAD) +coverage: $(COVERAGE_BINARIES) $(TEST_PAYLOAD) mkdir -p $(COVERAGE_PATH) mkdir -p image PID=$$(piggie/piggie) && \ @@ -103,16 +86,11 @@ coverage: check-go-version $(COVERAGE_BINARIES) $(TEST_PAYLOAD) # We do not want to upload coverage for autogenerated files (*.pb.go) sed -i '/\.pb\.go/d' ${COVERAGE_PATH}/coverage.out -codecov: - curl -Os https://uploader.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov -f "$(COVERAGE_PATH)/coverage.out" - clean: - @rm -f $(TEST_BINARIES) $(COVERAGE_BINARIES) codecov + @rm -f $(TEST_BINARIES) $(COVERAGE_BINARIES) @rm -rf image $(COVERAGE_PATH) @make -C crit/ clean @make -C loop/ clean @make -C mmapper/ clean -.PHONY: all clean coverage codecov crit-test phaul-test check-go-version +.PHONY: all clean coverage crit-test phaul-test