Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render the templates for LTSS code streams but don't build them on OBS #1092

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Render the templates for LTSS code streams but don't build them on OBS
This fixes #1087
dcermak committed Sep 4, 2024
commit 970bd69dc0684b75ff29366f007f51f0c5335a6c
4 changes: 3 additions & 1 deletion .github/workflows/cleanup-staging.yml
Original file line number Diff line number Diff line change
@@ -19,6 +19,8 @@ jobs:
- 7
- 6
- 5
- 4
- 3
- "16.0"
- Tumbleweed

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

- name: run the cleanup
23 changes: 16 additions & 7 deletions .github/workflows/obs_build.yml
Original file line number Diff line number Diff line change
@@ -12,13 +12,21 @@ jobs:
strategy:
fail-fast: false
matrix:
no_build:
- false
os_version:
- 7
- 6
- 5
- "16.0"
- Tumbleweed

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
@@ -83,7 +91,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
@@ -106,19 +114,20 @@ 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 || format('Created a staging project on OBS: [{0}]({1})', env.PROJECT_NAME, env.PROJECT_URL)) && '' }}

- 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'
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}

- name: Install crane to list images on the registry
uses: imjasonh/setup-crane@v0.4
if: env.no_change != 'true'
if: ${{ (env.no_change != 'true') && (! matrix.no_build) }}

- name: retrieve the build result
run: |
@@ -150,10 +159,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 }}
@@ -167,7 +176,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
43 changes: 32 additions & 11 deletions src/staging/bot.py
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@

from bci_build.logger import LOGGER
from bci_build.package import ALL_CONTAINER_IMAGE_NAMES
from bci_build.package import ALL_OS_LTSS_VERSIONS
from bci_build.package import BaseContainerImage
from bci_build.package import OsVersion
from dotnet.updater import DOTNET_IMAGES
@@ -298,14 +299,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]
@@ -320,10 +326,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
@@ -1532,7 +1546,7 @@ def main() -> None:
parser.add_argument(
"--os-version",
type=str,
choices=[str(v) for v in ALL_OS_VERSIONS],
choices=[str(v) for v in ALL_OS_VERSIONS.union(ALL_OS_LTSS_VERSIONS)],
nargs=1,
default=[os.getenv(OS_VERSION_ENVVAR_NAME)],
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():
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":

25 changes: 19 additions & 6 deletions tests/test_bot.py
Original file line number Diff line number Diff line change
@@ -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):