-
Notifications
You must be signed in to change notification settings - Fork 54
209 lines (182 loc) · 8.96 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
name: Build, Test, Automerge and Tag
# This workflow runs on all PRs that are targetting the main branch.
#
# It runs the test suite. If the PR is a release PR, it automerges and tags the main branch with
# the corresonding new version.
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches: [ main ]
jobs:
build-test-release:
name: Build artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout main branch
uses: actions/checkout@v4
- name: Checkout PR branch
uses: actions/checkout@v4
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@v5
with:
go-version-file: ./chart-verifier/go.mod
- name: Ensure Modules
working-directory: ./chart-verifier
run: make tidy
- 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@v5
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")" | tee -a $GITHUB_OUTPUT
shell: bash
- uses: actions/cache@v4
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 podman Image
working-directory: ./chart-verifier
id: build_podman_image
run: |
# build a podman image
image_tag="test"
echo "Building container image using podman for the tests, tagging as $image_tag"
make build-image IMAGE_TAG=$image_tag
podman build -t quay.io/redhat-certification/chart-verifier:$image_tag .
echo "podman_image_tag=$image_tag" | tee -a $GITHUB_OUTPUT
- name: Create tarfile
id: create-tarfile
working-directory: ./chart-verifier
run: |
# create test tarball for the tests
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_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@v4
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: Get main branch sha
id: main_sha
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
run: |
git fetch
export ORIGIN_MAIN_SHA=$(git rev-parse origin/main)
echo "origin_main_sha=$ORIGIN_MAIN_SHA" | tee -a $GITHUB_OUTPUT
- name: Create release tag
id: create_release_tag
if: ${{ steps.check_version_updated.outputs.updated == 'true'}}
uses: mathieudutour/[email protected]
with:
# It is necessary to use a Personal Access Token here rather than the usual GITHUB_TOKEN, as this
# step should trigger the release.yaml workflow, and events (such as tags) triggered by the
# GITHUB_TOKEN cannot create a new workflow run. See:
# https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow
# This Personal Access Token belongs to the openshift-helm-charts-bot account.
github_token: ${{ secrets.GH_HELM_BOT_TOKEN }}
custom_tag: ${{ steps.check_version_in_PR.outputs.PR_version }}
tag_prefix: ""
commit_sha: ${{ steps.main_sha.outputs.origin_main_sha }}