Skip to content

Commit c4679da

Browse files
authored
GitHub actions Build, Test and Release workflows (#94)
* Switching to Github Codeowners * Generate Codecoverage reports * Initial Build workflows * Upgrade to go1.18 * Fix Code Owners * Swith to ubuntu-latest * General fixes * Update to go 1.20 * Initial Dependabot setup * Upgrade all the things * Fix up testcoverage check * Switching to Go-lang/jwt * Only build the image if lint and tests pass * Simple Helm lint Test * Update Dockerfile to alpine:3.17.2 * helm chart fixes (#102) * Adding Error Counter Metric * Adding Semver Prefix and fix typo * Revert "helm chart fixes (#102)" (#103) This reverts commit 9185224. * Resolve issue 63 (#101) * Allow for overriding Token Path (#100) * Increase the number of Tags fetched for Docker Registries (#99) * Adding k8s.io support (#98) * Better support for selfHosted and SSL connections (#95) * Enable SSL Skip Verify if you're unable to provide a valid certificate bundle * Allow for additional Certs to be added into the CA Chain * Update README.md for helm installation * Adding initial release workflow * Build multi-arch images * Fix Dockerfile build artifact * Tag and Upload to quay.io/jetstack/version-checker instead of docker hub * Swithcing to main as the default branch changed * Set up for review * Switch to using sha for PR builds
1 parent 93df732 commit c4679da

File tree

16 files changed

+677
-525
lines changed

16 files changed

+677
-525
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @davidcollom

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
open-pull-requests-limit: 0
8+
9+
- package-ecosystem: "gomod"
10+
directory: "/"
11+
schedule:
12+
interval: "weekly"
13+
open-pull-requests-limit: 0

.github/workflows/build-test.yaml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Test & Build
2+
on:
3+
pull_request:
4+
branches:
5+
- 'main'
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
lint:
13+
permissions:
14+
contents: read # for actions/checkout to fetch code
15+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
16+
name: Lint Go code
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
21+
- name: Setup Golang
22+
uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.0
23+
- name: Run golangci-lint
24+
uses: golangci/golangci-lint-action@639cd343e1d3b897ff35927a75193d57cfcba299 # v3.6.0
25+
with:
26+
version: v1.53
27+
args: --timeout 10m --exclude SA5011 --verbose --issues-exit-code=0
28+
only-new-issues: true
29+
30+
test:
31+
name: Run unit tests for Go packages
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v3 # v3.5.3
36+
- name: Setup Go
37+
uses: actions/setup-go@v4
38+
39+
- name: Download and required packages
40+
run: |
41+
make deps
42+
43+
- name: Run all unit tests
44+
run: make test
45+
46+
- name: check test coverage
47+
uses: vladopajic/go-test-coverage@v2
48+
with:
49+
config: ./.testcoverage.yml
50+
51+
- name: Generate code coverage artifacts
52+
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
53+
with:
54+
name: code-coverage
55+
path: coverage.out
56+
57+
build:
58+
needs:
59+
- test
60+
- lint
61+
runs-on: ubuntu-latest
62+
strategy:
63+
fail-fast: false
64+
matrix:
65+
platform:
66+
- linux/amd64
67+
- linux/arm64
68+
- linux/arm/v7
69+
name: Build Images
70+
steps:
71+
- name: Checkout code
72+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
73+
- name: Set up QEMU
74+
uses: docker/setup-qemu-action@v2
75+
76+
- name: Set up Docker Buildx
77+
uses: docker/setup-buildx-action@v2
78+
with:
79+
platforms: ${{ matrix.platform }}
80+
81+
- name: Login to Docker Hub
82+
uses: docker/login-action@v2
83+
with:
84+
registry: quay.io
85+
username: ${{ secrets.QUAY_USERNAME }}
86+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
87+
88+
- name: Build and push
89+
uses: docker/build-push-action@v4
90+
with:
91+
context: .
92+
platforms: ${{ matrix.platform }}
93+
push: false
94+
tags: quay.io/jetstack/version-checker:${{github.sha}}
95+
cache-from: type=gha
96+
cache-to: type=gha,mode=max

.github/workflows/helm-test.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Test Helm Chart
2+
on:
3+
pull_request:
4+
paths:
5+
- 'deploy/charts/version-checker/**'
6+
branches:
7+
- 'main'
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lint:
15+
permissions:
16+
contents: read # for actions/checkout to fetch code
17+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
18+
name: Lint Helm Chart
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
23+
24+
- uses: azure/setup-helm@v3
25+
26+
- run: helm lint deploy/charts/version-checker
27+
28+
test:
29+
name: Run unit tests for Helm Chart
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Checkout code
33+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
34+
35+
- uses: azure/setup-helm@v3
36+
with:
37+
token: ${{ github.token }}
38+
39+
- name: Install helm Plugins
40+
run: |
41+
if [ ! -e "${HELM_PLUGINS}/helm-unittest" ]; then
42+
helm plugin install https://github.com/helm-unittest/helm-unittest.git
43+
fi
44+
45+
- name: Run Tests
46+
run: |
47+
if [ ! -e "deploy/charts/verson-checker/tests" ]; then
48+
echo "Not running tests, directory doesn't exist: deploy/charts/verson-checker/tests"
49+
exit 0
50+
fi
51+
helm unittest --helm3 --color deploy/charts/verson-checker

.github/workflows/release.yaml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Version-Checker Release
2+
3+
on:
4+
push:
5+
branches:
6+
- 'release-.*'
7+
tags:
8+
- '*'
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
helm-release:
16+
if: startsWith(github.ref, 'refs/tags/')
17+
runs-on: ubuntu-latest
18+
steps:
19+
# Checkout our Repo
20+
- uses: actions/checkout@v3
21+
with:
22+
path: version-checker
23+
24+
- name: checkout jetstack-charts
25+
uses: actions/checkout@v3
26+
with:
27+
token: ${{ secrets.JETSTACK_CHARTS_PAT }}
28+
repository: jetstack/jetstack-charts
29+
ref: main
30+
path: jetstack-charts
31+
32+
- uses: azure/setup-helm@v3
33+
with:
34+
token: ${{ github.token }}
35+
36+
- name: package helm chart
37+
run: |
38+
helm package version-checker/deploy/charts/version-checker -d jetstack-charts/charts/
39+
40+
- name: Creating PR
41+
uses: peter-evans/create-pull-request@v5
42+
with:
43+
token: ${{ secrets.JETSTACK_CHARTS_PAT }}
44+
title: "Release version-checker ${{github.ref_name }}"
45+
commit-message: "Release version-checker ${{github.ref_name }}"
46+
branch: version-checker/${{github.ref_name}}
47+
path: jetstack-charts
48+
add-paths: charts/*.tgz
49+
delete-branch: true
50+
signoff: true
51+
base: main
52+
draft: ${{ contains('-rc', github.ref_name) || !startsWith(github.ref, 'refs/tags/') }}
53+
54+
docker-release:
55+
runs-on: ubuntu-latest
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
platform:
60+
- linux/amd64
61+
- linux/arm64
62+
- linux/arm/v7
63+
steps:
64+
- uses: actions/checkout@v3
65+
- name: Set up QEMU
66+
uses: docker/setup-qemu-action@v2
67+
68+
- name: Set up Docker Buildx
69+
uses: docker/setup-buildx-action@v2
70+
with:
71+
platforms: ${{ matrix.platform }}
72+
73+
- name: Login to Docker Hub
74+
uses: docker/login-action@v2
75+
with:
76+
registry: quay.io
77+
username: ${{ secrets.QUAY_USERNAME }}
78+
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
79+
80+
- name: Build and push (if applicable)
81+
uses: docker/build-push-action@v4
82+
with:
83+
context: .
84+
platforms: ${{ matrix.platform }}
85+
push: ${{ !startsWith(github.ref, 'refs/tags/') }}
86+
tags: quay.io/jetstack/version-checker:${{github.ref_name}}
87+
cache-from: type=gha
88+
cache-to: type=gha,mode=max
89+
90+
91+
github-release:
92+
permissions:
93+
contents: write
94+
runs-on: ubuntu-latest
95+
steps:
96+
- uses: actions/checkout@v3
97+
98+
- name: Create Release / Change Logs
99+
uses: softprops/action-gh-release@v1
100+
with:
101+
draft: ${{ !startsWith(github.ref, 'refs/tags/') }}
102+
prerelease: ${{ contains('-rc', github.ref_name) || !startsWith(github.ref, 'refs/tags/') }}
103+
generate_release_notes: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/bin
2+
coverage.out

.testcoverage.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# (mandatory)
2+
# Path to coverprofile file (output of `go test -coverprofile` command)
3+
profile: coverage.out
4+
5+
# (optional)
6+
# When specified reported file paths will not contain local prefix in the output
7+
# local-prefix: "github.com/org/project"
8+
9+
# Holds coverage thresholds percentages, values should be in range [0-100]
10+
threshold:
11+
# (optional; default 0)
12+
# The minimum coverage that each file should have
13+
file: 0
14+
15+
# (optional; default 0)
16+
# The minimum coverage that each package should have
17+
package: 0
18+
19+
# (optional; default 0)
20+
# The minimum total coverage project should have
21+
total: 0
22+
23+
# Holds regexp rules which will override thresholds for matched files or packages
24+
# override:
25+
# # Increase coverage threshold to 100% for `foo` package (default is 80, as configured above)
26+
# - threshold: 100
27+
# path: ^pkg/lib/foo$
28+
29+
# Holds regexp rules which will exclude matched files or packages from coverage statistics
30+
# exclude:
31+
# # Exclude files or packages matching their paths
32+
# paths:
33+
# - \.pb\.go$ # excludes all protobuf generated files
34+
# - ^pkg/bar # exclude package `pkg/bar`
35+
36+
# NOTES:
37+
# - symbol `/` in all path regexps will be replaced by
38+
# current OS file path separator to properly work on Windows

Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
FROM alpine:3.12
1+
FROM golang:1.20-alpine as builder
2+
3+
RUN apk --no-cache add make
4+
5+
COPY . /app/
6+
WORKDIR /app/
7+
8+
RUN make build
9+
10+
11+
FROM alpine:3.18.2
212
LABEL description="Kubernetes utility for exposing used image versions compared to the latest version, as metrics."
313

414
RUN apk --no-cache add ca-certificates
515

6-
COPY ./bin/version-checker-linux /usr/bin/version-checker
16+
COPY --from=builder /app/bin/version-checker /usr/bin/version-checker
717

818
ENTRYPOINT ["/usr/bin/version-checker"]

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@ help: ## display this help
66

77
.PHONY: help build image all clean
88

9-
test: ## test version-checker
10-
go test ./...
9+
deps: ## Download all Dependencies
10+
go mod download
1111

12-
build: ## build version-checker
12+
test: deps ## test version-checker
13+
go test ./... -coverprofile=coverage.out
14+
15+
$(BINDIR):
1316
mkdir -p $(BINDIR)
17+
18+
build: deps $(BINDIR) ## build version-checker
1419
CGO_ENABLED=0 go build -o ./bin/version-checker ./cmd/.
1520

1621
verify: test build ## tests and builds version-checker
1722

1823
image: ## build docker image
19-
GOARCH=$(ARCH) GOOS=linux CGO_ENABLED=0 go build -o ./bin/version-checker-linux ./cmd/.
2024
docker build -t quay.io/jetstack/version-checker:v0.2.2 .
2125

2226
clean: ## clean up created files

OWNERS

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)