-
Notifications
You must be signed in to change notification settings - Fork 1
188 lines (172 loc) · 6.27 KB
/
test-tasks.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
184
185
186
187
188
name: ci
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
schedule:
- cron: '0 0 * * *'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
list-apko-images:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.output-images.outputs.images }}
steps:
- uses: actions/checkout@v4
- name: list images
id: output-images
run: |
cd images/apko
echo "images=$(ls *.yaml | sed -e 's/\.yaml$//' | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
build-apko-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: list-apko-images
strategy:
matrix:
image: ${{fromJSON(needs.list-apko-images.outputs.images)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build apko image ${{ matrix.image }}
if: github.event_name == 'pull_request'
uses: distroless/actions/apko-build@main
with:
config: images/apko/${{ matrix.image }}.yaml
tag: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest
- name: Build and publish apko image ${{ matrix.image }}
if: github.event_name != 'pull_request'
uses: distroless/actions/apko-publish@main
with:
config: images/apko/${{ matrix.image }}.yaml
tag: ghcr.io/${{ github.repository }}/${{ matrix.image }}:latest
list-images:
runs-on: ubuntu-latest
outputs:
images: ${{ steps.output-images.outputs.images }}
steps:
- uses: actions/checkout@v4
- name: list images
id: output-images
run: |
echo "images=$(ls images | grep -v apko | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
build-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: list-images
strategy:
matrix:
image: ${{fromJSON(needs.list-images.outputs.images)}}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
images/${{ matrix.image }}/**
- name: changed files
if: steps.changed-files.outputs.any_changed == 'true'
run: |
echo ${{ steps.changed-files.outputs.any_changed }}
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
- name: Log in to the Container registry
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request'
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request'
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ghcr.io/${{ github.repository }}/${{ matrix.image }}
- name: Build and push Docker image
if: steps.changed-files.outputs.any_changed == 'true' || github.event_name != 'pull_request'
uses: docker//build-push-action@v5
with:
context: images/${{ matrix.image }}
platforms: linux/amd64,linux/s390x,linux/ppc64le
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
test:
strategy:
fail-fast: false # Keep running if one leg fails.
matrix:
pipeline-version:
- v0.50.5
- v0.53.3
- latest
runs-on: ubuntu-latest
needs:
- build-images
- build-apko-images
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
# instantiate a KinD (Kubernetes in Docker) cluster, installs `kubectl` and configures the
# `kubeconfig` to reach the local cluster
- uses: helm/[email protected]
with:
cluster_name: kind
wait: 120s
# installs Tekton Pipelines and `tkn` command line, including a local Container-Registry with
# settings to reach it during testing
- uses: openshift-pipelines/setup-tektoncd@v1
with:
pipeline_version: ${{ matrix.pipeline-version }}
- name: run-tests
run: |
set -Eeuo pipefail
exitCode=0
# go-crane-image
kubectl create -f ./go-crane-image/go-crane-image.yaml
kubectl create -f ./go-crane-image/tests/run.yaml
tkn pipelinerun logs -f go-crane-image-test-run
tkn pipelinerun describe go-crane-image-test-run
kubectl get pipelinerun go-crane-image-test-run
status=$(kubectl get pipelinerun go-crane-image-test-run -o json | jq -r '.status.conditions[] | select(.type == "Succeeded") | .status')
if [[ "${status}" != "True" ]]; then
echo "go-crane-image test failed"
kubectl get pipelinerun/go-crane-image-test-run -o yaml
exitCode=1
fi
# go-ko-image
kubectl create -f ./go-ko-image/go-ko-image.yaml
kubectl create -f ./go-ko-image/tests/run.yaml
tkn pipelinerun logs -f go-ko-image-test-run
tkn pipelinerun describe go-ko-image-test-run
kubectl get pipelinerun go-ko-image-test-run
status=$(kubectl get pipelinerun go-ko-image-test-run -o json | jq -r '.status.conditions[] | select(.type == "Succeeded") | .status')
if [[ "${status}" != "True" ]]; then
echo "go-ko-image test failed"
kubectl get pipelinerun/go-ko-image-test-run -o yaml
exitCode=1
fi
exit $exitCode