-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (82 loc) · 2.34 KB
/
main.yml
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
name: main
run-name: ${{ github.actor }} - Testing and publishing
on:
push:
paths-ignore:
- '*.md'
- '**/*.md'
env:
GOLANG_VERSION: "1.21"
REGISTRY_IMAGE_NAME: "crm-back"
jobs:
prepare:
name: Prepare variables
runs-on: ubuntu-latest
outputs:
version: ${{ steps.prepare.outputs.version }}
commit: ${{ steps.prepare.outputs.commit }}
branch: ${{ steps.prepare.outputs.branch }}
tag: ${{ steps.prepare.outputs.tag }}
steps:
- name: Prepare variables
id: prepare
shell: bash
run: |
BRANCH=$(echo ${GITHUB_REF#refs/heads/} | tr '\' '-')
COMMIT_SHA_SHORT=$(echo ${GITHUB_SHA} | cut -c1-7)
VERSION=$(echo ${BRANCH}-${COMMIT_SHA_SHORT})
TAG=$(echo ${GITHUB_REF#refs/*/})
echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "commit=${COMMIT_SHA_SHORT}" >> $GITHUB_OUTPUT
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
echo version: $VERSION
echo commit: $COMMIT_SHA_SHORT
echo branch: $BRANCH
echo tag: $TAG
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
args: "--fix=false"
test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'
- name: Caches
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: |
go mod download
- name: Check tidiness
run: |
touch .env
make tidy
if [[ $(git diff --stat) != '' ]]; then
git diff
echo 'run `make tidy` and commit changes'
exit 1
fi
- name: Run unit tests
run: |
make test