Skip to content

Commit c99a0cc

Browse files
committed
Render the templates for LTSS code streams but don't build them on OBS
This fixes #1087
1 parent 77c5794 commit c99a0cc

File tree

4 files changed

+70
-25
lines changed

4 files changed

+70
-25
lines changed

.github/workflows/cleanup-staging.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
- 7
2020
- 6
2121
- 5
22+
- 4
23+
- 3
2224
- "16.0"
2325
- Tumbleweed
2426

@@ -44,7 +46,7 @@ jobs:
4446
id: find_comment
4547
with:
4648
issue-number: ${{ github.event.number }}
47-
body-includes: "Created a staging project on OBS for ${{ matrix.os_version }}: "
49+
body-includes: "Rendered the templates for ${{ matrix.os_version }}: "
4850
direction: last
4951

5052
- name: run the cleanup

.github/workflows/obs_build.yml

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15+
no_build:
16+
- false
1517
os_version:
1618
- 7
1719
- 6
1820
- 5
1921
- "16.0"
2022
- Tumbleweed
2123

24+
include:
25+
- os_version: 3
26+
no_build: true
27+
- os_version: 4
28+
no_build: true
29+
2230
steps:
2331
# we need all branches for the build checks
2432
- uses: actions/checkout@v4
@@ -83,7 +91,7 @@ jobs:
8391
--os-version ${{ matrix.os_version }} \
8492
--branch-name="${{ matrix.os_version }}-${{ github.event.pull_request.number }}" \
8593
-vvvv \
86-
scratch_build \
94+
${{ matrix.no_build && 'commit_state' || 'scratch_build' }} \
8795
--commit-message='Test build for #${{ github.event.pull_request.number }}' \
8896
| tee info
8997
if grep -q "No changes" info; then
@@ -106,19 +114,20 @@ jobs:
106114
issue-number: ${{ github.event.pull_request.number }}
107115
# !!! if you change the body, then you must adjust StagingBot.from_github_comment() !!!
108116
body: |
109-
Created a staging project on OBS for ${{ matrix.os_version }}: [${{ env.PROJECT_NAME }}](${{ env.PROJECT_URL }})
117+
Rendered the templates for ${{ matrix.os_version }}
110118
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 }})
119+
${{ (matrix.no_build || format('Created a staging project on OBS: [{0}]({1})', env.PROJECT_NAME, env.PROJECT_URL)) && '' }}
111120
112121
- name: wait for the build to finish
113122
run: poetry run scratch-build-bot -vvvv wait
114123
env:
115124
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
116125
OSC_USER: "defolos"
117-
if: env.no_change != 'true'
126+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
118127

119128
- name: Install crane to list images on the registry
120129
uses: imjasonh/[email protected]
121-
if: env.no_change != 'true'
130+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
122131

123132
- name: retrieve the build result
124133
run: |
@@ -150,10 +159,10 @@ jobs:
150159
env:
151160
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
152161
OSC_USER: "defolos"
153-
if: env.no_change != 'true'
162+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
154163

155164
- name: report the finished build
156-
if: env.no_change != 'true'
165+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
157166
uses: peter-evans/create-or-update-comment@v4
158167
with:
159168
issue-number: ${{ github.event.pull_request.number }}
@@ -167,7 +176,7 @@ jobs:
167176
env:
168177
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
169178
OSC_USER: "defolos"
170-
if: env.no_change != 'true'
179+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
171180

172181
- name: cleanup the branches if no functional changes were commited or the build was cancelled
173182
run: poetry run scratch-build-bot -vvvv -l cleanup

src/staging/bot.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from bci_build.logger import LOGGER
3535
from bci_build.package import ALL_CONTAINER_IMAGE_NAMES
36+
from bci_build.package import ALL_OS_LTSS_VERSIONS
3637
from bci_build.package import BaseContainerImage
3738
from bci_build.package import OsVersion
3839
from dotnet.updater import DOTNET_IMAGES
@@ -298,14 +299,19 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
298299
if comment_text == "":
299300
raise ValueError("Received empty github comment, cannot create the bot")
300301
# comment_text looks like this:
301-
# Created a staging project on OBS for 4: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
302+
#
303+
# Rendered the templates for 6
302304
# Changes pushed to branch [`sle15-sp4-HsmtR`](url/to/branch)
305+
# Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
306+
#
307+
# The last line of the comment is only present if the bot created a
308+
# build, otherwise it's missing
303309
lines = comment_text.strip().splitlines()
304-
proj_line = lines[0]
305-
CREATED_TEXT = "Created a staging project on OBS for "
306-
if CREATED_TEXT not in proj_line:
310+
branch_line = lines[0]
311+
RENDERED_TEMPLATES_TEXT = "Rendered the templates for "
312+
if RENDERED_TEMPLATES_TEXT not in branch_line:
307313
raise ValueError(f"Invalid first line in the comment: {comment_text}")
308-
os_ver, prj_markdown_link = proj_line.replace(CREATED_TEXT, "").split(": ")
314+
os_ver = branch_line.replace(RENDERED_TEMPLATES_TEXT, "").strip()
309315

