Skip to content

Commit 98e6102

Browse files
committed
use grep instead of tmp file
1 parent 300b45b commit 98e6102

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

.github/workflows/stubsabot.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,20 @@ jobs:
4040
run: uv pip install -r requirements-tests.txt --system
4141
- name: Run stubsabot
4242
id: runstubsabot
43+
shell: bash
4344
run: |
44-
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python scripts/stubsabot.py --action-level everything
45-
STUBS=$(cat /tmp/stubs.txt)
46-
echo "Stubs that should be tested by stubtest: $STUBS"
45+
# Parse stubsabot.py output to find stubs that should be tested.
46+
set -o pipefail
47+
exec 5>&1
48+
STUBS=$(script -qfc "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python scripts/stubsabot.py --action-level everything" /dev/null \
49+
| tee >(cat - >&5) \
50+
| sed -r "s/\x1B\[[0-9;]*[mK]//g" \
51+
| grep 'should be tested by stubsabot' \
52+
| awk '{print $1}' \
53+
| xargs)
54+
exit_code=$?
4755
echo "STUBS=$STUBS" >> $GITHUB_OUTPUT
56+
exit $exit_code
4857
4958
stubtest-third-party:
5059
name: "stubtest: third party"

scripts/stubsabot.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646

4747
POLICY_MONTHS_DELTA = 6
4848

49-
DEFAULT_STUBTEST_FILE = Path("/tmp/stubs.txt") # Sync with `stubsabot` github job
50-
5149

5250
class ActionLevel(enum.IntEnum):
5351
def __new__(cls, value: int, doc: str) -> Self:
@@ -631,17 +629,6 @@ def is_new_release(upload_datetime: datetime.datetime) -> bool:
631629
return upload_datetime > yesterday
632630

633631

634-
def append_stub_to_stubtest_list(distribution: str, *, file_path: Path = DEFAULT_STUBTEST_FILE) -> None:
635-
if Path.exists(file_path):
636-
with Path.open(file_path, "r") as f:
637-
stubs = f.read().strip()
638-
else:
639-
stubs = ""
640-
stubs = f"{stubs} {distribution}" if stubs else distribution
641-
with Path.open(file_path, "w") as f:
642-
f.write(stubs)
643-
644-
645632
async def determine_action(distribution: str, session: aiohttp.ClientSession) -> Update | NoUpdate | Obsolete | Remove | Error:
646633
try:
647634
return await determine_action_no_error_handling(distribution, session)
@@ -686,7 +673,8 @@ async def determine_action_no_error_handling(
686673
obsolete_since = await find_first_release_with_py_typed(pypi_info, session=session)
687674
if obsolete_since is None and latest_version in stub_info.version_spec:
688675
if is_new_release(latest_release.upload_date):
689-
append_stub_to_stubtest_list(latest_release.distribution)
676+
# Next print should be parsed by github action, see `stubsabot.yml`
677+
print(colored(f"{stub_info.distribution} should be tested by stubsabot", "blue"))
690678
return NoUpdate(stub_info.distribution, "up to date")
691679

692680
relevant_version = obsolete_since.version if obsolete_since else latest_version

0 commit comments

Comments
 (0)