-
Notifications
You must be signed in to change notification settings - Fork 22
172 lines (151 loc) · 6.55 KB
/
obs_build.yml
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
---
name: OBS Scratch Build
on:
pull_request:
jobs:
obs-build:
name: build all images on OBS
runs-on: ubuntu-latest
container: ghcr.io/dcermak/bci-ci:latest
strategy:
fail-fast: false
matrix:
os_version:
- 7
- 6
- "16.0"
- Tumbleweed
steps:
# we need all branches for the build checks
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.CHECKOUT_TOKEN }}
- uses: actions/cache@v4
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}
- name: fix the file permissions of the repository
run: chown -R $(id -un):$(id -gn) .
- name: install python dependencies
run: poetry install
- name: find the previous comment created by the bot
uses: peter-evans/find-comment@v3
id: find_comment
with:
issue-number: ${{ github.event.number }}
body-includes: "Created a staging project on OBS for ${{ matrix.os_version }}"
direction: last
- name: cleanup the previously created staging project & branch
run: echo "${{ steps.find_comment.outputs.comment-body }}" | poetry run scratch-build-bot -vvvv --from-stdin cleanup
shell: fish {0}
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: steps.find_comment.outputs.comment-id != ''
- name: update the comment with the previous build explaining that it has been deleted
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
body: "⚠️⚠️ Project and Branch have been deleted ⚠️⚠️"
edit-mode: append
if: steps.find_comment.outputs.comment-id != ''
- name: configure git user
run: |
set -xuo pipefail
username="${{ github.event.pull_request.user.login }}"
set +e
full_name=$(curl https://api.github.com/users/$username 2>/dev/null|jq '.name'|sed 's|"||g')
if [[ $? -ne 0 ]]; then
git config user.name "SUSE Update Bot"
git config user.email "[email protected]"
else
git config user.name "$full_name"
git config user.email "[email protected]"
fi
- name: commit the changes to a test branch and create a staging project on OBS
run: |
set -euo pipefail
poetry run scratch-build-bot \
--os-version ${{ matrix.os_version }} \
--branch-name="${{ matrix.os_version }}-${{ github.event.pull_request.number }}" \
-vvvv \
scratch_build \
--commit-message='Test build for #${{ github.event.pull_request.number }}' \
| tee info
if grep -q "No changes" info; then
echo "no_change=true" >> $GITHUB_ENV
else
echo "DEPLOYMENT_COMMIT_HASH=$(cat info)" >> $GITHUB_ENV
fi
cat test-build.env >> $GITHUB_ENV
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
- name: create a comment with a link to the staging project
if: env.no_change != 'true'
uses: peter-evans/create-or-update-comment@v4
id: create_comment
with:
comment-id: ${{ steps.find_comment.outputs.comment-id || '' }}
edit-mode: replace
issue-number: ${{ github.event.pull_request.number }}
# !!! if you change the body, then you must adjust StagingBot.from_github_comment() !!!
body: |
Created a staging project on OBS for ${{ matrix.os_version }}: [${{ env.PROJECT_NAME }}](${{ env.PROJECT_URL }})
Changes pushed to branch [`${{ env.BRANCH_NAME }}`](https://github.com/SUSE/BCI-dockerfile-generator/tree/${{ env.BRANCH_NAME }}) as commit [`${{ env.DEPLOYMENT_COMMIT_HASH }}`](https://github.com/SUSE/BCI-dockerfile-generator/commit/${{ env.DEPLOYMENT_COMMIT_HASH }})
- name: wait for the build to finish
run: poetry run scratch-build-bot -vvvv wait
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: env.no_change != 'true'
- name: Install crane to list images on the registry
uses: imjasonh/[email protected]
if: env.no_change != 'true'
- name: retrieve the build result
run: |
set -euo pipefail
export PROJECT_NAME=${{ env.PROJECT_NAME }}
export REGISTRY_PREFIX=$(echo ${PROJECT_NAME,,} | sed 's|:|/|g')
export TEST_OS_VER=${{ env.OS_VERSION_PRETTY }}
export TEST_OS_VER=$(echo ${TEST_OS_VER/SP/15.})
echo "build_res<<EOF" >> $GITHUB_ENV
poetry run scratch-build-bot query_build_result >> $GITHUB_ENV
echo >> $GITHUB_ENV
echo >> $GITHUB_ENV
echo "To run [BCI-tests](https://github.com/SUSE/BCI-tests) against this PR, use the following command:" >> $GITHUB_ENV
echo "\`\`\`bash" >> $GITHUB_ENV
echo "OS_VERSION=${TEST_OS_VER,,} TARGET=custom BASEURL=registry.opensuse.org/${REGISTRY_PREFIX}/ tox -- -n auto" >> $GITHUB_ENV
echo "\`\`\`" >> $GITHUB_ENV
echo >> $GITHUB_ENV
echo >> $GITHUB_ENV
poetry run scratch-build-bot get_container_urls >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
id: query_build_result
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: env.no_change != 'true'
- name: report the finished build
if: env.no_change != 'true'
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.create_comment.outputs.comment-id }}
body: ${{ env.build_res }}
edit-mode: append
reactions: rocket
- name: fail the job if the builds failed
run: poetry run scratch-build-bot get_build_quality
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: env.no_change != 'true'
- name: cleanup the branches if no functional changes were commited or the build was cancelled
run: poetry run scratch-build-bot -vvvv -l cleanup
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: ${{ env.no_change == 'true' || cancelled() }}