Skip to content

Commit b460565

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

File tree

3 files changed

+68
-25
lines changed

3 files changed

+68
-25
lines changed

.github/workflows/obs_build.yml

+17-8
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15+
no_build:
16+
- false
1517
os_version:
16-
- 6
1718
- 5
19+
- 6
1820
- Tumbleweed
1921
- Basalt
2022

23+
include:
24+
- os_version: 3
25+
no_build: true
26+
- os_version: 4
27+
no_build: true
28+
2129
steps:
2230
# we need all branches for the build checks
2331
- uses: actions/checkout@v4
@@ -82,7 +90,7 @@ jobs:
8290
--os-version ${{ matrix.os_version }} \
8391
--branch-name="${{ matrix.os_version }}-${{ github.event.pull_request.number }}" \
8492
-vvvv \
85-
scratch_build \
93+
${{ matrix.no_build && 'commit_state' || 'scratch_build' }} \
8694
--commit-message='Test build for #${{ github.event.pull_request.number }}' \
8795
| tee info
8896
if grep -q "No changes" info; then
@@ -103,19 +111,20 @@ jobs:
103111
issue-number: ${{ github.event.pull_request.number }}
104112
# !!! if you change the body, then you must adjust StagingBot.from_github_comment() !!!
105113
body: |
106-
Created a staging project on OBS for ${{ matrix.os_version }}: [${{ env.PROJECT_NAME }}](${{ env.PROJECT_URL }})
114+
Rendered the templates for ${{ matrix.os_version }}
107115
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 }})
116+
${{ matrix.no_build && '' || format('Created a staging project on OBS: [{0}]({1})', env.PROJECT_NAME, env.PROJECT_URL) }}
108117
109118
- name: wait for the build to finish
110119
run: poetry run scratch-build-bot -vvvv wait
111120
env:
112121
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
113122
OSC_USER: "defolos"
114-
if: env.no_change != 'true'
123+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
115124

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

120129
- name: retrieve the build result
121130
run: |
@@ -147,10 +156,10 @@ jobs:
147156
env:
148157
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
149158
OSC_USER: "defolos"
150-
if: env.no_change != 'true'
159+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
151160

152161
- name: report the finished build
153-
if: env.no_change != 'true'
162+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
154163
uses: peter-evans/create-or-update-comment@v4
155164
with:
156165
issue-number: ${{ github.event.pull_request.number }}
@@ -164,7 +173,7 @@ jobs:
164173
env:
165174
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
166175
OSC_USER: "defolos"
167-
if: env.no_change != 'true'
176+
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
168177

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

src/staging/bot.py

+32-11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from bci_build.logger import LOGGER
3131
from bci_build.package import ALL_CONTAINER_IMAGE_NAMES
32+
from bci_build.package import ALL_OS_LTSS_VERSIONS
3233
from bci_build.package import BaseContainerImage
3334
from bci_build.package import OsVersion
3435
from dotnet.updater import DOTNET_IMAGES
@@ -278,14 +279,19 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
278279
if comment_text == "":
279280
raise ValueError("Received empty github comment, cannot create the bot")
280281
# comment_text looks like this:
281-
# Created a staging project on OBS for 4: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
282+
#
283+
# Rendered the templates for 6
282284
# Changes pushed to branch [`sle15-sp4-HsmtR`](url/to/branch)
285+
# Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
286+
#
287+
# The last line of the comment is only present if the bot created a
288+
# build, otherwise it's missing
283289
lines = comment_text.strip().splitlines()
284-
proj_line = lines[0]
285-
CREATED_TEXT = "Created a staging project on OBS for "
286-
if CREATED_TEXT not in proj_line:
290+
branch_line = lines[0]
291+
RENDERED_TEMPLATES_TEXT = "Rendered the templates for "
292+
if RENDERED_TEMPLATES_TEXT not in branch_line:
287293
raise ValueError(f"Invalid first line in the comment: {comment_text}")
288-
os_ver, prj_markdown_link = proj_line.replace(CREATED_TEXT, "").split(": ")
294+
os_ver = branch_line.replace(RENDERED_TEMPLATES_TEXT, "").strip()
289295

290296
CHANGES_TEXT = "Changes pushed to branch "
291297
branch_line = lines[1]
@@ -300,10 +306,18 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
300306
osc_username=osc_username,
301307
)
302308

303-
assert (
304-
bot.staging_project_name
305-
== (prj := prj_markdown_link.split("]")[0].replace("[", ""))
306-
), f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
309+
# sanity check if we have created a project
310+
if len(lines) > 2 and (proj_line := lines[2]):
311+
prj_markdown_link = proj_line.replace(
312+
"Created a staging project on OBS: ", ""
313+
)
314+
prj = prj_markdown_link.split("]")[0].replace("[", "")
315+
316+
if bot.staging_project_name != prj:
317+
raise ValueError(
318+
f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
319+
)
320+
307321
return bot
308322

309323
@staticmethod
@@ -1545,7 +1559,7 @@ def main() -> None:
15451559
parser.add_argument(
15461560
"--os-version",
15471561
type=str,
1548-
choices=[str(v) for v in ALL_OS_VERSIONS],
1562+
choices=[str(v) for v in ALL_OS_VERSIONS.union(ALL_OS_LTSS_VERSIONS)],
15491563
nargs=1,
15501564
default=[os.getenv(OS_VERSION_ENVVAR_NAME)],
15511565
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.",
@@ -1773,7 +1787,14 @@ async def _create_staging_proj():
17731787
coro = _create_staging_proj()
17741788

17751789
elif action == "commit_state":
1776-
coro = bot.write_all_build_recipes_to_branch(args.commit_message[0])
1790+
1791+
async def _commit():
1792+
commit_or_None = await bot.write_all_build_recipes_to_branch(
1793+
args.commit_message[0]
1794+
)
1795+
return commit_or_None or "No changes"
1796+
1797+
coro = _commit()
17771798

17781799
elif action == "query_build_result":
17791800

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)