Skip to content

Commit 9f32232

Browse files
authored
Merge pull request #1818 from Adirio/ghactions
🌱 GH Actions
2 parents 097d34e + a9bf0a2 commit 9f32232

File tree

6 files changed

+103
-86
lines changed

6 files changed

+103
-86
lines changed

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
3+
# Trigger the CI on pull requests and direct pushes to any branch
4+
on:
5+
push:
6+
pull_request:
7+
8+
9+
jobs:
10+
11+
lint:
12+
name: Lint
13+
runs-on: ubuntu-latest
14+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
15+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
16+
steps:
17+
- name: Clone the code
18+
uses: actions/checkout@v2
19+
- name: Execute golangci-lint
20+
uses: golangci/golangci-lint-action@v2
21+
with:
22+
version: v1.29 # Always uses the latest patch version.
23+
only-new-issues: true # Show only new issues if it's a pull request
24+
25+
testdata:
26+
name: Verify testdata directory
27+
needs: lint
28+
runs-on: ubuntu-latest
29+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
30+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
31+
steps:
32+
- name: Clone the code
33+
uses: actions/checkout@v2
34+
- name: Setup Go
35+
uses: actions/setup-go@v2
36+
with:
37+
go-version: '^1.15'
38+
# This step is needed as the following one tries to remove
39+
# kustomize for each test but has no permission to do so
40+
- name: Remove pre-installed kustomize
41+
run: sudo rm -f /usr/local/bin/kustomize
42+
- name: Verify testdata directory
43+
run: make check-testdata
44+
45+
test:
46+
name: Test for ${{ matrix.os }}
47+
needs: lint
48+
runs-on: ${{ matrix.os }}
49+
strategy:
50+
matrix:
51+
os: [ubuntu-latest, macos-latest]
52+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
53+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
54+
steps:
55+
- name: Clone the code
56+
uses: actions/checkout@v2
57+
- name: Setup Go
58+
uses: actions/setup-go@v2
59+
with:
60+
go-version: '^1.15'
61+
# This step is needed as the following one tries to remove
62+
# kustomize for each test but has no permission to do so
63+
- name: Remove pre-installed kustomize
64+
run: sudo rm -f /usr/local/bin/kustomize
65+
- name: Perform the test
66+
run: make test
67+
68+
coverage:
69+
name: Code coverage
70+
needs:
71+
- lint
72+
- testdata
73+
- test
74+
runs-on: ubuntu-latest
75+
# Pull requests from the same repository won't trigger this checks as they were already triggered by the push
76+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
77+
steps:
78+
- name: Clone the code
79+
uses: actions/checkout@v2
80+
- name: Setup Go
81+
uses: actions/setup-go@v2
82+
with:
83+
go-version: '^1.15'
84+
- name: Generate the coverage output
85+
run: make test-coverage
86+
- name: Send the coverage output
87+
uses: shogo82148/actions-goveralls@v1
88+
with:
89+
path-to-profile: coverage-all.out

.github/workflows/golangci-lint.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

.github/workflows/verify.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ on:
44
pull_request_target:
55
types: [opened, edited, reopened]
66

7+
78
jobs:
9+
810
verify:
11+
name: Verify PR contents
912
runs-on: ubuntu-latest
10-
name: verify PR contents
1113
steps:
1214
- name: Verifier action
1315
id: verifier

.travis.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

common.sh

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ for p in ${GOPATH//:/ }; do
6262
fi
6363
done
6464

65-
if [ -z $go_workspace ]; then
66-
echo 'Current directory is not in $GOPATH' >&2
67-
exit 1
68-
fi
69-
7065
k8s_version=1.16.4
7166
goarch=amd64
7267
goos="unknown"
@@ -120,7 +115,7 @@ function prepare_staging_dir {
120115
if [ -z "$SKIP_FETCH_TOOLS" ]; then
121116
rm -rf "$kb_root_dir"
122117
else
123-
rm -f "$kb_root_dir/kubebuilder/bin/kubebuilder"
118+
rm -f "$kb_root_dir/bin/kubebuilder"
124119
fi
125120
}
126121

@@ -153,7 +148,7 @@ function build_kb {
153148
opts=-ldflags "-X sigs.k8s.io/kubebuilder/v2/cmd.kubeBuilderVersion=$INJECT_KB_VERSION"
154149
fi
155150

156-
GO111MODULE=on go build $opts -o $tmp_root/kubebuilder/bin/kubebuilder ./cmd
151+
GO111MODULE=on go build $opts -o $kb_root_dir/bin/kubebuilder ./cmd
157152
}
158153

159154
function install_kind {
@@ -175,7 +170,7 @@ function is_installed {
175170
}
176171

177172
function prepare_testdir_under_gopath {
178-
kb_test_dir=${go_workspace}/src/sigs.k8s.io/kubebuilder-test
173+
kb_test_dir=$kb_root_dir/test
179174
header_text "preparing test directory $kb_test_dir"
180175
rm -rf "$kb_test_dir" && mkdir -p "$kb_test_dir" && cd "$kb_test_dir"
181176
header_text "running kubebuilder commands in test directory $kb_test_dir"
@@ -185,11 +180,11 @@ function setup_envs {
185180
header_text "setting up env vars"
186181

187182
# Setup env vars
188-
export PATH=$tmp_root/kubebuilder/bin:$PATH
189-
export TEST_ASSET_KUBECTL=$tmp_root/kubebuilder/bin/kubectl
190-
export TEST_ASSET_KUBE_APISERVER=$tmp_root/kubebuilder/bin/kube-apiserver
191-
export TEST_ASSET_ETCD=$tmp_root/kubebuilder/bin/etcd
192-
export TEST_DEP=$tmp_root/kubebuilder/init_project
183+
export PATH=$kb_root_dir/bin:$PATH
184+
export TEST_ASSET_KUBECTL=$kb_root_dir/bin/kubectl
185+
export TEST_ASSET_KUBE_APISERVER=$kb_root_dir/bin/kube-apiserver
186+
export TEST_ASSET_ETCD=$kb_root_dir/bin/etcd
187+
export TEST_DEP=$kb_root_dir/init_project
193188
}
194189

195190
function cache_project {

test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export GO111MODULE=on
2424

2525
function test_init_project {
2626
header_text "performing init project"
27+
go mod init kubebuilder.io/test
2728
kubebuilder init --domain example.com <<< "n"
2829
}
2930

@@ -103,6 +104,7 @@ function test_project {
103104
prepare_staging_dir
104105
fetch_tools
105106
build_kb
107+
pushd .
106108

107109
setup_envs
108110

@@ -139,7 +141,7 @@ dump_project
139141
test_create_namespaced_coretype_controller
140142

141143
header_text "running kubebuilder unit tests"
142-
cd ${go_workspace}/src/sigs.k8s.io/kubebuilder
144+
popd
143145

144146
export GO111MODULE=on
145147
go test -race -v ./cmd/... ./pkg/... ./plugins/...

0 commit comments

Comments
 (0)