Skip to content

Commit

Permalink
Render the templates for LTSS code streams but don't build them on OBS
Browse files Browse the repository at this point in the history
This fixes #1087
  • Loading branch information
dcermak committed May 7, 2024
1 parent cedac80 commit e076da4
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 23 deletions.
23 changes: 16 additions & 7 deletions .github/workflows/obs_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ jobs:
strategy:
fail-fast: false
matrix:
no_build:
- false
os_version:
- 6
- 5
- 6
- Tumbleweed
- Basalt

include:
- os_version: 3
no_build: true
- os_version: 4
no_build: true

steps:
# we need all branches for the build checks
- uses: actions/checkout@v4
Expand Down Expand Up @@ -82,7 +90,7 @@ jobs:
--os-version ${{ matrix.os_version }} \
--branch-name="${{ matrix.os_version }}-${{ github.event.pull_request.number }}" \
-vvvv \
scratch_build \
${{ matrix.no_build && "commit_state" || "scratch_build" }} \
--commit-message='Test build for #${{ github.event.pull_request.number }}' \
| tee info
if grep -q "No changes" info; then
Expand All @@ -103,8 +111,9 @@ jobs:
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 }})
Rendered the templates for ${{ matrix.os_version }}
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 }})
${{ matrix.no_build || ('Created a staging project on OBS: [' + env.PROJECT_NAME + '](' + env.PROJECT_URL ')') }}
- name: wait for the build to finish
run: poetry run scratch-build-bot -vvvv wait
Expand All @@ -115,7 +124,7 @@ jobs:

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

- name: retrieve the build result
run: |
Expand Down Expand Up @@ -147,10 +156,10 @@ jobs:
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: env.no_change != 'true'
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}

- name: report the finished build
if: env.no_change != 'true'
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
Expand All @@ -164,7 +173,7 @@ jobs:
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: env.no_change != 'true'
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}

- name: cleanup the branches if no functional changes were commited or the build was cancelled
run: poetry run scratch-build-bot -vvvv -l cleanup
Expand Down
40 changes: 30 additions & 10 deletions src/staging/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,19 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
if comment_text == "":
raise ValueError("Received empty github comment, cannot create the bot")
# comment_text looks like this:
# Created a staging project on OBS for 4: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
#
# Rendered the templates for 6
# Changes pushed to branch [`sle15-sp4-HsmtR`](url/to/branch)
# Created a staging project on OBS: [home:defolos:BCI:Staging:SLE-15-SP4:sle15-sp4-HsmtR](url/to/proj)
#
# The last line of the comment is only present if the bot created a
# build, otherwise it's missing
lines = comment_text.strip().splitlines()
proj_line = lines[0]
CREATED_TEXT = "Created a staging project on OBS for "
if CREATED_TEXT not in proj_line:
branch_line = lines[0]
RENDERED_TEMPLATES_TEXT = "Rendered the templates for "
if RENDERED_TEMPLATES_TEXT not in branch_line:
raise ValueError(f"Invalid first line in the comment: {comment_text}")
os_ver, prj_markdown_link = proj_line.replace(CREATED_TEXT, "").split(": ")
os_ver = branch_line.replace(RENDERED_TEMPLATES_TEXT, "").strip()

CHANGES_TEXT = "Changes pushed to branch "
branch_line = lines[1]
Expand All @@ -300,10 +305,18 @@ def from_github_comment(comment_text: str, osc_username: str) -> "StagingBot":
osc_username=osc_username,
)

assert (
bot.staging_project_name
== (prj := prj_markdown_link.split("]")[0].replace("[", ""))
), f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
# sanity check if we have created a project
if len(lines) > 2 and (proj_line := lines[2]):
prj_markdown_link = proj_line.replace(
"Created a staging project on OBS: ", ""
)
prj = prj_markdown_link.split("]")[0].replace("[", "")

if bot.staging_project_name != prj:
raise ValueError(
f"Mismatch between the constructed project name ({bot.staging_project_name}) and the project name from the comment ({prj})"
)

return bot

@staticmethod
Expand Down Expand Up @@ -1773,7 +1786,14 @@ async def _create_staging_proj():
coro = _create_staging_proj()

elif action == "commit_state":
coro = bot.write_all_build_recipes_to_branch(args.commit_message[0])

async def _commit():
commit_or_None = await bot.write_all_build_recipes_to_branch(
args.commit_message[0]
)
return commit_or_None or "No changes"

coro = _commit()

elif action == "query_build_result":

Expand Down
25 changes: 19 additions & 6 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,45 @@ async def test_load_from_env(
"comment,bot",
[
(
"""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)
Changes pushed to branch [`sle15-sp4-AVeMj`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp4-AVeMj)""",
"""Rendered the templates for 4
Changes pushed to branch [`sle15-sp4-AVeMj`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp4-AVeMj)
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)""",
StagingBot(
os_version=OsVersion.SP4,
branch_name="sle15-sp4-AVeMj",
osc_username=_osc_user,
),
),
(
"""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)
Changes pushed to branch [`tumbleweed-EqgiS`](https://github.com/SUSE/BCI-dockerfile-generator/tree/tumbleweed-EqgiS)""",
"""Rendered the templates for Tumbleweed
Changes pushed to branch [`tumbleweed-EqgiS`](https://github.com/SUSE/BCI-dockerfile-generator/tree/tumbleweed-EqgiS)
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)""",
StagingBot(
os_version=OsVersion.TUMBLEWEED,
branch_name="tumbleweed-EqgiS",
osc_username=_osc_user,
),
),
(
"""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)
Changes pushed to branch [`sle15-sp3-OZGYa`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp3-OZGYa)""",
"""Rendered the templates for 3
Changes pushed to branch [`sle15-sp3-OZGYa`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp3-OZGYa)
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)""",
StagingBot(
os_version=OsVersion.SP3,
branch_name="sle15-sp3-OZGYa",
osc_username=_osc_user,
),
),
(
"""Rendered the templates for 6
Changes pushed to branch [`sle15-sp6-1337`](https://github.com/SUSE/BCI-dockerfile-generator/tree/sle15-sp6-1337)
""",
StagingBot(
os_version=OsVersion.SP6,
branch_name="sle15-sp6-1337",
osc_username=_osc_user,
),
),
],
)
def test_from_github_comment(comment: str, bot: StagingBot):
Expand Down

0 comments on commit e076da4

Please sign in to comment.