Skip to content

Commit 6fe2126

Browse files
committed
chore: switch to goreleaser
1 parent 379a4fb commit 6fe2126

3 files changed

Lines changed: 82 additions & 171 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,17 @@ name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [main, develop]
6-
tags: ["v*"]
5+
branches: [main]
76
pull_request:
8-
branches: [main, develop]
9-
10-
env:
11-
REGISTRY: ghcr.io
12-
IMAGE_NAME: ${{ github.repository }}
7+
branches: [main]
138

149
jobs:
1510
test:
1611
name: Test
1712
runs-on: ubuntu-latest
1813
strategy:
1914
matrix:
20-
go-version: ["1.23"]
15+
go-version: ["1.24"]
2116

2217
steps:
2318
- name: Checkout code
@@ -77,169 +72,6 @@ jobs:
7772
version: latest
7873
args: --timeout=5m
7974

80-
build:
81-
name: Build
82-
runs-on: ubuntu-latest
83-
needs: [test, lint]
84-
strategy:
85-
matrix:
86-
goos: [linux, windows, darwin]
87-
goarch: [amd64, arm64]
88-
exclude:
89-
- goos: windows
90-
goarch: arm64
91-
92-
steps:
93-
- name: Checkout code
94-
uses: actions/checkout@v4
95-
96-
- name: Set up Go
97-
uses: actions/setup-go@v5
98-
with:
99-
go-version: "1.23"
100-
101-
- name: Cache Go modules
102-
uses: actions/cache@v4
103-
with:
104-
path: |
105-
~/.cache/go-build
106-
~/go/pkg/mod
107-
key: ${{ runner.os }}-go-1.23-${{ hashFiles('**/go.sum') }}
108-
restore-keys: |
109-
${{ runner.os }}-go-1.23-
110-
111-
- name: Build binary
112-
env:
113-
GOOS: ${{ matrix.goos }}
114-
GOARCH: ${{ matrix.goarch }}
115-
CGO_ENABLED: 0
116-
run: |
117-
VERSION=${GITHUB_REF#refs/tags/}
118-
if [[ "$VERSION" == "refs/heads/"* ]]; then
119-
VERSION=${GITHUB_SHA:0:8}
120-
fi
121-
BINARY_NAME=dns-sync
122-
if [ "$GOOS" = "windows" ]; then
123-
BINARY_NAME="${BINARY_NAME}.exe"
124-
fi
125-
mkdir -p build
126-
go build -ldflags "-s -w -X main.version=$VERSION" -o build/${BINARY_NAME}-${GOOS}-${GOARCH} cmd/dns-sync/main.go
127-
128-
- name: Upload build artifacts
129-
uses: actions/upload-artifact@v4
130-
with:
131-
name: dns-sync-${{ matrix.goos }}-${{ matrix.goarch }}
132-
path: build/
133-
134-
docker:
135-
name: Build and Push Docker Image
136-
runs-on: ubuntu-latest
137-
needs: [test, lint]
138-
permissions:
139-
contents: read
140-
packages: write
141-
142-
steps:
143-
- name: Checkout code
144-
uses: actions/checkout@v4
145-
146-
- name: Set up Docker Buildx
147-
uses: docker/setup-buildx-action@v3
148-
149-
- name: Log in to Container Registry
150-
uses: docker/login-action@v3
151-
with:
152-
registry: ${{ env.REGISTRY }}
153-
username: ${{ github.actor }}
154-
password: ${{ secrets.GITHUB_TOKEN }}
155-
156-
- name: Extract metadata
157-
id: meta
158-
uses: docker/metadata-action@v5
159-
with:
160-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
161-
tags: |
162-
type=ref,event=branch
163-
type=ref,event=pr
164-
type=semver,pattern={{version}}
165-
type=semver,pattern={{major}}.{{minor}}
166-
type=semver,pattern={{major}}
167-
type=sha,prefix={{branch}}-
168-
type=raw,value=latest,enable={{is_default_branch}}
169-
170-
- name: Build and push Docker image
171-
uses: docker/build-push-action@v5
172-
with:
173-
context: .
174-
platforms: linux/amd64,linux/arm64
175-
push: true
176-
tags: ${{ steps.meta.outputs.tags }}
177-
labels: ${{ steps.meta.outputs.labels }}
178-
cache-from: type=gha
179-
cache-to: type=gha,mode=max
180-
build-args: |
181-
VERSION=${{ github.ref_name }}
182-
183-
release:
184-
name: Create Release
185-
runs-on: ubuntu-latest
186-
needs: [build]
187-
if: startsWith(github.ref, 'refs/tags/')
188-
permissions:
189-
contents: write
190-
191-
steps:
192-
- name: Checkout code
193-
uses: actions/checkout@v4
194-
195-
- name: Download all artifacts
196-
uses: actions/download-artifact@v4
197-
with:
198-
path: artifacts/
199-
200-
- name: Prepare release assets
201-
run: |
202-
mkdir -p release
203-
for dir in artifacts/*/; do
204-
if [ -d "$dir" ]; then
205-
cd "$dir"
206-
for file in *; do
207-
if [ -f "$file" ]; then
208-
# Create tar.gz for non-Windows binaries
209-
if [[ "$file" != *.exe ]]; then
210-
tar -czf "../../release/${file}.tar.gz" "$file"
211-
else
212-
# Create zip for Windows binaries
213-
zip "../../release/${file%.exe}.zip" "$file"
214-
fi
215-
fi
216-
done
217-
cd - > /dev/null
218-
fi
219-
done
220-
221-
- name: Generate changelog
222-
run: |
223-
if [ -f CHANGELOG.md ]; then
224-
# Extract changelog for current version
225-
awk '/^## \[/{if(p) exit; if($0 ~ /\['${GITHUB_REF#refs/tags/}'\]/) p=1} p' CHANGELOG.md > release_notes.md
226-
else
227-
echo "Release ${GITHUB_REF#refs/tags/}" > release_notes.md
228-
echo "" >> release_notes.md
229-
echo "### Changes" >> release_notes.md
230-
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD >> release_notes.md
231-
fi
232-
233-
- name: Create Release
234-
uses: softprops/action-gh-release@v1
235-
with:
236-
files: release/*
237-
body_path: release_notes.md
238-
draft: false
239-
prerelease: ${{ contains(github.ref, '-') }}
240-
env:
241-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
242-
24375
security:
24476
name: Security Scan
24577
runs-on: ubuntu-latest

.github/workflows/release.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: goreleaser
2+
3+
env:
4+
REGISTRY: ghcr.io
5+
IMAGE_NAME: ${{ github.repository }}
6+
7+
on:
8+
pull_request:
9+
push:
10+
# run only against tags
11+
tags:
12+
- "*"
13+
14+
permissions:
15+
contents: write
16+
packages: write
17+
18+
jobs:
19+
goreleaser:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
- name: Set up Go
27+
uses: actions/setup-go@v5
28+
with:
29+
go-version: "1.24"
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to Container Registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
# More assembly might be required: Docker logins, GPG, etc.
40+
# It all depends on your needs.
41+
- name: Run GoReleaser
42+
uses: goreleaser/goreleaser-action@v6
43+
with:
44+
distribution: goreleaser
45+
# 'latest', 'nightly', or a semver
46+
version: "~> v2"
47+
args: release --clean
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

goreleaser.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
project_name: dns-sync
2+
builds:
3+
- goos:
4+
- linux
5+
- windows
6+
- darwin
7+
goarch:
8+
- amd64
9+
- arm64
10+
dockers:
11+
- image_templates: ["ghcr.io/flanksource/dns-sync:{{ .Version }}"]
12+
dockerfile: Dockerfile
13+
build_flag_templates:
14+
- --label=org.opencontainers.image.title={{ .ProjectName }}
15+
- --label=org.opencontainers.image.description={{ .ProjectName }}
16+
- --label=org.opencontainers.image.url=https://github.com/flanksource/dns-sync
17+
- --label=org.opencontainers.image.source=https://github.com/flanksource/dns-sync
18+
- --label=org.opencontainers.image.version={{ .Version }}
19+
- --label=org.opencontainers.image.created={{ time "2006-01-02T15:04:05Z07:00" }}
20+
- --label=org.opencontainers.image.revision={{ .FullCommit }}
21+
- --label=org.opencontainers.image.licenses=Apache-2.0
22+
nfpms:
23+
- maintainer: Carlos A Becker <root@carlosbecker.dev>
24+
description: Sample project.
25+
homepage: https://github.com/caarlos0/tasktimer
26+
license: MIT
27+
formats:
28+
- deb
29+
- rpm
30+
- apk

0 commit comments

Comments
 (0)