Skip to content

Commit bc96edb

Browse files
committed
chore: Add CI
Signed-off-by: Yiannis <[email protected]>
1 parent 4d654c5 commit bc96edb

File tree

9 files changed

+184
-9
lines changed

9 files changed

+184
-9
lines changed

.github/workflows/ci.yaml

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
name: Lint
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read # for actions/checkout to fetch code
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Setup
21+
uses: actions/setup-go@v3
22+
with:
23+
go-version: 1.19.x
24+
cache: true
25+
- name: Prepare
26+
run: |
27+
echo "machine github.com login ${{ github.actor }} password ${{ secrets.BUILD_BOT_TOKEN }}" > ~/.netrc
28+
- name: Lint
29+
run: make lint
30+
31+
test:
32+
name: Test
33+
runs-on: ubuntu-latest
34+
permissions:
35+
contents: read # for actions/checkout to fetch code
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
- name: Setup
40+
uses: actions/setup-go@v3
41+
with:
42+
go-version: 1.19.x
43+
cache: true
44+
- name: Prepare
45+
run: |
46+
echo "machine github.com login ${{ github.actor }} password ${{ secrets.BUILD_BOT_TOKEN }}" > ~/.netrc
47+
- name: Test
48+
run: make test
49+
50+
push:
51+
name: Push
52+
if: github.event.pull_request.merged == true
53+
runs-on: ubuntu-latest
54+
needs: [lint, test]
55+
permissions:
56+
contents: read # for actions/checkout to fetch code
57+
packages: write # needed for ghcr access
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v3
61+
- name: Setup QEMU
62+
uses: docker/setup-qemu-action@v2
63+
- name: Setup Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
- name: Login to GitHub Container Registry
66+
uses: docker/login-action@v2
67+
with:
68+
registry: ghcr.io
69+
username: ${{ github.actor }}
70+
password: ${{ secrets.GITHUB_TOKEN }}
71+
- name: Login to DockerHub
72+
uses: docker/login-action@v2
73+
with:
74+
username: ${{ secrets.DOCKERHUB_USERNAME }}
75+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
76+
- name: Prepare
77+
run: |
78+
echo "machine github.com login ${{ github.actor }} password ${{ secrets.BUILD_BOT_TOKEN }}" | tee ~/.netrc .netrc
79+
- name: Push to GitHub Container Registry
80+
run: make docker-push # defaults to ghcr.io
81+
- name: Push to DockerHub
82+
run: IMG_REGISTRY=docker.io make docker-push

.github/workflows/release.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
- name: Setup QEMU
16+
uses: docker/setup-qemu-action@v2
17+
- name: Setup Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
- name: Login to GitHub Container Registry
20+
uses: docker/login-action@v2
21+
with:
22+
registry: ghcr.io
23+
username: ${{ github.actor }}
24+
password: ${{ secrets.GITHUB_TOKEN }}
25+
- name: Login to DockerHub
26+
uses: docker/login-action@v2
27+
with:
28+
username: ${{ secrets.DOCKERHUB_USERNAME }}
29+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
30+
- name: Push to GitHub Container Registry
31+
run: make release # defaults to ghcr.io
32+
- name: Push to DockerHub
33+
run: IMG_REGISTRY=docker.io make release

.github/workflows/scan.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Scan
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
scan:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read # for actions/checkout to fetch code
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
- name: Setup | Go
20+
uses: actions/setup-go@v3
21+
with:
22+
go-version: 1.19.x
23+
cache: true
24+
- name: Setup | Snyk
25+
uses: snyk/actions/setup@master
26+
- name: Prepare
27+
run: |
28+
echo "machine github.com login ${{ github.actor }} password ${{ secrets.BUILD_BOT_TOKEN }}" > ~/.netrc
29+
- name: Run Snyk to check for vulnerabilities
30+
run: snyk test --org=product-engineering-ly9 --file=go.mod
31+
env:
32+
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN_WEAVEWORKS_ALL }}

.snyk

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.25.0
3+
# ignores vulnerabilities until expiry date; change duration by modifying expiry date
4+
ignore:
5+
SNYK-GOLANG-GITHUBCOMEMICKLEIGORESTFUL-2435653:
6+
- '*':
7+
reason: >-
8+
Waiting for upstream dependency to be resolved
9+
https://github.com/kubernetes/client-go/issues/1135
10+
expires: 2022-09-21T11:42:12.847Z
11+
created: 2022-08-22T11:42:12.850Z
12+
patch: {}

Makefile

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11

