@@ -2,22 +2,17 @@ name: CI/CD Pipeline
22
33on :
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
149jobs :
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
0 commit comments