|
| 1 | +name: Flaky Test Tracker |
| 2 | + |
| 3 | +# Runs daily and on-demand to detect flaky tests from recent CI runs. |
| 4 | +# Parses JUnit XML artifacts from Rust-CI workflow runs, identifies tests |
| 5 | +# marked as flaky (failed then passed on retry), and creates/updates a |
| 6 | +# tracking issue with a summary table. |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + issues: write |
| 11 | + actions: read |
| 12 | + |
| 13 | +on: |
| 14 | + schedule: |
| 15 | + # Run daily at 06:00 UTC |
| 16 | + - cron: "0 6 * * *" |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +env: |
| 20 | + # The label applied to the flaky test tracking issue. |
| 21 | + FLAKY_ISSUE_LABEL: "flaky-test" |
| 22 | + # How many recent Rust-CI workflow runs to scan. |
| 23 | + LOOKBACK_RUNS: 20 |
| 24 | + |
| 25 | +jobs: |
| 26 | + detect-flaky-tests: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 30 | + |
| 31 | + - name: Ensure flaky-test label exists |
| 32 | + env: |
| 33 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 34 | + run: | |
| 35 | + gh label create "$FLAKY_ISSUE_LABEL" \ |
| 36 | + --description "Automatically detected flaky tests" \ |
| 37 | + --color "FBCA04" \ |
| 38 | + --force |
| 39 | +
|
| 40 | + - name: Download JUnit XML from recent Rust-CI runs |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + run: | |
| 44 | + set -euo pipefail |
| 45 | + mkdir -p junit-artifacts |
| 46 | +
|
| 47 | + # Get the workflow ID for Rust-CI |
| 48 | + WORKFLOW_ID=$(gh api "repos/${{ github.repository }}/actions/workflows" \ |
| 49 | + --jq '.workflows[] | select(.name == "Rust-CI") | .id') |
| 50 | +
|
| 51 | + if [[ -z "$WORKFLOW_ID" ]]; then |
| 52 | + echo "::warning::Could not find Rust-CI workflow" |
| 53 | + exit 0 |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "Rust-CI workflow ID: $WORKFLOW_ID" |
| 57 | +
|
| 58 | + # Get recent completed runs on the default branch |
| 59 | + RUN_IDS=$(gh api "repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/runs?branch=main&status=completed&per_page=$LOOKBACK_RUNS" \ |
| 60 | + --jq '.workflow_runs[].id') |
| 61 | +
|
| 62 | + echo "Found $(echo "$RUN_IDS" | wc -l) recent runs" |
| 63 | +
|
| 64 | + for RUN_ID in $RUN_IDS; do |
| 65 | + echo "Checking run $RUN_ID for JUnit artifacts..." |
| 66 | + # List artifacts for this run that match our naming pattern |
| 67 | + ARTIFACT_INFO=$(gh api "repos/${{ github.repository }}/actions/runs/$RUN_ID/artifacts" \ |
| 68 | + --jq '.artifacts[] | select(.name | startswith("junit-xml-")) | "\(.id) \(.name)"' || true) |
| 69 | +
|
| 70 | + while IFS=' ' read -r ARTIFACT_ID ARTIFACT_NAME; do |
| 71 | + [[ -z "$ARTIFACT_ID" ]] && continue |
| 72 | + echo " Downloading artifact $ARTIFACT_NAME ($ARTIFACT_ID) from run $RUN_ID" |
| 73 | + DEST_DIR="junit-artifacts/run-$RUN_ID/$ARTIFACT_NAME" |
| 74 | + mkdir -p "$DEST_DIR" |
| 75 | + gh api "repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID/zip" \ |
| 76 | + > "$DEST_DIR/artifact.zip" || true |
| 77 | + (cd "$DEST_DIR" && unzip -o -q "artifact.zip" 2>/dev/null && rm -f "artifact.zip") || true |
| 78 | + done <<< "$ARTIFACT_INFO" |
| 79 | + done |
| 80 | +
|
| 81 | + echo "Downloaded artifacts:" |
| 82 | + find junit-artifacts -name '*.xml' | head -50 || echo "No XML files found" |
| 83 | +
|
| 84 | + - name: Parse JUnit XML and detect flaky tests |
| 85 | + id: parse |
| 86 | + env: |
| 87 | + GITHUB_REPO_URL: ${{ github.server_url }}/${{ github.repository }} |
| 88 | + FLAKY_ISSUE_LABEL: ${{ env.FLAKY_ISSUE_LABEL }} |
| 89 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 90 | + run: python3 .github/workflows/scripts/parse_flaky.py |
| 91 | + |
| 92 | + - name: Create or update tracking issue |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | +
|
| 98 | + BODY=$(cat flaky-report.md) |
| 99 | + TITLE="Flaky Test Report (automated)" |
| 100 | +
|
| 101 | + # Find existing open issue with the flaky-test label and our title |
| 102 | + EXISTING_ISSUE=$(gh issue list \ |
| 103 | + --label "$FLAKY_ISSUE_LABEL" \ |
| 104 | + --state open \ |
| 105 | + --search "$TITLE" \ |
| 106 | + --json number,title \ |
| 107 | + --jq '.[] | select(.title == "'"$TITLE"'") | .number' \ |
| 108 | + | head -1) |
| 109 | +
|
| 110 | + if [[ -n "$EXISTING_ISSUE" ]]; then |
| 111 | + echo "Updating existing issue #$EXISTING_ISSUE" |
| 112 | + gh issue edit "$EXISTING_ISSUE" --body "$BODY" |
| 113 | + else |
| 114 | + echo "Creating new tracking issue" |
| 115 | + gh issue create \ |
| 116 | + --title "$TITLE" \ |
| 117 | + --body "$BODY" \ |
| 118 | + --label "$FLAKY_ISSUE_LABEL" |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Post summary |
| 122 | + if: always() |
| 123 | + run: | |
| 124 | + if [[ -f flaky-report.md ]]; then |
| 125 | + cat flaky-report.md >> "$GITHUB_STEP_SUMMARY" |
| 126 | + fi |
0 commit comments