-
Notifications
You must be signed in to change notification settings - Fork 124
99 lines (98 loc) · 3.46 KB
/
ci_any_pr.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
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
## TODO:: Post comment on correct ways to resolve the build errors
name: "Continuous Integration - Pull Request"
on:
pull_request:
branches:
- main
jobs:
# Run static code tests: license-check, terraform format, Golang linting
static-code-tests:
runs-on: [self-hosted, runner-nov-22]
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- name: License Check
run: |
addlicense -check -ignore anthos-bm-openstack-terraform/resources/cloud-config.yaml ./
- name: Terraform Checkstyle
timeout-minutes: 20
run: |
tfenv use 1.9.5
terraform fmt -recursive -check -diff ./
- name: Golang Checkstyle
timeout-minutes: 20
run: |
golint ./... > golint.err 2>&1
if ! [ -s golint.err ]; then
exit 0
fi
if ! grep -q '"./..." matched no packages' "golint.err"; then
echo '[✘] Some .go files are not properly formatted. Check for lint errors using (golint ./...)'
cat golint.err
exit 1
fi
# Run terraform validate on terraform based samples
tf-validate:
runs-on: [self-hosted, runner-nov-22]
strategy:
matrix:
# list of directories in the repo that hosts Terraform samples
# update this list as new terraform samples are added to the repo
tf-sample: [
'anthos-attached-clusters',
'anthos-bm-gcp-terraform',
'anthos-bm-openstack-terraform',
'anthos-multi-cloud/AWS',
'anthos-multi-cloud/Azure'
]
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- name: Terraform Validate
timeout-minutes: 20
env:
SAMPLE_DIR: ${{ matrix.tf-sample }}
run: |
echo "Terraform validating: $SAMPLE_DIR"
cd $SAMPLE_DIR
tfenv use 1.9.5
terraform init -backend=false
terraform validate -json .
# Run the Golang unit tests in any of the samples
go-unit-tests:
runs-on: [self-hosted, runner-nov-22]
strategy:
matrix:
# list of directories in the repo that hosts Golang unit tests
# update this list as new unit tests in golang are added to the repo
go-test-dir: ['anthos-bm-gcp-terraform/test/unit/']
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
with:
go-version-file: ${{ matrix.go-test-dir }}/../go.mod
- name: Golang unit tests
timeout-minutes: 20
env:
GOLANG_TEST_DIR: ${{ matrix.go-test-dir }}
run: |
source /var/local/gh-runner/env_vars
cd $GOLANG_TEST_DIR
/usr/local/go/bin/go test -v -timeout 30m ./