-
Notifications
You must be signed in to change notification settings - Fork 40
154 lines (148 loc) · 5.59 KB
/
ci.yaml
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
# This runs checks to verify if code is properly formated and that tests (unit and integration against a mocked environment) are passing.
name: Lint & Test
on:
push:
branches:
- main
paths-ignore:
- '*.md'
- '.github/*.md'
- '.openapi-generator-ignore'
- 'docs/**'
- 'pkg/api/openapi/docs/**'
- 'pkg/api/openapi/.openapi-generator-ignore'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths-ignore:
- '*.md'
- '.github/*.md'
- '.openapi-generator-ignore'
- 'docs/**'
- 'pkg/api/openapi/docs/**'
- 'pkg/api/openapi/.openapi-generator-ignore'
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request'}}
env:
# set ocm env to integration
OCM_ENV: integration
# GORM env variables. These values are defined in the postgres service definition above
GORM_DIALECT: postgres
GORM_HOST: 127.0.0.1
GORM_PORT: 5432
GORM_NAME: serviceapitests
GORM_USERNAME: kas_fleet_manager
GORM_PASSWORD: foobar-bizz-buzz
GORM_SSLMODE: disable
GORM_DEBUG: false
# Dummy MAS SSO variables
MAS_SSO_CLIENT_ID: kas-fleet-manager
MAS_SSO_CLIENT_SECRET: kas-fleet-manager
OSD_IDP_MAS_SSO_CLIENT_ID: kas-fleet-manager
OSD_IDP_MAS_SSO_CLIENT_SECRET: kas-fleet-manager
# Dummy AWS credentials
AWS_ACCOUNT_ID: aws_accountid
AWS_ACCESS_KEY: aws_accesskey
AWS_SECRET_ACCESS_KEY: aws_secretaccesskey
ROUTE53_ACCESS_KEY: aws_route53_access_key
ROUTE53_SECRET_ACCESS_KEY: aws_route53_secret_access_key
# Dummy Kafka TLS env variables
KAFKA_TLS_CERT: kafka_tls_cert
KAFKA_TLS_KEY: kafka_tls_key
# So that OCM secrets are initialised
DOCKER_PR_CHECK: true
TEST_TIMEOUT: 30m
jobs:
lint-test:
if: "github.event_name != 'pull_request' || github.event.pull_request.draft == false"
name: "Lint & Test"
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.13
env:
POSTGRES_PASSWORD: foobar-bizz-buzz
POSTGRES_USER: kas_fleet_manager
POSTGRES_DB: serviceapitests
ports:
- 5432:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
--name kas-fleet-manager-db
keycloak:
image: quay.io/keycloak/keycloak:17.0.1-legacy
env:
DB_VENDOR: h2
KEYCLOAK_USER: admin
KEYCLOAK_PASSWORD: admin
ports:
- 8180:8080
options: --health-cmd "curl -f http://localhost:8080/auth/realms/master" --health-interval 40s --health-retries 8 --health-timeout 60s
steps:
- name: Check out code under the $GITHUB_WORKSPACE directory
uses: actions/checkout@v3
- name: Set up Go 1.19.6
uses: actions/setup-go@v4
with:
go-version: "1.19.6"
- uses: dorny/paths-filter@v2
id: filter
with:
base: main
list-files: json
filters: |
openapi:
- 'openapi/*.yaml'
- name: Increase Postgres max_connections limit
run: docker exec -i kas-fleet-manager-db /bin/bash docker-entrypoint.sh psql -U kas_fleet_manager -d serviceapitests -c 'alter system set max_connections=200;'
- name: Restart Postgres container
run: docker restart --time 0 kas-fleet-manager-db
- name: Setup Keycloak realm config
run: make sso/config
- name: Run Golang-ci linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
skip-cache: true
only-new-issues: false
- name: Make sure there is no uncommited autogenerated code
run: ./.github/check_for_uncommitted_generated_code.sh
# Validate OpenAPI spec only when there are changes to the corresponding files
- if: contains(steps.filter.outputs.openapi_files, 'openapi/kas-fleet-manager.yaml') || contains(steps.filter.outputs.openapi_files, 'openapi/kas-fleet-manager-private-admin.yaml') || contains(steps.filter.outputs.openapi_files, 'openapi/connector_mgmt.yaml')
name: Validate KAS Fleet Manager OpenAPI changes
run: make openapi/spec/validate
- name: Run Migration Script
run: make db/migrate
- name: Setup tests secrets
run: |
make ocm/setup aws/setup keycloak/setup redhatsso/setup kafkacert/setup
- name: Lint & Test
run: |
export GOPATH=$(go env GOPATH)
export PATH=${PATH}:$GOPATH/bin
make verify lint/templates binary test test/integration
timeout-minutes: 14
- name: Upload unit tests code coverage to codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.out
flags: unittests # optional
name: codecov-kas-fleet-manager # optional
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)
- name: Validate that kas-fleet-manager images can be built successful.
if: github.event_name == 'pull_request'
run: make image/build
- name: Build and publish image to quay.io
if: github.event_name == 'push'
env:
QUAY_USER_NAME: ${{ secrets.QUAY_BF2_USERNAME }}
QUAY_USER_PASSWORD: ${{ secrets.QUAY_BF2_PASSWORD }}
QUAY_ORG_NAME: "bf2fc6cc711aee1a0c2a82e312df7f2e6b37baa12bd9b1f2fd752e260d93a6f8144ac730947f25caa2bfe6ad0f410da360940ee6d28d6c1688d3822c4055650e"
run: |
chmod +x ./build_deploy.sh
./build_deploy.sh