Skip to content

Commit

Permalink
.github/workflows: add a build and test workflows
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vdemeester committed Feb 18, 2025
1 parent 4006b00 commit afce644
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- name: ko-resolve
run: |
cat <<EOF > .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
3 changes: 2 additions & 1 deletion .github/workflows/e2e-matrix.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit afce644

Please sign in to comment.