Skip to content

Commit 72f42cc

Browse files
author
Sven Siegmund
committed
test(refactor): test_update_actions to use Action rather than dataclasses.OwnerRepo | dataclasses.CommitVersion
1 parent 376bc0e commit 72f42cc

File tree

3 files changed

+52
-23
lines changed

3 files changed

+52
-23
lines changed

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ select = [
4545
"N811", # constant-imported-as-non-constant
4646
]
4747
"tests/e2e/test_update_actions.py" = [
48+
"F401", # unused-import
4849
"N811", # constant-imported-as-non-constant
4950
]
5051

scripts/update-test_update_actions.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ actions_from_all_workflows() {
3434

3535
get_actions_from_all_workflows_with_their_latest_commits_and_versions() {
3636
actions_from_all_workflows | while read owner repo old_commit old_version; do
37-
url="https://api.github.com/repos/$owner/$repo/tags"
37+
url="https://api.github.com/repos/$owner/$repo/tags"
3838

3939
if [ -n "$CI_STARTER_GH_API_TOKEN" ]; then
40-
tags=$(curl -s -H "Authorization: token $CI_STARTER_GH_API_TOKEN" "$url")
40+
tags=$(curl -sS -H "Authorization: token $CI_STARTER_GH_API_TOKEN" "$url")
4141
else
42-
tags=$(curl -s "$url")
42+
tags=$(curl -sS "$url")
4343
fi
4444

4545
latest_release=$(echo "$tags" | jq -rc '.[0]')
@@ -62,7 +62,9 @@ find_line_where_original_code_continues() {
6262

6363
generate_code() {
6464
get_actions_from_all_workflows_with_their_latest_commits_and_versions | while read owner repo commit version; do
65-
printf " expected_actions[OwnerRepo(\"%s\", \"%s\")] = CommitVersion(\"%s\", \"%s\")\n" "$owner" "$repo" "$commit" "$version"
65+
name="$owner/$repo"
66+
printf ' expected_actions["%s"] = Action(owner="%s", repo="%s", commit="%s", version=Version.parse("%s"),)\n' \
67+
"$name" "$owner" "$repo" "$commit" "$version"
6668
done
6769
printf "\n"
6870
}

tests/e2e/test_update_actions.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
from click.testing import CliRunner, Result
44
from ruamel.yaml import YAML as Yaml
5+
from semver.version import Version
56

7+
from ci_starter.action import Action
68
from ci_starter.cli import cli
79
from ci_starter.constants import GITHUB_WORKFLOWS_DIR
8-
from ci_starter.dataclasses import CommitVersion, OwnerRepo
910
from ci_starter.utils import get_actions
1011
from tests.e2e.constants import SUCCESSFUL_RETURN_CODE
1112

@@ -18,34 +19,59 @@ def test_update_action(cli_runner: CliRunner, test_project_path_str, step_parser
1819

1920
workflows = Path(test_project_path_str, GITHUB_WORKFLOWS_DIR).rglob("*.yml")
2021

21-
expected_actions: dict[OwnerRepo, CommitVersion] = {}
22+
expected_actions: dict[str, Action] = {}
2223

2324
# adding keys and values to expected_actions is managed by scripts/update-test_update_actions.sh
24-
expected_actions[OwnerRepo("actions", "checkout")] = CommitVersion(
25-
"08c6903cd8c0fde910a37f88322edcfb5dd907a8", "5.0.0"
25+
expected_actions["actions/checkout"] = Action(
26+
owner="actions",
27+
repo="checkout",
28+
commit="08c6903cd8c0fde910a37f88322edcfb5dd907a8",
29+
version=Version.parse("5.0.0"),
2630
)
27-
expected_actions[OwnerRepo("actions", "download-artifact")] = CommitVersion(
28-
"634f93cb2916e3fdff6788551b99b062d0335ce0", "5.0.0"
31+
expected_actions["actions/download-artifact"] = Action(
32+
owner="actions",
33+
repo="download-artifact",
34+
commit="634f93cb2916e3fdff6788551b99b062d0335ce0",
35+
version=Version.parse("5.0.0"),
2936
)
30-
expected_actions[OwnerRepo("actions", "setup-python")] = CommitVersion(
31-
"e797f83bcb11b83ae66e0230d6156d7c80228e7c", "6.0.0"
37+
expected_actions["actions/setup-python"] = Action(
38+
owner="actions",
39+
repo="setup-python",
40+
commit="e797f83bcb11b83ae66e0230d6156d7c80228e7c",
41+
version=Version.parse("6.0.0"),
3242
)
33-
expected_actions[OwnerRepo("actions", "upload-artifact")] = CommitVersion(
34-
"ea165f8d65b6e75b540449e92b4886f43607fa02", "4.6.2"
43+
expected_actions["actions/upload-artifact"] = Action(
44+
owner="actions",
45+
repo="upload-artifact",
46+
commit="ea165f8d65b6e75b540449e92b4886f43607fa02",
47+
version=Version.parse("4.6.2"),
3548
)
36-
expected_actions[OwnerRepo("astral-sh", "ruff-action")] = CommitVersion(
37-
"57714a7c8a2e59f32539362ba31877a1957dded1", "3.5.1"
49+
expected_actions["astral-sh/ruff-action"] = Action(
50+
owner="astral-sh",
51+
repo="ruff-action",
52+
commit="57714a7c8a2e59f32539362ba31877a1957dded1",
53+
version=Version.parse("3.5.1"),
3854
)
39-
expected_actions[OwnerRepo("astral-sh", "setup-uv")] = CommitVersion(
40-
"eb1897b8dc4b5d5bfe39a428a8f2304605e0983c", "7.0.0"
55+
expected_actions["astral-sh/setup-uv"] = Action(
56+
owner="astral-sh",
57+
repo="setup-uv",
58+
commit="eb1897b8dc4b5d5bfe39a428a8f2304605e0983c",
59+
version=Version.parse("7.0.0"),
4160
)
42-
expected_actions[OwnerRepo("pypa", "gh-action-pypi-publish")] = CommitVersion(
43-
"ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e", "1.13.0"
61+
expected_actions["pypa/gh-action-pypi-publish"] = Action(
62+
owner="pypa",
63+
repo="gh-action-pypi-publish",
64+
commit="ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e",
65+
version=Version.parse("1.13.0"),
4466
)
4567

4668
for file in workflows:
4769
data = step_parser.load(file)
4870
for action in get_actions(data):
49-
actual_commit_and_version = CommitVersion(action.commit, str(action.version))
50-
expected_commit_and_version = expected_actions[OwnerRepo(action.owner, action.repo)]
51-
assert actual_commit_and_version == expected_commit_and_version
71+
actual_commit = action.commit
72+
actual_version = action.version
73+
expected_commit = expected_actions[action.name].commit
74+
expected_version = expected_actions[action.name].version
75+
76+
assert actual_commit == expected_commit
77+
assert actual_version == expected_version

0 commit comments

Comments
 (0)