-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (125 loc) · 4.09 KB
/
Go-Build.yml
File metadata and controls
151 lines (125 loc) · 4.09 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
# =============================================================================
# GO-OPTIMIZR CI Pipeline
# Verifies compilation and runs tests on every push and pull request
# =============================================================================
name: Go Build & Test
on:
push:
branches: [ main, master, develop ]
tags: [ 'v*' ]
pull_request:
branches: [ main, master ]
env:
GO_VERSION: '1.22'
jobs:
# ---------------------------------------------------------------------------
# Build Job: Verify code compiles (Linux only - CGO required for webp)
# ---------------------------------------------------------------------------
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
goarch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install libwebp
run: |
sudo apt-get update
sudo apt-get install -y libwebp-dev
- name: Install cross-compilation tools
if: matrix.goarch == 'arm64'
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Verify dependencies
run: |
go mod download
go mod verify
- name: Build binary
env:
GOOS: linux
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
CC: ${{ matrix.goarch == 'arm64' && 'aarch64-linux-gnu-gcc' || 'gcc' }}
run: |
go build -v -ldflags="-s -w" -o go-optimizr-linux-${{ matrix.goarch }} ./cmd/optimizr
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: go-optimizr-linux-${{ matrix.goarch }}
path: go-optimizr-linux-${{ matrix.goarch }}
retention-days: 7
# ---------------------------------------------------------------------------
# Lint Job: Code quality checks
# ---------------------------------------------------------------------------
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install libwebp
run: |
sudo apt-get update
sudo apt-get install -y libwebp-dev
- name: Run go vet
run: go vet ./...
- name: Check formatting
run: |
if [ -n "$(gofmt -l .)" ]; then
echo "Code is not formatted. Run 'go fmt ./...'"
gofmt -d .
exit 1
fi
# ---------------------------------------------------------------------------
# Docker Build Job: Verify Dockerfile builds correctly
# ---------------------------------------------------------------------------
docker:
name: Docker Build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: go-optimizr:test
cache-from: type=gha
cache-to: type=gha,mode=max
# ---------------------------------------------------------------------------
# Release Job: Create release on tagged pushes
# ---------------------------------------------------------------------------
release:
name: Release
needs: [build, lint, docker]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/**/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}