forked from digitalocean/csi-digitalocean
-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (132 loc) · 5.42 KB
/
test.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
155
# Copyright 2022 DigitalOcean
#
# 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.
### Run unit as well as end-to-end tests on PRs and master pushes. For the
### latter, we also push a new CSI plugin master image to the container
### registry.
name: test
env:
DOCKER_ORG: digitalocean
DOCKER_USER: ${{ secrets.DockerHubUser }}
on:
push:
branches:
- master
pull_request:
branches:
jobs:
unit-test:
runs-on: ubuntu-20.04
steps:
- name: checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
fetch-depth: 1
- name: Go setup
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # v3.3.0
with:
go-version-file: go.mod
- name: Run unit tests
run: make all
push-images:
runs-on: ubuntu-20.04
needs: unit-test
steps:
- name: checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
fetch-depth: 1
- name: Log into container registry
run: echo "${{ secrets.DockerHubToken }}" | docker login --username ${DOCKER_USER} --password-stdin
# Github Actions provides a limited amount of disk space only that we
# exceed during the Docker build (https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#supported-runners-and-hardware-resources).
# Free up as much disk space as possible.
- name: free disk space
run: |
sudo swapoff -a
sudo rm -f /swapfile
sudo apt clean
docker system prune -af --volumes
df -h
- name: build and push runner image
env:
# ${{ github.head_ref }} is empty for non-pull requests, which is
# exactly what we want on master.
RUNNER_IMAGE_TAG_PREFIX: ${{ github.head_ref }}
run: RUNNER_IMAGE=${DOCKER_ORG}/k8s-e2e-test-runner make runner-push
- name: Build and push development plugin image
env:
VERSION: ${{ github.head_ref }}
run: |
VERSION="${VERSION:-latest}"
DOCKER_REPO=${DOCKER_ORG}/do-csi-plugin-dev make publish
e2e-test:
runs-on: ubuntu-20.04
needs: push-images
strategy:
matrix:
kube-release: ['1.25', '1.24', '1.23', '1.22']
steps:
- name: checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
fetch-depth: 1
- name: Go setup
uses: actions/setup-go@268d8c0ca0432bb2cf416faae41297df9d262d7f # v3.3.0
with:
go-version-file: go.mod
- name: Install kustomize
env:
KUSTOMIZE_VERSION: '4.4.1'
run: curl -fL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_linux_amd64.tar.gz | sudo tar xzv -C /usr/local/bin kustomize
- name: Run end-to-end tests
env:
DIGITALOCEAN_ACCESS_TOKEN: ${{ secrets.CSIDigitalOceanAccessToken }}
# ${{ github.head_ref }} will be empty for pull requests and non-empty
# for pushes. Handle the cases in "run" below to parameterize our e2e
# test invocation accordingly.
BRANCH: ${{ github.head_ref }}
# Use less ginkgo nodes to avoid running into the DO API rate limit.
# The upstream end-to-end tests are quite demanding in terms of API
# request volume, and we run them concurrently.
NUM_GINKGO_NODES: "8"
run: |
BRANCH=$(echo -n ${BRANCH} | tr -c '[:alnum:]._-' '-')
NAME_SUFFIX="${BRANCH}"
TAG="${BRANCH}"
if [[ $BRANCH != "" ]]; then
# Hash name suffix which goes into the cluster name to ensure we do
# not exceed any name constraints.
NAME_SUFFIX=$(echo -n ${BRANCH} | sha256sum | cut -c1-7)
RUNNER_IMAGE_TAG_PREFIX=${BRANCH}-
else
NAME_SUFFIX=master
TAG=latest
fi
TIMEOUT=60m make test-e2e E2E_ARGS="-ginkgo-nodes ${NUM_GINKGO_NODES} -driver-image ${DOCKER_ORG}/do-csi-plugin-dev:${TAG} -runner-image ${DOCKER_ORG}/k8s-e2e-test-runner:${RUNNER_IMAGE_TAG_PREFIX}latest -name-suffix ${NAME_SUFFIX} -retain ${{ matrix.kube-release }}"
tag-new-master-image:
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/master'
needs: e2e-test
steps:
- name: checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
with:
fetch-depth: 1
- name: Log into container registry
run: echo "${{ secrets.DockerHubToken }}" | docker login --username ${DOCKER_USER} --password-stdin
- name: tag new CSI plugin master image
run: |
docker pull ${DOCKER_ORG}/do-csi-plugin-dev:latest
docker tag ${DOCKER_ORG}/do-csi-plugin-dev:latest ${DOCKER_ORG}/do-csi-plugin:master
docker push ${DOCKER_ORG}/do-csi-plugin:master