88
99permissions :
1010 actions : read
11- contents : read
11+ contents : write
1212 pull-requests : write
1313 checks : write
1414
@@ -23,28 +23,65 @@ jobs:
2323 run-id : ${{ github.event.workflow_run.id }}
2424 github-token : ${{ secrets.GITHUB_TOKEN }}
2525 pattern : ctrf-*
26- path : ctrf-reports
26+ path : ctrf-blob
2727 merge-multiple : true
2828
29+ - name : 📂 Checkout Flaky History
30+ uses : actions/checkout@v4
31+ continue-on-error : true
32+ with :
33+ ref : flaky-monitor-results
34+ path : flaky-history
35+ fetch-depth : 0
36+
37+ - name : 📦 Prepare Reports
38+ run : |
39+ mkdir -p all-reports
40+
41+ # initialize history branch if checkout failed (branch doesn't exist)
42+ if [ ! -d "flaky-history" ]; then
43+ echo "Creating orphan branch directory"
44+ mkdir -p flaky-history
45+ cd flaky-history
46+ git init
47+ git checkout --orphan flaky-monitor-results
48+ cd ..
49+ fi
50+
51+ # Copy history to processing dir
52+ # (Ignore errors if empty)
53+ cp flaky-history/*.json all-reports/ 2>/dev/null || true
54+
55+ # Process current run artifacts
56+ # Rename to avoid collisions and track run ID
57+ # We expect files like ctrf-tavern-ubuntu-latest.json
58+ for file in ctrf-blob/*.json; do
59+ if [ -e "$file" ]; then
60+ filename=$(basename "$file" .json)
61+ cp "$file" "all-reports/${filename}-${{ github.event.workflow_run.id }}.json"
62+ fi
63+ done
64+
2965 - name : Get PR Number
3066 id : pr_info
3167 run : |
68+ # Retrieve PR number for commenting
69+ # Note: workflow_run context has limited PR info depending on trigger
3270 echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> $GITHUB_OUTPUT
3371
3472 - name : 📊 Publish Test Report
3573 uses : ctrf-io/github-test-reporter@v1
3674 env :
3775 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3876 with :
39- report-path : ' ctrf -reports/*.json'
77+ report-path : ' all -reports/*.json'
4078 upload-artifact : true
41- fetch-previous-results : true
79+ fetch-previous-results : false # Using orphan branch instead
4280 pull-request : false
4381 issue : ${{ steps.pr_info.outputs.pr_number }}
4482 overwrite-comment : true
4583
4684 # Report Config
47- # https://github.com/ctrf-io/github-test-reporter/blob/main/docs/report-showcase.md
4885 summary-delta-report : true
4986 tests-changed-report : true
5087 insights-report : true
5592 previous-results-report : true
5693 previous-results-max : 100
5794 artifact-name : ' flaky-report'
95+
96+ - name : 💾 Persist Results (Main Only)
97+ if : ${{ github.event.workflow_run.head_branch == 'main' }}
98+ run : |
99+ cd flaky-history
100+
101+ # Configure git identity
102+ git config user.name "github-actions[bot]"
103+ git config user.email "github-actions[bot]@users.noreply.github.com"
104+
105+ # Ensure remote is set up correctly regardless of checkout success/fail
106+ # First, remove origin if it exists to avoid errors on re-add
107+ git remote remove origin 2>/dev/null || true
108+ git remote add origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git
109+
110+ # Fetch origin to make sure we have the latest state if checkout failed earlier but branch exists
111+ # (This handles race conditions or edge cases where checkout failed for other reasons)
112+ git fetch origin flaky-monitor-results 2>/dev/null || true
113+
114+ # If we are on a detached head or master (from init), ensure we are on the orphan branch
115+ current_branch=$(git branch --show-current)
116+ if [ "$current_branch" != "flaky-monitor-results" ]; then
117+ git checkout -b flaky-monitor-results || git checkout flaky-monitor-results
118+ fi
119+
120+ # Copy NEW reports from current run to history
121+ # Note: We copy from the renamed versions in all-reports to ensure uniqueness
122+ # Filter for files ending in this run-id
123+ cp ../all-reports/*-${{ github.event.workflow_run.id }}.json .
124+
125+ git add .
126+ git commit -m "Add test results from run ${{ github.event.workflow_run.id }}"
127+
128+ # Push to the orphan branch
129+ git push origin flaky-monitor-results
0 commit comments