Skip to content

Commit 318a061

Browse files
committed
Add new command /tests to run bci-tests on a test build
1 parent ec9cac7 commit 318a061

4 files changed

Lines changed: 129 additions & 0 deletions

File tree

.github/workflows/command-dispatch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ jobs:
1414
commands: |
1515
vc
1616
help
17+
tests
1718
issue-type: pull-request
1819
permission: none

.github/workflows/help-command.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ jobs:
1717
> --- | ---
1818
> /help | Print this message
1919
> /vc user=$user [packages=$pkg] $changelog_entry | Appends the given changelog entry as the provided user to the packages in the current branch.
20+
> /tests os_version=$os_ver [env=$tox-environments] [branch=$bci-tests-branch] | Runs the tests
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
name: Tests Command
3+
on:
4+
repository_dispatch:
5+
types: [tests-command]
6+
7+
jobs:
8+
append-changelog:
9+
runs-on: ubuntu-22.04
10+
container: ghcr.io/dcermak/bci-ci:latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
fetch-depth: 0
15+
16+
- uses: actions/cache@v3
17+
with:
18+
path: ~/.cache/pypoetry/virtualenvs
19+
key: poetry-${{ hashFiles('poetry.lock') }}
20+
21+
- name: fix the file permissions of the repository
22+
run: chown -R $(id -un):$(id -gn) .
23+
24+
- name: install python dependencies
25+
run: poetry install
26+
27+
- name: get the command parameters
28+
id: vars
29+
run: |
30+
OS_VERSION="${{ github.event.client_payload.slash_command.args.named.os_version }}"
31+
if [[ -z "$OS_VERSION" ]]; then echo "Missing os_version parameter!"; exit 1; fi
32+
echo "OS_VERSION=$OS_VERSION" >> $GITHUB_ENV
33+
34+
TOX_ENV="${{ github.event.client_payload.slash_command.args.named.env }}"
35+
if [[ ! -z "$TOX_ENV" ]]; then
36+
echo "TOX_ENV=$TOX_ENV" >> $GITHUB_ENV
37+
fi
38+
39+
BCI_TESTS_BRANCH="${{ github.event.client_payload.slash_command.args.named.branch }}"
40+
if [[ ! -z "$BCI_TESTS_BRANCH" ]]; then
41+
echo "BCI_TESTS_BRANCH=$BCI_TESTS_BRANCH"
42+
fi
43+
44+
- name: find the previous comment created by the bot
45+
uses: peter-evans/find-comment@v2
46+
id: find_comment
47+
with:
48+
issue-number: ${{ github.event.number }}
49+
body-includes: "Created a staging project on OBS for ${{ env.OS_VERSION }}"
50+
direction: last
51+
52+
- name: error out if no previous comment was found
53+
if: steps.find_comment.outputs.comment-id == ''
54+
run: exit 1
55+
56+
- name: run BCI-tests
57+
run: echo "${{ steps.find_comment.outputs.comment-body }}" | poetry run scratch-build-bot -vvvv --from-stdin run_bci_tests
58+
shell: fish {0}
59+
env:
60+
OSC_PASSWORD: ${{ secrets.OSC_PASSWORD }}
61+
OSC_USER: "defolos"
62+
if: steps.find_comment.outputs.comment-id != ''
63+
64+
- name: Add reaction to the original comment on success
65+
if: ${{ success() }}
66+
uses: peter-evans/create-or-update-comment@v3
67+
with:
68+
token: ${{ secrets.PAT }}
69+
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
70+
reaction-type: "+1"
71+
72+
- name: generate the url to this workflow run
73+
if: ${{ failure() || cancelled() }}
74+
run: echo "run_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
75+
76+
- name: Add reaction and a link to the error to the original comment on failure
77+
if: ${{ failure() || cancelled() }}
78+
uses: peter-evans/create-or-update-comment@v3
79+
with:
80+
token: ${{ secrets.PAT }}
81+
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
82+
reaction-type: "-1"
83+
body: Failed to run BCI-Tests, see the [workflow run](${{ env.run_url }}) for further details.

src/staging/bot.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from obs_package_update.util import CommandError
3333
from obs_package_update.util import CommandResult
3434
from obs_package_update.util import retry_async_run_cmd
35+
from obs_package_update.util import run_cmd
3536
from obs_package_update.util import RunCommand
3637
from staging.build_result import Arch
3738
from staging.build_result import PackageBuildResult
@@ -1044,6 +1045,18 @@ async def fetch_build_results(self) -> list[RepositoryBuildResult]:
10441045
(await self._run_cmd(self._osc_fetch_results_cmd())).stdout
10451046
)
10461047

1048+
@property
1049+
def staging_project_registry_base_url(self) -> str:
1050+
"""Returns the base url to the containers in the staging project on
1051+
OBS. This url is missing the repository name and the actual container
1052+
tag, but it can be used to plug the staging project directly into
1053+
BCI-tests.
1054+
1055+
"""
1056+
return "registry.opensuse.org/" + self.staging_project_name.lower().replace(
1057+
":", "/"
1058+
)
1059+
10471060
async def force_rebuild(self) -> str:
10481061
"""Deletes all binaries of the project on OBS and force rebuilds everything."""
10491062
await self._run_cmd(
@@ -1448,6 +1461,7 @@ def main() -> None:
14481461
"changelog_check",
14491462
"setup_obs_package",
14501463
"find_missing_packages",
1464+
"run_bci_tests",
14511465
]
14521466

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

1645+
subparsers.add_parser("run_bci_tests", help="Run BCI-Tests on test build")
1646+
16311647
loop = asyncio.get_event_loop()
16321648
args = parser.parse_args()
16331649

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

17761792
coro = _pkgs_as_str()
17771793

1794+
elif action == "run_bci_tests":
1795+
if bot.os_version == OsVersion.TUMBLEWEED:
1796+
raise ValueError("Running BCI-Tests is not supported on Tumbleweed.")
1797+
1798+
async def _run_tests() -> str:
1799+
tox_env = os.getenv("TOX_ENV")
1800+
bci_tests_branch = os.getenv("BCI_TESTS_BRANCH")
1801+
await run_cmd(
1802+
f"git clone https://github.com/SUSE/BCI-tests", logger=LOGGER
1803+
)
1804+
runner = RunCommand(
1805+
cwd=os.path.join(os.getcwd(), "BCI-tests"), logger=LOGGER
1806+
)
1807+
if bci_tests_branch:
1808+
await runner(f"git checkout {bci_tests_branch}")
1809+
1810+
test_res = await runner(
1811+
f"tox {'-e ' + tox_env if tox_env else ''} -- -n auto",
1812+
env={
1813+
"OS_VERSION": f"15.{bot.os_version}",
1814+
"TARGET": "custom",
1815+
"BASEURL": bot.staging_project_registry_base_url,
1816+
},
1817+
)
1818+
return test_res.stdout
1819+
1820+
coro = _run_tests()
1821+
17781822
else:
17791823
assert False, f"invalid action: {action}"
17801824

0 commit comments

Comments
 (0)