Skip to content

Commit 039260d

Browse files
author
Måns Thörnvik
committed
big update
1 parent f80c240 commit 039260d

14 files changed

Lines changed: 581 additions & 129 deletions

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.git/
2+
.github/
3+
4+
README.md
5+
LICENSE
6+
Makefile
7+
cmd/
8+
build/
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
14+
15+
- name: Set up Golang ${{ matrix.go-version-alias }}
16+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
17+
with:
18+
go-version-file: go.mod
19+
cache: false
20+
21+
- name: Checksum
22+
id: checksum
23+
run: |
24+
sha256sum go.mod go.sum > modsum.txt
25+
26+
# Exclude _test files, they are not needed to build the code and they change more often than the actual code.
27+
find . -type f -name "*.go" ! -name "*_test.go" -exec sha256sum {} \; > gosum.txt
28+
sha256sum modsum.txt gosum.txt > totalmodsum.txt
29+
echo "checksum=$(cat totalmodsum.txt | awk '{print $1}')" >> $GITHUB_OUTPUT
30+
31+
# Use restore-keys to always use a cache that was created with the same
32+
# prefix.
33+
- name: Cache go modules and the buildcache
34+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
35+
with:
36+
path: |
37+
~/go/pkg/mod
38+
~/.cache/go-build
39+
key: build-${{ github.sha }}
40+
restore-keys: build-
41+
42+
- name: Build server binary
43+
run: make build
44+
45+
- name: Build CLI binary
46+
run: make buildctl
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Unit test
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
14+
15+
- name: Set up Golang
16+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
17+
with:
18+
go-version-file: go.mod
19+
cache: false
20+
21+
- name: Checksum
22+
id: checksum
23+
run: |
24+
sha256sum go.mod go.sum > modsum.txt
25+
26+
find . -type f -name "*.go" -exec sha256sum {} \; > gosum.txt
27+
sha256sum modsum.txt gosum.txt > totalmodsum.txt
28+
echo "checksum=$(cat totalmodsum.txt | awk '{print $1}')" >> $GITHUB_OUTPUT
29+
30+
# Use restore-keys to always use a cache that was created with the same
31+
# prefix.
32+
- name: Cache go modules and the buildcache
33+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
34+
with:
35+
path: |
36+
~/go/pkg/mod
37+
~/.cache/go-build
38+
key: unit-test-${{ github.sha }}
39+
restore-keys: unit-test-
40+
41+
- name: Run tests
42+
run: go test ./... -v -failfast -coverprofile=coverage.out
43+
44+
- name: Generate coverage report
45+
run: go tool cover -html=coverage.out -o coverage.html
46+
47+
- name: Upload coverage report
48+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
49+
with:
50+
name: go-coverage-report-${{ matrix.go-version-alias }}
51+
path: coverage.html
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
name: Linting
1+
name: Code scanning
2+
3+
run-name: "Linting: ${{ github.event.head_commit.message }}"
24

35
on:
46
push:
@@ -13,7 +15,7 @@ permissions:
1315
security-events: write
1416

1517
jobs:
16-
go:
18+
golangci-lint:
1719
runs-on: ubuntu-latest
1820
steps:
1921
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -22,10 +24,11 @@ jobs:
2224
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
2325
with:
2426
version: v2.12.0
27+
working-directory: sample-go-app
2528
args: --output.sarif.path=results.sarif
2629

2730
- name: Upload SARIF report
2831
if: always()
2932
uses: github/codeql-action/upload-sarif@e46ed2cbd01164d986452f91f178727624ae40d7 # v4.53.3
3033
with:
31-
sarif_file: results.sarif
34+
sarif_file: sample-go-app/results.sarif

.github/workflows/go.yaml

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

.github/workflows/main.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ permissions:
1313
security-events: write
1414

1515
jobs:
16-
go:
17-
name: Golang
18-
uses: ./.github/workflows/go.yaml
16+
build:
17+
uses: ./.github/workflows/callable-build.yaml
18+
19+
unit-test:
20+
uses: ./.github/workflows/callable-test-unit.yaml
1921

2022
image:
2123
name: Image
22-
needs: go
2324
uses: ./.github/workflows/image.yaml
2425
with:
2526
push: false

.github/workflows/pull-request.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ permissions:
1313
security-events: write
1414

1515
jobs:
16-
go:
17-
name: Golang
18-
uses: ./.github/workflows/go.yaml
16+
build:
17+
uses: ./.github/workflows/callable-build.yaml
18+
19+
unit-test:
20+
uses: ./.github/workflows/callable-test-unit.yaml
1921

2022
image:
2123
name: Image
22-
needs: go
2324
uses: ./.github/workflows/image.yaml
2425
with:
25-
version: "latest"
2626
push: false

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ client/client
2020

2121
# Go workspace file
2222
go.work
23+
24+
# Build output
25+
build/

0 commit comments

Comments
 (0)