1+ name : Go CI
2+
3+ on :
4+ push :
5+ branches : [ master, lab03 ]
6+ paths :
7+ - ' app_go/**'
8+ - ' .github/workflows/go-ci.yml'
9+ pull_request :
10+ branches : [ master ]
11+ paths :
12+ - ' app_go/**'
13+
14+ jobs :
15+ test :
16+ name : Test Go Application
17+ runs-on : ubuntu-latest
18+
19+ steps :
20+ - name : Checkout code
21+ uses : actions/checkout@v4
22+
23+ - name : Set up Go
24+ uses : actions/setup-go@v5
25+ with :
26+ go-version : ' 1.23'
27+ cache-dependency-path : app_go/go.sum
28+
29+ - name : Install dependencies
30+ working-directory : ./app_go
31+ run : go mod download
32+
33+ - name : Run gofmt
34+ working-directory : ./app_go
35+ run : |
36+ gofmt -l .
37+ test -z "$(gofmt -l .)"
38+
39+ - name : Run go vet
40+ working-directory : ./app_go
41+ run : go vet ./...
42+
43+ - name : Run tests
44+ working-directory : ./app_go
45+ run : go test -v ./...
46+
47+ docker :
48+ name : Build and Push Docker Image
49+ runs-on : ubuntu-latest
50+ needs : test
51+ if : github.event_name == 'push'
52+
53+ steps :
54+ - name : Checkout code
55+ uses : actions/checkout@v4
56+
57+ - name : Set up Docker Buildx
58+ uses : docker/setup-buildx-action@v3
59+
60+ - name : Log in to Docker Hub
61+ uses : docker/login-action@v3
62+ with :
63+ username : ${{ secrets.DOCKERHUB_USERNAME }}
64+ password : ${{ secrets.DOCKERHUB_TOKEN }}
65+
66+ - name : Extract metadata
67+ id : meta
68+ uses : docker/metadata-action@v5
69+ with :
70+ images : ${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service-go
71+ tags : |
72+ type=raw,value=latest
73+ type=sha,prefix={{date 'YYYY.MM.DD'}}-
74+
75+ - name : Build and push
76+ uses : docker/build-push-action@v6
77+ with :
78+ context : ./app_go
79+ push : true
80+ tags : ${{ steps.meta.outputs.tags }}
81+ labels : ${{ steps.meta.outputs.labels }}
82+ cache-from : type=gha
83+ cache-to : type=gha,mode=max
0 commit comments