310316
CHANGES_TEXT = "Changes pushed to branch "
311317
branch_line = lines[1]
@@ -320,10 +326,18 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
320326
osc_username=osc_username,
321327
)
322328

323-
assert (
324-
bot.staging_project_name
325-
== (prj := prj_markdown_link.split("]")[0].replace("[", ""))
326-
), f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
329+
# sanity check if we have created a project
330+
if len(lines) > 2 and (proj_line := lines[2]):
331+
prj_markdown_link = proj_line.replace(
332+
"Created a staging project on OBS: ", ""
333+
)
334+
prj = prj_markdown_link.split("]")[0].replace("[", "")
335+
336+
if bot.staging_project_name != prj:
337+
raise ValueError(
338+
f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
339+
)
340+
327341
return bot
328342

329343
@staticmethod
@@ -1532,7 +1546,7 @@ def main() -> None:
15321546
parser.add_argument(
15331547
"--os-version",
15341548
type=str,
1535-
choices=[str(v) for v in ALL_OS_VERSIONS],
1549+
choices=[str(v) for v in ALL_OS_VERSIONS.union(ALL_OS_LTSS_VERSIONS)],
15361550
nargs=1,
15371551
default=[os.getenv(OS_VERSION_ENVVAR_NAME)],
15381552
help=f"The OS version for which all actions shall be made. The value from the environment variable {OS_VERSION_ENVVAR_NAME} is used if not provided.",
@@ -1764,7 +1778,14 @@ async def _create_staging_proj():
17641778
coro = _create_staging_proj()
17651779

17661780
elif action == "commit_state":
1767-
coro = bot.write_all_build_recipes_to_branch(args.commit_message[0])
1781+
1782+
async def _commit():
1783+
commit_or_None = await bot.write_all_build_recipes_to_branch(
1784+
args.commit_message[0]
1785+
)
1786+
return commit_or_None or "No changes"
1787+
1788+
coro = _commit()
17681789

17691790
elif action == "query_build_result":
17701791

tests/test_bot.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -47,32 +47,45 @@ async def test_load_from_env(
4747
"comment,bot",
4848
[
4949
(
50-
"""Created a staging project on OBS for 4: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj)
51-
Changes pushed to branch [`sle15-sp4-AVeMj`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp4-AVeMj)""",
50+
"""Rendered the templates for 4
51+
Changes pushed to branch [`sle15-sp4-AVeMj`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp4-AVeMj)
52+
Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-AVeMj)""",
5253
StagingBot(
5354
os_version=OsVersion.SP4,
5455
branch_name="sle15-sp4-AVeMj",
5556
osc_username=_osc_user,
5657
),
5758
),
5859
(
59-
"""Created a staging project on OBS for Tumbleweed: [home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS)
60-
Changes pushed to branch [`tumbleweed-EqgiS`](https://github.com/SUSE/BCI-dockerfile-generator/tree/tumbleweed-EqgiS)""",
60+
"""Rendered the templates for Tumbleweed
61+
Changes pushed to branch [`tumbleweed-EqgiS`](https://github.com/SUSE/BCI-dockerfile-generator/tree/tumbleweed-EqgiS)
62+
Created a staging project on OBS: [home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:Tumbleweed:tumbleweed-EqgiS)""",
6163
StagingBot(
6264
os_version=OsVersion.TUMBLEWEED,
6365
branch_name="tumbleweed-EqgiS",
6466
osc_username=_osc_user,
6567
),
6668
),
6769
(
68-
"""Created a staging project on OBS for 3: [home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa)
69-
Changes pushed to branch [`sle15-sp3-OZGYa`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp3-OZGYa)""",
70+
"""Rendered the templates for 3
71+
Changes pushed to branch [`sle15-sp3-OZGYa`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp3-OZGYa)
72+
Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa](https://build.opensuse.org/project/show/home:defolos:BCI:Staging:SLE-15-SP3:sle15-sp3-OZGYa)""",
7073
StagingBot(
7174
os_version=OsVersion.SP3,
7275
branch_name="sle15-sp3-OZGYa",
7376
osc_username=_osc_user,
7477
),
7578
),
79+
(
80+
"""Rendered the templates for 6
81+
Changes pushed to branch [`sle15-sp6-1337`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp6-1337)
82+
""",
83+
StagingBot(
84+
os_version=OsVersion.SP6,
85+
branch_name="sle15-sp6-1337",
86+
osc_username=_osc_user,
87+
),
88+
),
7689
],
7790
)
7891
def test_from_github_comment(comment: str, bot: StagingBot):

0 commit comments

Comments
 (0)