-
Notifications
You must be signed in to change notification settings - Fork 0
167 lines (146 loc) · 4.71 KB
/
build.yaml
File metadata and controls
167 lines (146 loc) · 4.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: CI Build & Test
on:
workflow_dispatch:
push:
branches:
- main
paths-ignore:
- docs/**
- "**.md"
- .github/workflows/docs-website.yaml
- .github/workflows/validations.yaml
- .github/workflows/release.yaml
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
paths-ignore:
- docs/**
- "**.md"
- .github/workflows/docs-website.yaml
- .github/workflows/validations.yaml
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
validate:
name: Quality Validations
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v6
# Set up Go environment
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: true
cache-dependency-path: "**/*.sum"
- name: GolangCI Lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
- name: Run format-check
run: |
UNFORMATTED=$(gofmt -l .)
if [ -n "$UNFORMATTED" ]; then
echo "The following files are not formatted according to gofmt:"
echo "$UNFORMATTED"
exit 1
fi
test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
# Checkout code
- name: Checkout repository
uses: actions/checkout@v6
# Set up Go environment
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: true
cache-dependency-path: "**/*.sum"
- name: Run tests
run: go test -race -cover -covermode=atomic -coverprofile=coverage.txt ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
prepare:
name: Prepare Build Config
runs-on: ubuntu-latest
outputs:
is_pr: ${{ steps.config.outputs.is_pr }}
should_push_docker: ${{ steps.config.outputs.should_push_docker }}
steps:
- id: config
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PR builds: no Docker push
echo "is_pr=true" >> "$GITHUB_OUTPUT"
echo "should_push_docker=false" >> "$GITHUB_OUTPUT"
else
# Main branch: push Docker with 'main' tag
echo "is_pr=false" >> "$GITHUB_OUTPUT"
echo "should_push_docker=true" >> "$GITHUB_OUTPUT"
fi
build:
name: Build with GoReleaser
runs-on: ubuntu-latest
needs:
- test
- validate
- prepare
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
cache: true
cache-dependency-path: "**/*.sum"
- name: Set up Docker Buildx
if: needs.prepare.outputs.should_push_docker == 'true'
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: needs.prepare.outputs.should_push_docker == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Modify GoReleaser config for CI builds
run: |
# Install yq
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
if [[ "${{ needs.prepare.outputs.is_pr }}" == "true" ]]; then
# PR builds: Skip Docker entirely
yq eval -i 'del(.dockers) | del(.docker_manifests) | del(.docker_signs)' .goreleaser.yaml
else
# Main branch builds: Change image tags to 'main'
yq eval -i '
.dockers[0].image_templates = ["ghcr.io/spechtlabs/tka:main-amd64"] |
.dockers[1].image_templates = ["ghcr.io/spechtlabs/tka:main-arm64"] |
.docker_manifests[0].name_template = "ghcr.io/spechtlabs/tka:main" |
.docker_manifests[0].image_templates = ["ghcr.io/spechtlabs/tka:main-amd64", "ghcr.io/spechtlabs/tka:main-arm64"] |
del(.docker_manifests[1]) | del(.docker_manifests[1]) |
del(.docker_signs)
' .goreleaser.yaml
fi
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
args: release --snapshot --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}