Skip to content

Commit

Permalink
tekton: add go-unit-tests and golangci lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rphillips committed Dec 19, 2024
1 parent c23cce7 commit 8923e88
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
112 changes: 112 additions & 0 deletions .tekton/instaslice-go-unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: go-unit-test-lint
annotations:
pipelinesascode.tekton.dev/task: "[git-clone]"
pipelinesascode.tekton.dev/max-keep-runs: "2"
pipelinesascode.tekton.dev/cancel-in-progress: "true"
pipelinesascode.tekton.dev/on-target-branch: "main"
pipelinesascode.tekton.dev/on-event: "pull_request"
pipelinesascode.tekton.dev/on-path-change: "[***/*.go]"
spec:
params:
- name: repo_url
value: "{{repo_url}}"
- name: revision
value: "{{revision}}"
pipelineSpec:
params:
- name: repo_url
- name: revision
tasks:
- name: go
taskSpec:
workspaces:
- name: source
steps:
- name: fetch-repo
ref:
resolver: http
params:
- name: url
value: https://raw.githubusercontent.com/tektoncd/catalog/main/stepaction/git-clone/0.1/git-clone.yaml
params:
- name: output-path
value: $(workspaces.source.path)
- name: url
value: "$(params.repo_url)"
- name: revision
value: "$(params.revision)"
- name: cache-fetch
ref:
resolver: http
params:
- name: url
value: https://raw.githubusercontent.com/openshift-pipelines/tekton-caches/main/tekton/cache-fetch.yaml
params:
- name: patterns
value: ["**go.mod", "**go.sum"]
- name: source
value: oci://image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/cache-go:{{hash}}
- name: cachePath
value: $(workspaces.source.path)/go-build-cache
- name: workingdir
value: $(workspaces.source.path)
- name: unittest
# we get bumped out when usingh the official image with docker.io
# ratelimit so workaround this.
image: golang:1.22
env:
- name: GOCACHE
value: $(workspaces.source.path)/go-build-cache/cache
- name: GOMODCACHE
value: $(workspaces.source.path)/go-build-cache/mod
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env bash
set -eux
git config --global --add safe.directory $(workspaces.source.path)
make test-unit
- name: lint
image: golangci/golangci-lint:v1.62.2
workingDir: $(workspaces.source.path)
env:
- name: GOCACHE
value: $(workspaces.source.path)/go-build-cache/cache
- name: GOMODCACHE
value: $(workspaces.source.path)/go-build-cache/mod
- name: GOLANGCILINT_CACHE
value: $(workspaces.source.path)/go-build-cache/golangci-cache
script: |
#!/usr/bin/env bash
set -eux
make lint
- name: cache-upload
ref:
resolver: http
params:
- name: url
value: https://raw.githubusercontent.com/openshift-pipelines/tekton-caches/main/tekton/cache-upload.yaml
params:
- name: patterns
value: ["**go.mod", "**go.sum"]
- name: target
value: oci://image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/cache-go:{{hash}}
- name: cachePath
value: $(workspaces.source.path)/go-build-cache
- name: workingdir
value: $(workspaces.source.path)
- name: force-cache-upload
value: "false"
workspaces:
- name: source
workspace: source
workspaces:
- name: source
workspaces:
- name: source
emptyDir: {}
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ vet: ## Run go vet against code.
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

.PHONY: test-unit
test-unit:
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e:
Expand Down

0 comments on commit 8923e88

Please sign in to comment.