-
Notifications
You must be signed in to change notification settings - Fork 10
169 lines (156 loc) · 5.96 KB
/
Copy pathtest-promise.yaml
File metadata and controls
169 lines (156 loc) · 5.96 KB
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
name: Test Promise
on:
workflow_dispatch:
inputs:
promise-dir:
type: string
description: The directory containing the promise to test
push:
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.changed.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- id: changed
run: |
if [ -n "${{ inputs.promise-dir }}" ]; then
matrix=$(echo '${{ inputs.promise-dir }}' | jq -Rnc '[inputs]')
else
matrix=$(git diff --name-only HEAD~1 HEAD \
| grep -oE '^[^/]+' \
| sort -u \
| while read dir; do [ -f "$dir/promise.yaml" ] && echo "$dir"; done \
| jq -Rnc '[inputs]')
fi
echo "matrix=$matrix" >> $GITHUB_OUTPUT
echo "changed promises: $matrix"
test-promise:
needs: detect-changes
if: needs.detect-changes.outputs.matrix != '[]'
strategy:
matrix:
promise_dir: ${{ fromJson(needs.detect-changes.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- name: Checkout Kratix Marketplace repository
uses: actions/checkout@v4
- name: Install Kind
uses: helm/kind-action@v1
with:
install_only: true
version: v0.29.0
- name: Checkout Kratix repository
uses: actions/checkout@v4
with:
repository: syntasso/kratix
path: kratix
ref: latest
- name: Deploy Kratix
working-directory: kratix
run: |
make quick-start
./scripts/register-destination --name platform-cluster --context kind-platform --state-store default --with-label environment=platform
kubectl wait --for condition=available -n kratix-platform-system deployment/kratix-platform-controller-manager --timeout 60s
- name: Install Promise
working-directory: ${{ matrix.promise_dir }}
run: |
if test -f ./internal/scripts/pipeline-image; then
./internal/scripts/pipeline-image build load
fi
if test -f "internal/scripts/pre-test"; then
./internal/scripts/pre-test
fi
kubectl create --filename promise.yaml
- name: Test Promise
working-directory: ${{ matrix.promise_dir }}
run: |
for i in $(seq 1 100); do
./internal/scripts/test promise && exit 0
sleep 6
done
echo "test failed after 100 attempts, exiting"
exit 1
- name: Wait for CRDs
working-directory: ${{ matrix.promise_dir }}
run: |
if test -f "resource-request.yaml"; then
crd=$(yq e 'select(.kind == "Promise") | .spec.api.metadata.name' promise.yaml)
while ! kubectl get crd ${crd} 2>/dev/null; do
sleep 1
done
kubectl wait crd/${crd} --for condition=established --timeout=60s
fi
- name: Apply Resource Request
working-directory: ${{ matrix.promise_dir }}
run: |
if test -f "resource-request.yaml"; then
kubectl apply --filename resource-request.yaml
fi
- name: Test Resource Request
working-directory: ${{ matrix.promise_dir }}
run: |
for i in $(seq 1 100); do
./internal/scripts/test resource-request && exit 0
sleep 10
done
echo "test failed after 100 attempts, exiting"
exit 1
- name: Delete Resource Request
working-directory: ${{ matrix.promise_dir }}
run: |
if test -f "resource-request.yaml"; then
kubectl delete --filename resource-request.yaml
fi
- name: Test Resource Request Deletion
working-directory: ${{ matrix.promise_dir }}
run: |
if ! test -f "internal/scripts/test-delete"; then
echo "no test-delete file found, exiting"
exit 0
fi
for i in $(seq 1 100); do
./internal/scripts/test-delete && exit 0
sleep 6
done
echo "delete-test failed after 100 attempts, exiting"
exit 1
- name: Docker login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Docker (Pinned)
uses: docker/setup-docker-action@v4
with:
version: 29.1.5
- name: Push Image
if: ${{ github.ref == 'refs/heads/main' }}
working-directory: ${{ matrix.promise_dir }}
run: |
./internal/scripts/pipeline-image push
- name: Verify package is public
if: ${{ github.ref == 'refs/heads/main' }}
working-directory: ${{ matrix.promise_dir }}
run: |
if test -f "internal/configure-pipeline/Dockerfile"; then
resource_image=$(yq 'select(document_index == 0) | .spec.workflows.resource.configure[0].spec.containers[0].image' promise.yaml | cut -d "/" -f 3,4 | cut -d ":" -f 1)
promise_image=$(yq 'select(document_index == 0) | .spec.workflows.promise.configure[0].spec.containers[0].image' promise.yaml | cut -d "/" -f 3,4 | cut -d ":" -f 1)
for image in $resource_image $promise_image; do
if [ "$image" != "null" ]; then
visibility=$(curl -sL \
-H "Accept: application/vnd.github+json"\
-H "Authorization: Bearer $GHCR_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/orgs/syntasso/packages?package_type=container&per_page=150" |
jq -r ".[] | select(.name | contains (\"${image}\")) | .visibility")
test "${visibility}" = "public"
fi
done
fi
env:
GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}