-
Notifications
You must be signed in to change notification settings - Fork 1
feat: implement issue #1364 — [Fleet Monitor] petry-projects/.github-private — .github/workflows/test.yml #1366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+134
−2
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f68f1e8
feat: implement issue #1364 — [Fleet Monitor] petry-projects/.github-…
don-petry 7ace117
chore: dev-lead update (review-changes) [skip ci-relay]
don-petry f93ece6
fix(bot): address bot feedback [skip ci-relay]
don-petry 1d82d6c
fix(reviews): address review comments [skip ci-relay]
don-petry 3d46dc7
chore: dev-lead update (review-changes) [skip ci-relay]
don-petry cd3b2a1
chore: dev-lead update (review-changes) [skip ci-relay]
don-petry e9f064f
Merge branch 'main' into dev-lead/issue-1364-20260723-0915
don-petry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| # test_test_workflow_resilience.sh — regression guard for issue #1364. | ||
| # | ||
| # The Tests workflow (.github/workflows/test.yml) flaked at ~14.8% of runs. Its | ||
| # only non-deterministic step is "Install test dependencies", which fetches | ||
| # packages over the network: | ||
| # - pip install pyyaml | ||
| # - sudo apt-get update && sudo apt-get install -y yq | ||
| # Transient PyPI / apt-mirror failures (and pip falling back to a source build) | ||
| # failed the whole run even though every test itself is pure and local. This | ||
| # test asserts the install step is hardened so a single transient fetch failure | ||
| # no longer fails the workflow: | ||
| # 1. network installs are wrapped in a bounded retry, | ||
| # 2. pip is pinned and binary-only (no flaky source build). | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| WORKFLOW="${SCRIPT_DIR}/../.github/workflows/test.yml" | ||
| STEP_NAME="Install test dependencies" | ||
| fail=0 | ||
|
|
||
| if ! command -v yq >/dev/null 2>&1; then | ||
| echo "FAIL: yq is required to run this test" | ||
| exit 2 | ||
| fi | ||
|
|
||
| if [ ! -f "$WORKFLOW" ]; then | ||
| echo "FAIL: $WORKFLOW not found" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Bracket-index the hyphenated job key: under jq-based yq (kislyuk), `.jobs.unit-tests` | ||
| # parses as `.jobs.unit - tests` and fails with "tests/0 is not defined" (issue #1364). | ||
| run=$(yq '.jobs["unit-tests"].steps[] | select(.name == "'"$STEP_NAME"'") | .run' "$WORKFLOW") | ||
|
|
||
| if [ -z "$run" ] || [ "$run" = "null" ]; then | ||
| echo "FAIL: could not find the \"$STEP_NAME\" step in $WORKFLOW" | ||
|
don-petry marked this conversation as resolved.
|
||
| exit 1 | ||
| fi | ||
|
|
||
|
don-petry marked this conversation as resolved.
|
||
| # Normalize newlines and repeated spaces into a single logical line so the checks | ||
| # below are robust to multi-line run blocks and backslash line continuations | ||
| # (e.g. "retry \<newline> pip install ...") that a line-by-line grep would miss. | ||
| normalized_run=$(printf '%s\n' "$run" | tr '\n' ' ' | tr -s ' ') | ||
|
|
||
| # 1. A retry helper must be defined so transient fetch failures are absorbed. | ||
| # Use POSIX [[:space:]] rather than the PCRE \s shorthand so the check is | ||
| # portable to BSD/macOS grep. Assert grep exits exactly 1 (no match) so a grep | ||
| # error (exit 2) can't be mistaken for "not found". | ||
| status=0 | ||
| grep -Eq 'retry[[:space:]]*\(\)' <<<"$normalized_run" || status=$? | ||
| if [ "$status" -eq 2 ]; then | ||
| echo "FAIL: grep error while checking for retry() helper" | ||
| exit 2 | ||
| elif [ "$status" -eq 1 ]; then | ||
| echo "FAIL: \"$STEP_NAME\" must define a retry() helper to absorb transient" | ||
| echo " network failures (apt mirror / PyPI) — issue #1364." | ||
| fail=1 | ||
| fi | ||
|
don-petry marked this conversation as resolved.
|
||
|
|
||
| # 2. Every network fetch must go through retry (check all occurrences are wrapped). | ||
| while IFS= read -r cmd; do | ||
| if grep -Eq "$cmd" <<<"$normalized_run"; then | ||
| # Count total occurrences and retry-wrapped occurrences; they must match. | ||
| # Anchor "retry" directly before the command (allowing only a "sudo" prefix, | ||
| # which is how the real invocations read: "retry pip install", "retry sudo | ||
| # apt-get update"). A greedy "retry.*$cmd" is wrong two ways: it spans across | ||
| # logical commands — after newline normalization there are no ;|& separators | ||
| # to stop it, so an un-retried "apt-get install" preceded by any earlier | ||
| # "retry" would false-pass — and its single leftmost-longest match undercounts | ||
| # when a command legitimately appears more than once. | ||
| total=$(grep -Eo "(^|[^a-z])$cmd" <<<"$normalized_run" | wc -l) | ||
| wrapped=$(grep -Eo "retry[[:space:]]+(sudo[[:space:]]+)?$cmd" <<<"$normalized_run" | wc -l) | ||
| if [ "$total" -ne "$wrapped" ]; then | ||
| echo "FAIL: all occurrences of \"$cmd\" in \"$STEP_NAME\" must be wrapped in retry" | ||
| echo " (found $total, wrapped $wrapped) — issue #1364" | ||
| fail=1 | ||
| fi | ||
| fi | ||
| done <<'CMDS' | ||
| apt-get update | ||
| apt-get install | ||
| pip install | ||
| CMDS | ||
|
don-petry marked this conversation as resolved.
|
||
|
|
||
| # 3. pip must be pinned and binary-only so it never falls back to a source build. | ||
| if grep -Eq 'pip install' <<<"$normalized_run"; then | ||
| status=0 | ||
| grep -Fq -- '--only-binary' <<<"$normalized_run" || status=$? | ||
| if [ "$status" -eq 2 ]; then | ||
| echo "FAIL: grep error while checking for --only-binary" | ||
| exit 2 | ||
| elif [ "$status" -eq 1 ]; then | ||
| echo "FAIL: the pip install in \"$STEP_NAME\" must use --only-binary to avoid" | ||
| echo " a flaky source build (issue #1364)." | ||
|
don-petry marked this conversation as resolved.
|
||
| fail=1 | ||
| fi | ||
| status=0 | ||
| grep -Eiq 'pyyaml==[0-9]+\.[0-9]+\.[0-9]+' <<<"$normalized_run" || status=$? | ||
| if [ "$status" -eq 2 ]; then | ||
| echo "FAIL: grep error while checking for the pyyaml version pin" | ||
| exit 2 | ||
| elif [ "$status" -eq 1 ]; then | ||
| echo "FAIL: the pip install in \"$STEP_NAME\" must pin pyyaml to a specific" | ||
| echo " version (pyyaml==X.Y.Z) for reproducible installs (issue #1364)." | ||
|
don-petry marked this conversation as resolved.
|
||
| fail=1 | ||
|
don-petry marked this conversation as resolved.
|
||
| fi | ||
| fi | ||
|
|
||
| if [ "$fail" -eq 0 ]; then | ||
| echo "PASS: $WORKFLOW dependency install is retry-hardened and pinned" | ||
| fi | ||
| exit "$fail" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.