From afce6447e908da5288bdf1298bede9688ff5830f Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 18 Feb 2025 13:36:02 +0100 Subject: [PATCH] .github/workflows: add a build and test workflows This commit introduces a new GitHub Actions workflow for building and testing the Go project. The workflow includes jobs for building the Go binary, running unit tests with verbose and race conditions, verifying generated code, and checking multi-architecture builds. Additionally, the e2e-matrix workflow is updated to trigger on ~workflow_call~ instead of ~pull_request~. The Makefile is also updated to include a new target for running unit tests with both verbose and race conditions. Signed-off-by: Vincent Demeester --- .github/workflows/build-and-test.yaml | 83 +++++++++++++++++++++++++++ .github/workflows/e2e-matrix.yml | 3 +- Makefile | 7 ++- 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/build-and-test.yaml diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 00000000000..54ed6743cf4 --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,83 @@ +name: Build and Tests + +on: [ pull_request ] + +defaults: + run: + shell: bash + +jobs: + build: + name: build go binary + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go 1.22 + uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + - name: build + run: | + go build ./... + tests: + needs: [ build ] + name: test go + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go 1.22 + uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + - name: build + run: | + make test-unit-verbose-and-race + generated: + needs: [ build ] + name: check if generated code is up-to-date + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go 1.22 + uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + - name: generated + run: | + ./hack/verify-codegen.sh + multi-arch-build: + needs: [ build ] + name: check if multi-arch build works + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up Go 1.22 + uses: actions/setup-go@v5 + with: + go-version: 1.22.5 + - uses: ko-build/setup-ko@v0.8 + - name: ko-resolve + run: | + cat < .ko.yaml + defaultBaseImage: cgr.dev/chainguard/static + baseImageOverrides: + # Use the combined base image for images that should include Windows support. + # NOTE: Make sure this list of images to use the combined base image is in sync with what's in tekton/publish.yaml's 'create-ko-yaml' Task. + github.com/tektoncd/pipeline/cmd/entrypoint: ghcr.io/tektoncd/pipeline/github.com/tektoncd/pipeline/combined-base-image:latest + github.com/tektoncd/pipeline/cmd/nop: ghcr.io/tektoncd/pipeline/github.com/tektoncd/pipeline/combined-base-image:latest + github.com/tektoncd/pipeline/cmd/workingdirinit: ghcr.io/tektoncd/pipeline/github.com/tektoncd/pipeline/combined-base-image:latest + + github.com/tektoncd/pipeline/cmd/git-init: cgr.dev/chainguard/git + EOF + + KO_DOCKER_REPO=example.com ko resolve -l 'app.kubernetes.io/component!=resolvers' --platform=all --push=false -R -f config 1>/dev/null + KO_DOCKER_REPO=example.com ko resolve --platform=all --push=false -f config/resolvers 1>/dev/null + e2e-tests: + needs: + - build + - tests + uses: ./.github/workflows/e2e-matrix.yml diff --git a/.github/workflows/e2e-matrix.yml b/.github/workflows/e2e-matrix.yml index 06d6d759500..b9a5e50eeed 100644 --- a/.github/workflows/e2e-matrix.yml +++ b/.github/workflows/e2e-matrix.yml @@ -1,7 +1,8 @@ name: Tekton Integration # Adapted from https://github.com/mattmoor/mink/blob/master/.github/workflows/minkind.yaml -on: [ pull_request ] +# on: [ pull_request ] +on: [workflow_call] defaults: run: diff --git a/Makefile b/Makefile index 4810773aa6c..a3778fc04bc 100644 --- a/Makefile +++ b/Makefile @@ -84,9 +84,10 @@ vendor: $Q ./hack/update-deps.sh ## Tests -TEST_UNIT_TARGETS := test-unit-verbose test-unit-race -test-unit-verbose: ARGS=-v -test-unit-race: ARGS=-race +TEST_UNIT_TARGETS := test-unit-verbose test-unit-race test-unit-verbose-and-race +test-unit-verbose: ARGS=-v +test-unit-race: ARGS=-race +test-unit-verbose-and-race: ARGS=-v -race $(TEST_UNIT_TARGETS): test-unit .PHONY: $(TEST_UNIT_TARGETS) test-unit test-unit: ## Run unit tests