This repository has been archived by the owner on Aug 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
183 lines (183 loc) · 6.21 KB
/
action.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: 'Kind Test'
description: 'Creates a kind cluster, installs helm charts, runs an app via skaffold, and runs tests'
inputs:
token:
description: 'Github token, if there are dependencies, this should be a PAT so that the other repos can be cloned'
required: false
default: ${{ github.token }}
ref:
description: 'Git ref to use'
required: false
default: ${{ github.ref }}
test-command:
description: 'What test command to run'
required: false
default: 'go test'
test-working-directory:
description: 'Directory to run tests from'
required: false
default: 'test'
wait-for-ports:
description: 'Ports to wait for, used for dependent charts, if those charts need exposed local ports as part of testing. Comma separated list such as `8000,8001`'
required: false
default: ''
max-wait:
description: 'Max time in milliseconds to wait for readiness on ports set in `wait-for-ports`'
required: false
default: 300000
check-interval:
description: 'Interval to check readiness on ports set in `wait-for-ports`'
required: false
default: 5000
helm-charts:
description: 'Helm charts to install, a json formatted string, that is a list of objects'
required: false
default: '[]'
credentials-json:
description: 'Gcloud service account credentials json. This is required if you are installing helm charts'
required: false
project-id:
description: 'gcloud project id. This is required if you are installing helm charts'
required: false
region:
description: 'artifact registry region'
required: false
default: 'us-west1'
repository:
description: 'artifact registry repository'
required: false
default: 'charts'
helm-install-wait-timeout:
description: 'How long to wait for installed charts to be healthy before failing'
required: false
default: 3m
dependencies:
description: 'Other git repos in this organization to clone and run skaffold for. Should be a comma separated list of short repository names, excluding the organization'
required: false
default: ''
sleep:
description: 'Seconds to sleep before running tests'
required: false
default: 10
helm-repo-name:
description: 'Helm repository name to add'
required: false
default: unsupervised
helm-repo-url:
description: 'Helm repository url'
required: false
default: 'https://raw.githubusercontent.com/${{ github.repository_owner }}/charts/main'
helm-repo-username:
description: 'Helm repository username'
required: false
default: ''
helm-repo-password:
description: 'Helm repository password'
required: false
default: ''
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ inputs.token }}
ref: ${{ inputs.ref }}
path: app
- name: Setup Go
if: hashFiles('app/go.mod') != '' # rudimentary file existence check
uses: actions/setup-go@v2
with:
go-version: '1.17.x'
- name: Setup Go Cache
if: hashFiles('app/go.mod') != '' # rudimentary file existence check
uses: actions/cache@v2
with:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Setup skaffold cache
uses: actions/cache@v2
with:
path: |
~/.skaffold/cache
key: ${{ runner.os }}-skaffold-${{ hashFiles('**/skaffold.yaml') }}
restore-keys: |
${{ runner.os }}-skaffold-
- name: Setup tools
uses: yokawasa/action-setup-kube-tools@v0.7.1
with:
helm: '3.7.2'
skaffold: '1.35.0'
- name: Add helm repository
shell: bash
run: |
helm repo add ${{ inputs.helm-repo-name}} ${{ inputs.helm-repo-url}} --username ${{ inputs.helm-repo-username }} --password ${{ inputs.helm-repo-password }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.6.0
- uses: google-github-actions/auth@v0
with:
credentials_json: ${{ inputs.credentials-json }}
- id: auth
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ inputs.credentials-json }}
- name: Setup gcloud
uses: google-github-actions/setup-gcloud@v0.3.0
with:
project_id: ${{ inputs.project-id }}
- name: Prepare for skaffold and tests
shell: bash
run: |
git config --global url."https://${{ inputs.token }}@github.com".insteadOf "https://github.com"
gcloud auth configure-docker ${{ inputs.region }}-docker.pkg.dev
mkdir ${GITHUB_WORKSPACE}/skaffold-logs
- name: Create Kind cluster
uses: engineerd/setup-kind@v0.5.0
with:
version: "v0.11.1"
- name: Run Dependencies
if: inputs.dependencies != ''
env:
GITHUB_TOKEN: ${{ inputs.token }}
HELM_EXPERIMENTAL_OCI: 1
GOOGLE_APPLICATION_CREDENTIALS: ${{steps.auth.outputs.credentials_file_path}}
shell: bash
run: ${{ github.action_path }}/run-dependencies.sh ${{ inputs.dependencies }}
- name: Run app via skaffold
env:
SKAFFOLD_ACTIONS: true
HELM_EXPERIMENTAL_OCI: 1
GOOGLE_APPLICATION_CREDENTIALS: ${{steps.auth.outputs.credentials_file_path}}
shell: bash
working-directory: app
run: |
skaffold run --tail --port-forward=user --verbosity=info > ${GITHUB_WORKSPACE}/skaffold-logs/app.txt &
- name: Wait for ready
if: inputs.wait-for-ports != ''
uses: Unsupervisedcom/action-wait-for-ports@v1
with:
ports: ${{ inputs.wait-for-ports }}
max-wait: ${{ inputs.max-wait }}
check-interval: ${{ inputs.check-interval }}
- name: Run tests
shell: bash
working-directory: app/${{ inputs.test-working-directory }}
run: |
sleep ${{ inputs.sleep }}
${{ inputs.test-command }}
- name: Report status on failure
if: failure()
shell: bash
run: |
kubectl get all --all-namespaces
for i in ${GITHUB_WORKSPACE}/skaffold-logs/*.txt
do
echo "logs for $i"
cat $i
done