Skip to content

Commit

Permalink
Add new command /tests to run bci-tests on a test build
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Jun 27, 2023
1 parent ec9cac7 commit 318a061
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ jobs:
commands: |
vc
help
tests
issue-type: pull-request
permission: none
1 change: 1 addition & 0 deletions .github/workflows/help-command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
> --- | ---
> /help | Print this message
> /vc user=$user [packages=$pkg] $changelog_entry | Appends the given changelog entry as the provided user to the packages in the current branch.
> /tests os_version=$os_ver [env=$tox-environments] [branch=$bci-tests-branch] | Runs the tests
83 changes: 83 additions & 0 deletions .github/workflows/tests-command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
name: Tests Command
on:
repository_dispatch:
types: [tests-command]

jobs:
append-changelog:
runs-on: ubuntu-22.04
container: ghcr.io/dcermak/bci-ci:latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/cache@v3
with:
path: ~/.cache/pypoetry/virtualenvs
key: poetry-${{ hashFiles('poetry.lock') }}

- name: fix the file permissions of the repository
run: chown -R $(id -un):$(id -gn) .

- name: install python dependencies
run: poetry install

- name: get the command parameters
id: vars
run: |
OS_VERSION="${{ github.event.client_payload.slash_command.args.named.os_version }}"
if [[ -z "$OS_VERSION" ]]; then echo "Missing os_version parameter!"; exit 1; fi
echo "OS_VERSION=$OS_VERSION" >> $GITHUB_ENV
TOX_ENV="${{ github.event.client_payload.slash_command.args.named.env }}"
if [[ ! -z "$TOX_ENV" ]]; then
echo "TOX_ENV=$TOX_ENV" >> $GITHUB_ENV
fi
BCI_TESTS_BRANCH="${{ github.event.client_payload.slash_command.args.named.branch }}"
if [[ ! -z "$BCI_TESTS_BRANCH" ]]; then
echo "BCI_TESTS_BRANCH=$BCI_TESTS_BRANCH"
fi
- name: find the previous comment created by the bot
uses: peter-evans/find-comment@v2
id: find_comment
with:
issue-number: ${{ github.event.number }}
body-includes: "Created a staging project on OBS for ${{ env.OS_VERSION }}"
direction: last

- name: error out if no previous comment was found
if: steps.find_comment.outputs.comment-id == ''
run: exit 1

- name: run BCI-tests
run: echo "${{ steps.find_comment.outputs.comment-body }}" | poetry run scratch-build-bot -vvvv --from-stdin run_bci_tests
shell: fish {0}
env:
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
OSC_USER: "defolos"
if: steps.find_comment.outputs.comment-id != ''

- name: Add reaction to the original comment on success
if: ${{ success() }}
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.PAT }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: "+1"

- name: generate the url to this workflow run
if: ${{ failure() || cancelled() }}
run: echo "run_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV

- name: Add reaction and a link to the error to the original comment on failure
if: ${{ failure() || cancelled() }}
uses: peter-evans/create-or-update-comment@v3
with:
token: ${{ secrets.PAT }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reaction-type: "-1"
body: Failed to run BCI-Tests, see the [workflow run](${{ env.run_url }}) for further details.
44 changes: 44 additions & 0 deletions src/staging/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from obs_package_update.util import CommandError
from obs_package_update.util import CommandResult
from obs_package_update.util import retry_async_run_cmd
from obs_package_update.util import run_cmd
from obs_package_update.util import RunCommand
from staging.build_result import Arch
from staging.build_result import PackageBuildResult
Expand Down Expand Up @@ -1044,6 +1045,18 @@ async def fetch_build_results(self) -> list[RepositoryBuildResult]:
(await self._run_cmd(self._osc_fetch_results_cmd())).stdout
)

@property
def staging_project_registry_base_url(self) -> str:
"""Returns the base url to the containers in the staging project on
OBS. This url is missing the repository name and the actual container
tag, but it can be used to plug the staging project directly into
BCI-tests.
"""
return "registry.opensuse.org/" + self.staging_project_name.lower().replace(
":", "/"
)

async def force_rebuild(self) -> str:
"""Deletes all binaries of the project on OBS and force rebuilds everything."""
await self._run_cmd(
Expand Down Expand Up @@ -1448,6 +1461,7 @@ def main() -> None:
"changelog_check",
"setup_obs_package",
"find_missing_packages",
"run_bci_tests",
]

parser = argparse.ArgumentParser()
Expand Down Expand Up @@ -1628,6 +1642,8 @@ def add_commit_message_arg(p: argparse.ArgumentParser) -> None:
help="Find all packages that are in the deployment branch and are missing from `devel:BCI:*` on OBS",
)

subparsers.add_parser("run_bci_tests", help="Run BCI-Tests on test build")

loop = asyncio.get_event_loop()
args = parser.parse_args()

Expand Down Expand Up @@ -1775,6 +1791,34 @@ async def _pkgs_as_str() -> str:

coro = _pkgs_as_str()

elif action == "run_bci_tests":
if bot.os_version == OsVersion.TUMBLEWEED:
raise ValueError("Running BCI-Tests is not supported on Tumbleweed.")

async def _run_tests() -> str:
tox_env = os.getenv("TOX_ENV")
bci_tests_branch = os.getenv("BCI_TESTS_BRANCH")
await run_cmd(
f"git clone https://github.com/SUSE/BCI-tests", logger=LOGGER
)
runner = RunCommand(
cwd=os.path.join(os.getcwd(), "BCI-tests"), logger=LOGGER
)
if bci_tests_branch:
await runner(f"git checkout {bci_tests_branch}")

test_res = await runner(
f"tox {'-e ' + tox_env if tox_env else ''} -- -n auto",
env={
"OS_VERSION": f"15.{bot.os_version}",
"TARGET": "custom",
"BASEURL": bot.staging_project_registry_base_url,
},
)
return test_res.stdout

coro = _run_tests()

else:
assert False, f"invalid action: {action}"

Expand Down

0 comments on commit 318a061

Please sign in to comment.