Skip to content

Commit 5fc4fdb

Browse files
authored
Merge pull request #187 from fi-ts/add-test-to-github-workflows
Add test to workflows steps
2 parents 4e6065b + f90f769 commit 5fc4fdb

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

.github/workflows/pull_request.yaml

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,49 @@ jobs:
1212
- name: Checkout
1313
uses: actions/checkout@v2
1414

15+
- name: Ensure Go Version
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: '^1.16'
19+
20+
- name: Lint
21+
uses: golangci/golangci-lint-action@v2
22+
with:
23+
version: v1.32.2
24+
args: --timeout=5m
25+
26+
- name: Get Kubebuilder Version
27+
id: get-kubebuilder-version
28+
run: echo "::set-output name=version::$(make kubebuilder-version-ci)"
29+
shell: bash
30+
31+
- name: Ensure etcd
32+
id: Ensure-etcd
33+
uses: actions/cache@v2
34+
with:
35+
path: ~/go/bin/etcd
36+
key: ${{ runner.os }}-kubebuilder-${{ steps.get-kubebuilder-version.outputs.version }}-etcd
37+
38+
- name: Ensure kube-apiserver
39+
id: ensure-kube-apiserver
40+
uses: actions/cache@v2
41+
with:
42+
path: ~/go/bin/kube-apiserver
43+
key: ${{ runner.os }}-kubebuilder-${{ steps.get-kubebuilder-version.outputs.version }}-kube-apiserver
44+
45+
- name: Ensure Kubebuilder Metadata
46+
id: ensure-kubebuilder-metadata
47+
uses: actions/cache@v2
48+
with:
49+
path: ~/.kubebuilder/${{ steps.get-kubebuilder-version.outputs.version }}
50+
key: ${{ runner.os }}-kubebuilder-${{ steps.get-kubebuilder-version.outputs.version }}
51+
52+
- name: Install Kubebuilder
53+
run: make kubebuilder
54+
55+
- name: Run tests
56+
run: make test
57+
1558
- name: Figure out if running fork PR
1659
id: fork
1760
run: '["${{ secrets.DOCKER_REGISTRY_TOKEN }}" == ""] && echo "::set-output name=is_fork_pr::true" || echo "::set-output name=is_fork_pr::false"'
@@ -24,12 +67,6 @@ jobs:
2467
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
2568
if: steps.fork.outputs.is_fork_pr == 'false'
2669

27-
- name: Lint
28-
uses: golangci/golangci-lint-action@v2
29-
with:
30-
version: v1.32.2
31-
args: --timeout=5m
32-
3370
- name: Build Docker image
3471
run: |
3572
export DOCKER_TAG=pr-${GITHUB_HEAD_REF}

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ all: manager
2828

2929
# Run tests
3030
test: generate fmt vet manifests
31-
go test ./... -coverprofile cover.out -v
31+
KUBEBUILDER_ASSETS=${GOBIN} go test ./... -coverprofile cover.out -v
3232

3333
# todo: Modify Dockerfile to include the version magic
3434
# Build manager binary
@@ -183,3 +183,19 @@ install-configmap-sidecars:
183183
# Todo: Add release version when the changes in main branch are released
184184
crd-cwnp-for-testing:
185185
curl https://raw.githubusercontent.com/metal-stack/firewall-controller/master/config/crd/bases/metal-stack.io_clusterwidenetworkpolicies.yaml -o external/test/crd-clusterwidenetworkpolicy.yaml
186+
187+
KUBEBUILDER_VERSION:=2.3.2
188+
kubebuilder:
189+
ifeq (,$(wildcard ~/.kubebuilder/${KUBEBUILDER_VERSION}))
190+
{ \
191+
os=$$(go env GOOS) ;\
192+
arch=$$(go env GOARCH) ;\
193+
curl -L https://go.kubebuilder.io/dl/${KUBEBUILDER_VERSION}/$${os}/$${arch} | tar -xz -C /tmp/ ;\
194+
mv /tmp/kubebuilder_${KUBEBUILDER_VERSION}_$${os}_$${arch}/bin/* ${GOBIN} ;\
195+
mkdir -p ~/.kubebuilder ;\
196+
touch ~/.kubebuilder/${KUBEBUILDER_VERSION} ;\
197+
}
198+
endif
199+
200+
kubebuilder-version-ci:
201+
@echo ${KUBEBUILDER_VERSION}

0 commit comments

Comments
 (0)