22
# Image URL to use all building/pushing image targets
3-
IMG_TAG ?= latest
4-
IMG ?= ghcr.io/weaveworks/pipeline-controller:$(IMG_TAG)
3+
IMG_TAG ?= $(shell echo "$$(git describe --tags "$$(git rev-parse "HEAD^{commit}")^{commit}" --match v* 2>/dev/null || git rev-parse "HEAD^{commit}")$$([ -z "$$(git status --porcelain 2>/dev/null)" ] || echo -dirty)")
4+
IMG_REGISTRY ?= ghcr.io
5+
IMG ?= $(IMG_REGISTRY)/weaveworks/pipeline-controller:$(IMG_TAG)
56
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
67
ENVTEST_K8S_VERSION = 1.24.2
78

@@ -14,6 +15,11 @@ endif
1415
# GOPRIVATE = github.com/weaveworks/cluster-controller
1516

1617
DOCKER_BUILD_ARGS ?= --load
18+
DOCKER_BUILD_LABELS ?= --label org.opencontainers.image.created=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") \
19+
--label org.opencontainers.image.authors="Weaveworks Product Engineering" \
20+
--label org.opencontainers.image.source=github.com/weaveworks/pipeline-controller \
21+
--label org.opencontainers.image.revision=$(IMG_TAG) \
22+
--label org.opencontainers.image.vendor=Weaveworks
1723

1824
# Setting SHELL to bash allows bash commands to be executed by recipes.
1925
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
@@ -58,6 +64,9 @@ fmt: ## Run go fmt against code.
5864
vet: ## Run go vet against code.
5965
go vet ./...
6066

67+
lint: golangci-lint ## Run linters against code
68+
$(GOLANGCI_LINT) run --out-format=github-actions --timeout 600s
69+
6170
.PHONY: test
6271
test: manifests generate fmt vet envtest ## Run tests.
6372
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
@@ -74,7 +83,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
7483

7584
.PHONY: docker-build
7685
docker-build: test ## Build docker image with the manager.
77-
docker build --secret id=netrc,src=.netrc -t ${IMG} $(DOCKER_BUILD_ARGS) .
86+
docker buildx build --secret id=netrc,src=.netrc -t ${IMG} $(DOCKER_BUILD_ARGS) $(DOCKER_BUILD_LABELS) .
7887

7988
.PHONY: docker-push
8089
docker-push: DOCKER_BUILD_ARGS=--push --platform linux/arm64/v8,linux/amd64
@@ -118,10 +127,12 @@ $(LOCALBIN):
118127
KUSTOMIZE ?= $(LOCALBIN)/kustomize
119128
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
120129
ENVTEST ?= $(LOCALBIN)/setup-envtest
130+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
121131

122132
## Tool Versions
123133
KUSTOMIZE_VERSION ?= v4.5.7
124134
CONTROLLER_TOOLS_VERSION ?= v0.9.2
135+
GOLANGCI_LINT_VERSION ?= v1.48.0
125136

126137
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
127138
.PHONY: kustomize
@@ -138,3 +149,8 @@ $(CONTROLLER_GEN): $(LOCALBIN)
138149
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
139150
$(ENVTEST): $(LOCALBIN)
140151
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
152+
153+
.PHONY: golangci-lint
154+
golangci-lint: $(GOLANGCI_LINT)
155+
$(GOLANGCI_LINT): $(LOCALBIN)
156+
test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)

controllers/pipeline_controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type PipelineReconciler struct {
3333

3434
func NewPipelineReconciler(c client.Client, s *runtime.Scheme, controllerName string) *PipelineReconciler {
3535
targetScheme := runtime.NewScheme()
36-
helmctrlv2beta1.AddToScheme(targetScheme)
36+
_ = helmctrlv2beta1.AddToScheme(targetScheme)
3737
return &PipelineReconciler{
3838
Client: c,
3939
Scheme: s,

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
replace github.com/weaveworks/pipeline-controller/api => ./api
66

7-
replace gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b => gopkg.in/yaml.v3 v3.0.0
7+
replace gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b => gopkg.in/yaml.v3 v3.0.1
88

99
require (
1010
github.com/fluxcd/helm-controller/api v0.22.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -977,8 +977,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
977977
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
978978
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
979979
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
980-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
981-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
980+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
981+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
982982
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
983983
gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8=
984984
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

go.work.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cloud.google.com/go v0.81.0 h1:at8Tk2zUz63cLPR0JPWm5vp77pEZmzxEQBEfRKn1VV8=
22
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
33
go.uber.org/zap v1.19.1 h1:ue41HOKd1vGURxrmeKIgELGb3jPW9DMUDGtsinblHwI=
4-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
5-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
5+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)