-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (160 loc) · 5.23 KB
/
tests.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
name: CI
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: goginapi
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
CodeScan:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- name: Checkout Source
uses: actions/checkout@v4
- name: Self sast-scan
uses: AppThreat/sast-scan-action@1.0.2
with:
output: reports
type: go,bash
- name: Upload scan reports
uses: actions/upload-artifact@v3
with:
name: sast-scan-reports
path: reports
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
UnitTest:
needs: codescan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run unit tests
run: go test -v ./...
IntegrationTest:
needs: unittest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run integration tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
Performance_test:
runs-on: ubuntu-latest
env:
NR_ACCOUNTID: ${{secrets.NR_ACCOUNTID}}
NR_APIKEY: ${{secrets.NR_APIKEY}}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup NewRelic Agent
run: |
docker run \
-d --restart unless-stopped \
--name newrelic-statsd \
-h $(hostname) \
-e NR_ACCOUNT_ID=$NR_ACCOUNTID \
-e NR_API_KEY=$NR_APIKEY \
-e NR_EU_REGION=true \
-e NR_LOG_METRICS=true \
-e TAGS="k6Test:PerformanceTest" \
-p 8125:8125/udp \
newrelic/nri-statsd:latest
- name: Docker compose application
run: docker-compose up -d
- name: Download and Installing K6_v32 ...
run: |
curl https://github.com/k6io/k6/releases/download/v0.32.0/k6-v0.32.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
- name: Run Performance test
run: K6_STATSD_ENABLE_TAGS=true ./k6 run --out statsd performance/tests/perf_login_test.js
DockerPublish:
needs: integrationtest
name: DockerPublish
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v4
with:
go-version: ^1.17
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Publish to Registry
uses: docker/build-push-action@v5.0.0
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: dipjyotimetia/goginapi
dockerfile: Dockerfile
tags: latest
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
GithubPublish:
# Ensure test job passes before pushing image.
needs: integrationtest
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Log into registry
run: echo "${{ secrets.DOCKER_PACKAGE }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
- name: Push image
run: |
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION