-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (94 loc) · 2.75 KB
/
main.yml
File metadata and controls
111 lines (94 loc) · 2.75 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
name: goproxy-workflow
on:
push:
branches:
- main
jobs:
run-tests:
runs-on: ubuntu-latest
steps:
- name: Get repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.x'
- name: Install dependencies
run: |
cd src
go mod tidy
- name: Run tests with coverage
run: |
cd src
sudo go test -coverprofile=coverage.txt ./...
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: src/coverage.txt
flags: unittests
fail_ci_if_error: true
version-and-tag:
runs-on: ubuntu-latest
needs: run-tests
steps:
- name: Get repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9
with:
versionSpec: '5.x'
- name: Generate Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.9
- name: Tag and Push Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag $(echo ${{ steps.gitversion.outputs.semver }})
git push origin $(echo ${{ steps.gitversion.outputs.semver }})
build-image:
runs-on: ubuntu-latest
needs: [run-tests, version-and-tag]
steps:
- name: Get repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: 'recursive'
- name: Get Version from Git
id: get_version
run: echo "VERSION=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.x'
- name: Install dependencies
run: |
cd src
go mod tidy
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and Tag Docker Image
env:
VERSION: ${{ env.VERSION }}
run: |
docker build -t nlipatov/goproxy:${VERSION} src
docker tag nlipatov/goproxy:${VERSION} nlipatov/goproxy:latest
- name: Push Docker Images
env:
VERSION: ${{ env.VERSION }}
run: |
docker push nlipatov/goproxy:${VERSION}
docker push nlipatov/goproxy:latest