-
Notifications
You must be signed in to change notification settings - Fork 54
253 lines (219 loc) · 10.8 KB
/
build.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
name: Build, Test and Release
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches: [ main ]
jobs:
build:
name: Build artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v3
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
path: "chart-verifier"
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Ensure Modules
working-directory: ./chart-verifier
run: make tidy
- name: Ensure Formatting
working-directory: ./chart-verifier
run: make fmt
- name: Run Linters
working-directory: ./chart-verifier
run: make lint
- name: Build Binary
working-directory: ./chart-verifier
run: make bin
- name: Run tests
working-directory: ./chart-verifier
run: |
# Run go tests
make test
if [[ ! -z $(git status -s) ]]
then
echo "go test - errors running go tests : $(git status -s)"
exit 1
fi
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Set up Python scripts on PR branch
working-directory: ./chart-verifier
run: |
# set up python requirements and scripts on PR branch
python3 -m venv ve1
cd scripts && ../ve1/bin/pip3 install -r requirements.txt && cd ..
cd scripts && ../ve1/bin/python3 setup.py install && cd ..
- name: Check if only release file in PR
working-directory: ./chart-verifier
id: check_version_in_PR
run: |
# check if release file only is included in PR
ve1/bin/release-checker --api-url=${{ github.event.pull_request._links.self.href }}
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v2
id: cache
with:
path: ./chart-verifier/oc
key: ${{ steps.get-date.outputs.date }}
- name: Install oc
working-directory: ./chart-verifier
id: install-oc
run: |
# install oc
curl -sLO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
tar zxvf openshift-client-linux.tar.gz oc
- name: Build the Image
working-directory: ./chart-verifier
id: build_image
run: |
# build a docker image
commit_sha=$(git rev-parse --short HEAD)
ve1/bin/build-and-test --image-name="quay.io/redhat-certification/chart-verifier" --sha-value=$commit_sha --build-only="True"}
- name: Build podman Image
working-directory: ./chart-verifier
id: build_podman_image
run: |
# build a podman image
# sudo apt install qemu-system-x86
commit_sha=$(git rev-parse --short HEAD)
image_tag="podman-"$commit_sha
echo "use image tag $image_tag"
podman build -t quay.io/redhat-certification/chart-verifier:$image_tag .
echo "podman_image_tag=$image_tag" >> $GITHUB_OUTPUT
- name: Create tarfile
id: create-tarfile
working-directory: ./chart-verifier
run: |
# check if release file only is included in PR
ve1/bin/tar-file --release="test"
- name: Login to oc
working-directory: ./chart-verifier
env:
KUBECONFIG: /tmp/ci-kubeconfig
run: |
# oc login
API_SERVER=$( echo -n ${{ secrets.API_SERVER }} | base64 -d)
gpg --version
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
if [ $GITHUB_REPOSITORY == "redhat-certification/chart-verifier" ]; then
# TODO: temporarily allow for skipping TLS verification as the new cluster uses local-only certificates
# This if logic isn't removed to remind us to come back and swap this out when a valid cert is put in place.
./oc login --insecure-skip-tls-verify --token=${{ secrets.CLUSTER_TOKEN }} --server=${API_SERVER}
else
./oc login --insecure-skip-tls-verify --token=${{ secrets.CLUSTER_TOKEN }} --server=${API_SERVER}
fi
ve1/bin/sa-for-chart-testing --create charts-${{ github.event.number }} --token token.txt --server ${API_SERVER}
- name: Run the tests
working-directory: ./chart-verifier
env:
KUBECONFIG: /tmp/ci-kubeconfig
VERIFIER_IMAGE_TAG: ${{ steps.build_image.outputs.verifier-image-tag }}
VERIFIER_TARBALL_NAME : ${{ steps.create-tarfile.outputs.tarball_full_name }}
PODMAN_IMAGE_TAG : ${{ steps.build_podman_image.outputs.podman_image_tag }}
id: run_test
run: |
# run pytest
ve1/bin/pytest -v --log-cli-level=WARNING --tb=short
- name: Delete Namespace
if: ${{ always() && steps.install-oc.conclusion == 'success' }}
working-directory: ./chart-verifier
env:
KUBECONFIG: /tmp/ci-kubeconfig
run: |
# delete the namespace
API_SERVER=$( echo -n ${{ secrets.API_SERVER }} | base64 -d)
./oc login --token=${{ secrets.CLUSTER_TOKEN }} --server=${API_SERVER}
ve1/bin/sa-for-chart-testing --delete charts-${{ github.event.number }}
- name: Set up Python scripts on main branch
run: |
# set up python requirements and scripts on main branch
echo $(pwd)
python3 -m venv ve1
cd scripts && ../ve1/bin/pip3 install -r requirements.txt && cd ..
cd scripts && ../ve1/bin/python3 setup.py install && cd ..
- name: Check for restricted files and user permissiom
id: check_authorization
run: |
# check for a restricted file and, if found, check user has permissiom
ve1/bin/check-user --api-url=${{ github.event.pull_request._links.self.href }} --user=${{ github.event.pull_request.user.login }}
- name: Check if version updated
id: check_version_updated
if: ${{ steps.check_version_in_PR.outputs.PR_includes_release == 'true' }}
run: |
# check if version file was changed
ve1/bin/release-checker --version=${{ steps.check_version_in_PR.outputs.PR_version }}
- name: Approve PR
id: approve_pr
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
uses: hmarr/auto-approve-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Merge PR
id: merge_pr
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
uses: pascalgn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MERGE_METHOD: squash
MERGE_LABELS: ""
- name: Check for PR merge
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
run: |
ve1/bin/check-auto-merge --api-url=${{ github.event.pull_request._links.self.href }}
- name: Create the the release
id: create_release
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.check_version_in_PR.outputs.PR_version }}
body: ${{ steps.check_version_in_PR.outputs.PR_release_body }}
files: ${{ steps.check_version_in_PR.outputs.PR_tarball_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait for image build to complete
# Quay is configured to automatically build our image. This waits
# for it to complete before proceeding successfully.
id: wait_for_image_build
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
run:
expectedImage=quay.io/redhat-certification/chart-verifier:${{ steps.check_version_in_PR.outputs.PR_version }}
for i in {1..30}; do
s=60
echo "Querying Quay for "${expectedImage}" in ${s} seconds..."
sleep $s
skopeo inspect docker://"${expectedImage}" && echo "Image Found!" && exit 0
done
echo "ERR Image not found in allotted time."
exit 1
- name: Login to Quay as Bot
id: login_as_bot
if: ${{ steps.wait_for_image_build.outcome == 'success'}}
uses: redhat-actions/podman-login@v1
with:
username: ${{ secrets.QUAY_BOT_USERNAME }}
password: ${{ secrets.QUAY_BOT_TOKEN }}
registry: quay.io/redhat-certification
- name: Update latest tag
if: ${{ steps.login_as_bot.outcome == 'success'}}
id: update_latest_tag
# TODO: When we shift to a push-from-this-repo model (instead of Quay build model)
# we should transition this tag workflow to use the digest of the image built here in CI.
run: |
imageReference=quay.io/redhat-certification/chart-verifier
podman pull ${imageReference}:${{ steps.check_version_in_PR.outputs.PR_version }}
podman tag ${imageReference}:${{ steps.check_version_in_PR.outputs.PR_version }} ${imageReference}:latest
podman push ${imageReference}:latest