Skip to content
This repository was archived by the owner on Aug 4, 2024. It is now read-only.

Commit 8a09636

Browse files
Zack StevensZack Stevens
andauthored
fix: Init (#1)
Co-authored-by: Zack Stevens <[email protected]>
1 parent 5b1a1a7 commit 8a09636

File tree

3 files changed

+189
-20
lines changed

3 files changed

+189
-20
lines changed

CHANGELOG.md

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

action.yaml

Lines changed: 176 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,183 @@
1-
name: 'Hello World' # taken from https://docs.github.com/en/actions/creating-actions/creating-a-composite-action
2-
description: 'Greet someone'
1+
name: 'Kind Test'
2+
description: 'Creates a kind cluster, installs helm charts, runs an app via skaffold, and runs tests'
33
inputs:
4-
who-to-greet: # id of input
5-
description: 'Who to greet'
6-
required: true
7-
default: 'World'
8-
outputs:
9-
random-number:
10-
description: "Random number"
11-
value: ${{ steps.random-number-generator.outputs.random-id }}
4+
token:
5+
description: 'Github token, if there are dependencies, this should be a PAT so that the other repos can be cloned'
6+
required: false
7+
default: ${{ github.token }}
8+
ref:
9+
description: 'Git ref to use'
10+
required: false
11+
default: ${{ github.ref }}
12+
test-command:
13+
description: 'What test command to run'
14+
required: false
15+
default: 'go test'
16+
test-working-directory:
17+
description: 'Directory to run tests from'
18+
required: false
19+
default: 'test'
20+
wait-for-ports:
21+
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`'
22+
required: false
23+
default: ''
24+
max-wait:
25+
description: 'Max time in milliseconds to wait for readiness on ports set in `wait-for-ports`'
26+
required: false
27+
default: 300000
28+
check-interval:
29+
description: 'Interval to check readiness on ports set in `wait-for-ports`'
30+
required: false
31+
default: 5000
32+
helm-charts:
33+
description: 'Helm charts to install, a json formatted string, that is a list of objects'
34+
required: false
35+
default: '[]'
36+
credentials-json:
37+
description: 'Gcloud service account credentials json. This is required if you are installing helm charts'
38+
required: false
39+
project-id:
40+
description: 'gcloud project id. This is required if you are installing helm charts'
41+
required: false
42+
region:
43+
description: 'artifact registry region'
44+
required: false
45+
default: 'us-west1'
46+
repository:
47+
description: 'artifact registry repository'
48+
required: false
49+
default: 'charts'
50+
helm-install-wait-timeout:
51+
description: 'How long to wait for installed charts to be healthy before failing'
52+
required: false
53+
default: 3m
54+
dependencies:
55+
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'
56+
required: false
57+
default: ''
58+
sleep:
59+
description: 'Seconds to sleep before running tests'
60+
required: false
61+
default: 10
62+
helm-repo-name:
63+
description: 'Helm repository name to add'
64+
required: false
65+
default: unsupervised
66+
helm-repo-url:
67+
description: 'Helm repository url'
68+
required: false
69+
default: 'https://raw.githubusercontent.com/${{ github.repository_owner }}/charts/main'
70+
helm-repo-username:
71+
description: 'Helm repository username'
72+
required: false
73+
default: ''
74+
helm-repo-password:
75+
description: 'Helm repository password'
76+
required: false
77+
default: ''
1278
runs:
1379
using: "composite"
1480
steps:
15-
- run: echo Hello ${{ inputs.who-to-greet }}.
81+
- name: Checkout
82+
uses: actions/checkout@v2
83+
with:
84+
token: ${{ inputs.token }}
85+
ref: ${{ inputs.ref }}
86+
path: app
87+
- name: Setup Go
88+
if: hashFiles('app/go.mod') != '' # rudimentary file existence check
89+
uses: actions/setup-go@v2
90+
with:
91+
go-version: '1.17.x'
92+
- name: Setup Go Cache
93+
if: hashFiles('app/go.mod') != '' # rudimentary file existence check
94+
uses: actions/cache@v2
95+
with:
96+
# * Module download cache
97+
# * Build cache (Linux)
98+
path: |
99+
~/go/pkg/mod
100+
~/.cache/go-build
101+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
102+
restore-keys: |
103+
${{ runner.os }}-go-
104+
- name: Setup skaffold cache
105+
uses: actions/cache@v2
106+
with:
107+
path: |
108+
~/.skaffold/cache
109+
key: ${{ runner.os }}-skaffold-${{ hashFiles('**/skaffold.yaml') }}
110+
restore-keys: |
111+
${{ runner.os }}-skaffold-
112+
- name: Setup tools
113+
uses: yokawasa/[email protected]
114+
with:
115+
helm: '3.7.2'
116+
skaffold: '1.35.0'
117+
- name: Add helm repository
16118
shell: bash
17-
- id: random-number-generator
18-
run: echo "::set-output name=random-id::$(echo $RANDOM)"
119+
run: |
120+
helm repo add ${{ inputs.helm-repo-name}} ${{ inputs.helm-repo-url}} --username ${{ inputs.helm-repo-username }} --password ${{ inputs.helm-repo-password }}
121+
- name: Set up Docker Buildx
122+
uses: docker/[email protected]
123+
- uses: google-github-actions/auth@v0
124+
with:
125+
credentials_json: ${{ inputs.credentials-json }}
126+
- id: auth
127+
uses: google-github-actions/auth@v0
128+
with:
129+
credentials_json: ${{ inputs.credentials-json }}
130+
- name: Setup gcloud
131+
uses: google-github-actions/[email protected]
132+
with:
133+
project_id: ${{ inputs.project-id }}
134+
- name: Prepare for skaffold and tests
19135
shell: bash
20-
- run: ${{ github.action_path }}/goodbye.sh
136+
run: |
137+
git config --global url."https://${{ inputs.token }}@github.com".insteadOf "https://github.com"
138+
gcloud auth configure-docker ${{ inputs.region }}-docker.pkg.dev
139+
mkdir ${GITHUB_WORKSPACE}/skaffold-logs
140+
- name: Create Kind cluster
141+
uses: engineerd/[email protected]
142+
with:
143+
version: "v0.11.1"
144+
- name: Run Dependencies
145+
if: inputs.dependencies != ''
146+
env:
147+
GITHUB_TOKEN: ${{ inputs.token }}
148+
HELM_EXPERIMENTAL_OCI: 1
149+
GOOGLE_APPLICATION_CREDENTIALS: ${{steps.auth.outputs.credentials_file_path}}
21150
shell: bash
151+
run: ${{ github.action_path }}/run-dependencies.sh ${{ inputs.dependencies }}
152+
- name: Run app via skaffold
153+
env:
154+
SKAFFOLD_ACTIONS: true
155+
HELM_EXPERIMENTAL_OCI: 1
156+
GOOGLE_APPLICATION_CREDENTIALS: ${{steps.auth.outputs.credentials_file_path}}
157+
shell: bash
158+
working-directory: app
159+
run: |
160+
skaffold run --tail --port-forward=user --verbosity=info > ${GITHUB_WORKSPACE}/skaffold-logs/app.txt &
161+
- name: Wait for ready
162+
if: inputs.wait-for-ports != ''
163+
uses: Unsupervisedcom/action-wait-for-ports@v1
164+
with:
165+
ports: ${{ inputs.wait-for-ports }}
166+
max-wait: ${{ inputs.max-wait }}
167+
check-interval: ${{ inputs.check-interval }}
168+
- name: Run tests
169+
shell: bash
170+
working-directory: app/${{ inputs.test-working-directory }}
171+
run: |
172+
sleep ${{ inputs.sleep }}
173+
${{ inputs.test-command }}
174+
- name: Report status on failure
175+
if: failure()
176+
shell: bash
177+
run: |
178+
kubectl get all --all-namespaces
179+
for i in ${GITHUB_WORKSPACE}/skaffold-logs/*.txt
180+
do
181+
echo "logs for $i"
182+
cat $i
183+
done

run-dependencies.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
dependencies=$1
5+
6+
mkdir dependencies && cd dependencies
7+
8+
for i in ${dependencies//,/ }
9+
do
10+
git clone https://${GITHUB_TOKEN}@github.com/Unsupervisedcom/${i}.git
11+
cd $i
12+
skaffold run --tail --port-forward=user --verbosity=info > ${GITHUB_WORKSPACE}/skaffold-logs/${i}.txt &
13+
done

0 commit comments

Comments
 (0)