From 845dd3166d462ae4323a50fa23fe2f29e14c9cd0 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 18 Feb 2025 17:10:36 +0100 Subject: [PATCH] feat(ci): add comprehensive CI workflow This commit introduces a new CI workflow in `.github/workflows/ci.yaml` that handles build, linting, testing, and calls the e2e workflows. It optimizes the CI pipeline by including caching mechanisms and consolidates previously separate workflows. The following changes have been made: * Added a multi-stage CI workflow named `ci`. * Introduced linting steps using tools like `gofmt`, `golangci-lint`, `yamllint` and `go-license` check. * Incorporated build, unit tests, and generated code verification. * Added a multi-arch build support configuration. * Consolidated end-to-end tests via a workflow call in `e2e-matrix.yml`. Additionally, the redundant `golangci-lint.yaml` workflow has been removed. Support for a new test target `test-unit-verbose-and-race` is introduced in the `Makefile`, and the Go toolchain in `go.mod` is updated from `go 1.22.3` to `go 1.22.7`. Signed-off-by: Vincent Demeester --- .github/workflows/ci.yaml | 110 ++++++++++++++++++++++++++ .github/workflows/e2e-matrix.yml | 27 ++----- .github/workflows/golangci-lint.yaml | 25 ------ Makefile | 7 +- config/config-feature-flags.yaml | 4 +- docs/stepactions.md | 2 +- pkg/apis/config/feature_flags.go | 2 +- pkg/apis/config/feature_flags_test.go | 2 + 8 files changed, 128 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/ci.yaml delete mode 100644 .github/workflows/golangci-lint.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000000..bc1c4718bef --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,110 @@ +name: ci + +on: [pull_request] # yamllint disable-line rule:truthy + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull-request.number || github.ref }} + cancel-in-progress: true + +defaults: + run: + shell: bash + +permissions: + contents: read + checks: write # Used to annotate code in the PR + +jobs: + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + with: + go-version-file: "go.mod" + - name: build + run: | + go build -v ./... + linting: + needs: [build] + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + with: + go-version-file: "go.mod" + - name: gofmt + run: | + gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*')) + if [[ -n "$gofmt_out" ]]; then + failed=1 + fi + echo "$gofmt_out" + - name: golangci-lint + uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 + with: + version: v1.62.2 + args: --timeout=10m + - name: yamllint + run: | + apt update && apt install -y yamllint + yamllint -c .yamllint $(find . -path ./vendor -prune -o -type f -regex ".*y[a]ml" -print | tr '\n' ' ') + - name: check-license + run: | + go install github.com/google/go-licenses@v1.0.0 + go-licenses check ./... + tests: + needs: [build] + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + with: + go-version-file: "go.mod" + - name: build + run: | + make test-unit-verbose-and-race + generated: + needs: [build] + name: Check generated code + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + with: + go-version-file: "go.mod" + - name: generated + run: | + ./hack/verify-codegen.sh + multi-arch-build: + needs: [build] + name: Multi-arch build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 + with: + go-version-file: "go.mod" + - 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] + uses: ./.github/workflows/e2e-matrix.yml diff --git a/.github/workflows/e2e-matrix.yml b/.github/workflows/e2e-matrix.yml index 06d6d759500..161ed90cec7 100644 --- a/.github/workflows/e2e-matrix.yml +++ b/.github/workflows/e2e-matrix.yml @@ -1,7 +1,7 @@ name: Tekton Integration # Adapted from https://github.com/mattmoor/mink/blob/master/.github/workflows/minkind.yaml -on: [ pull_request ] +on: [workflow_call] defaults: run: @@ -9,6 +9,9 @@ defaults: jobs: e2e-tests: + concurrency: + group: ${{ github.workflow }}-${{ matrix.k8s-name }}-${{ matrix.feature-flags }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true name: e2e tests runs-on: ubuntu-latest strategy: @@ -36,33 +39,20 @@ jobs: - feature-flags: beta env-file: prow-beta env: - GOPATH: ${{ github.workspace }} - GO111MODULE: on KO_DOCKER_REPO: registry.local:5000/tekton CLUSTER_DOMAIN: c${{ github.run_id }}.local ARTIFACTS: ${{ github.workspace }}/artifacts steps: - - name: Check out code onto GOPATH - uses: actions/checkout@v4 + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 with: - path: ${{ github.workspace }}/src/github.com/tektoncd/pipeline - - - - name: Set up Go 1.22 - uses: actions/setup-go@v5 - with: - go-version: 1.22.5 + go-version-file: "go.mod" + - uses: ko-build/setup-ko@v0.8 - name: Install Dependencies working-directory: ./ run: | - echo '::group:: install ko' - curl -L https://github.com/ko-build/ko/releases/download/v0.15.4/ko_0.15.4_Linux_x86_64.tar.gz | tar xzf - ko - chmod +x ./ko - sudo mv ko /usr/local/bin - echo '::endgroup::' - echo '::group:: install go-junit-report' go install github.com/jstemmer/go-junit-report@v0.9.1 echo '::endgroup::' @@ -74,7 +64,6 @@ jobs: echo "${GOPATH}/bin" >> "$GITHUB_PATH" - name: Run tests - working-directory: ${{ github.workspace }}/src/github.com/tektoncd/pipeline run: | ./hack/setup-kind.sh \ --registry-url $(echo ${KO_DOCKER_REPO} | cut -d'/' -f 1) \ diff --git a/.github/workflows/golangci-lint.yaml b/.github/workflows/golangci-lint.yaml deleted file mode 100644 index 89d62e17af5..00000000000 --- a/.github/workflows/golangci-lint.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: golangci-lint -on: # yamllint disable-line rule:truthy - push: - branches: - - main - pull_request: # yamllint disable-line rule:empty-values - -permissions: - contents: read - checks: write # Used to annotate code in the PR - -jobs: - golangci: - name: lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0 - with: - go-version: "1.23" - - name: golangci-lint - uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 - with: - version: v1.62.2 - args: --timeout=10m 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 diff --git a/config/config-feature-flags.yaml b/config/config-feature-flags.yaml index 398f37d1880..1e5fc4777fe 100644 --- a/config/config-feature-flags.yaml +++ b/config/config-feature-flags.yaml @@ -123,8 +123,8 @@ data: # Setting this flag to "true" will enable the CEL evaluation in WhenExpression enable-cel-in-whenexpression: "false" # Setting this flag to "true" will enable the use of StepActions in Steps - # This feature is in preview mode and not implemented yet. Please check #7259 for updates. - enable-step-actions: "false" + # This feature is in beta and enabled by default. + enable-step-actions: "true" # Setting this flag to "true" will enable the use of Artifacts in Steps # This feature is in preview mode and not implemented yet. Please check #7693 for updates. enable-artifacts: "false" diff --git a/docs/stepactions.md b/docs/stepactions.md index 062a2e39d94..73d7ab7482e 100644 --- a/docs/stepactions.md +++ b/docs/stepactions.md @@ -22,7 +22,7 @@ weight: 201 ## Overview > :seedling: **`StepActions` is an [beta](additional-configs.md#beta-features) feature.** -> The `enable-step-actions` feature flag must be set to `"true"` to specify a `StepAction` in a `Step`. +> Step actions are enabled by default. You can disable them by setting the `enable-step-actions` feature flag to `"false"`. A `StepAction` is the reusable and scriptable unit of work that is performed by a `Step`. diff --git a/pkg/apis/config/feature_flags.go b/pkg/apis/config/feature_flags.go index d0db62052cf..038ccf5f220 100644 --- a/pkg/apis/config/feature_flags.go +++ b/pkg/apis/config/feature_flags.go @@ -156,7 +156,7 @@ var ( DefaultEnableStepActions = PerFeatureFlag{ Name: EnableStepActions, Stability: BetaAPIFields, - Enabled: DefaultBetaFeatureEnabled, + Enabled: DefaultStableFeatureEnabled, } // DefaultEnableArtifacts is the default PerFeatureFlag value for EnableArtifacts diff --git a/pkg/apis/config/feature_flags_test.go b/pkg/apis/config/feature_flags_test.go index 30c0e06a8e0..bb98c622dfc 100644 --- a/pkg/apis/config/feature_flags_test.go +++ b/pkg/apis/config/feature_flags_test.go @@ -131,6 +131,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { SetSecurityContext: config.DefaultSetSecurityContext, Coschedule: config.DefaultCoschedule, EnableParamEnum: config.DefaultEnableParamEnum.Enabled, + EnableStepActions: true, DisableInlineSpec: config.DefaultDisableInlineSpec, }, fileName: "feature-flags-bundles-and-custom-tasks", @@ -152,6 +153,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { SetSecurityContext: config.DefaultSetSecurityContext, Coschedule: config.DefaultCoschedule, EnableParamEnum: config.DefaultEnableParamEnum.Enabled, + EnableStepActions: true, DisableInlineSpec: config.DefaultDisableInlineSpec, }, fileName: "feature-flags-beta-api-fields",