diff --git a/.github/workflows/cleanup-staging.yml b/.github/workflows/cleanup-staging.yml index 2066db3b4..bc5f0a0af 100644 --- a/.github/workflows/cleanup-staging.yml +++ b/.github/workflows/cleanup-staging.yml @@ -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 diff --git a/.github/workflows/obs_build.yml b/.github/workflows/obs_build.yml index c43b4c66a..d8a076616 100644 --- a/.github/workflows/obs_build.yml +++ b/.github/workflows/obs_build.yml @@ -12,13 +12,23 @@ jobs: strategy: fail-fast: false matrix: + no_build: + - false os_version: - 7 - 6 - 5 + - 4 + - 3 - "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 +93,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 +116,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 +161,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 +178,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 diff --git a/src/staging/bot.py b/src/staging/bot.py index 425c63dda..59042d8a6 100644 --- a/src/staging/bot.py +++ b/src/staging/bot.py @@ -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": diff --git a/tests/test_bot.py b/tests/test_bot.py index e7a815ffb..e420cec37 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -47,8 +47,9 @@ 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", @@ -56,8 +57,9 @@ async def test_load_from_env( ), ), ( - """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", @@ -65,14 +67,25 @@ async def test_load_from_env( ), ), ( - """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):