@@ -43,9 +43,82 @@ defaults:
43
43
shell : bash
44
44
45
45
jobs :
46
+ # Add a new job to check if base branch run is completed
47
+ check-base-benchmark :
48
+ name : Check base branch benchmark
49
+ if : github.event_name == 'pull_request'
50
+ runs-on : ubuntu-latest
51
+ steps :
52
+ - name : Checkout repository
53
+ uses : taiki-e/checkout-action@b13d20b7cda4e2f325ef19895128f7ff735c0b3d # v1.3.1
54
+
55
+ - name : Wait for base branch benchmark run to succeed
56
+ env :
57
+ GH_TOKEN : ${{ github.token }}
58
+ REPO : ${{ github.repository }}
59
+ BASE_BRANCH_NAME : ${{ github.event.pull_request.base.ref }}
60
+ WORKFLOW_FILE_NAME : ${{ github.workflow }}
61
+ MAX_WAIT_MINUTES : 15
62
+ run : |
63
+ echo "Looking for the latest workflow run on '$BASE_BRANCH_NAME' for '$WORKFLOW_FILE_NAME'..."
64
+ INITIAL_RUN_ID=""
65
+ CURRENT_RUN_ID=""
66
+
67
+ # Try to find the latest run on the base branch initially
68
+ INITIAL_RUN_ID=$(gh run list --workflow "$WORKFLOW_FILE_NAME" --branch "$BASE_BRANCH_NAME" --limit 1 --json databaseId --jq '.[0].databaseId // empty')
69
+
70
+ if [ -z "$INITIAL_RUN_ID" ]; then
71
+ echo "Warning: Could not find a recent run on '$BASE_BRANCH_NAME'. Proceeding without waiting."
72
+ else
73
+ echo "Found initial target run ID: $INITIAL_RUN_ID. Starting to monitor..."
74
+ WAIT_START_TIME=$(date +%s)
75
+ MAX_WAIT_SECONDS=$((MAX_WAIT_MINUTES * 60))
76
+ CURRENT_RUN_ID=$INITIAL_RUN_ID
77
+
78
+ while true; do
79
+ # Re-check for the latest workflow run in case there were new pushes
80
+ LATEST_RUN_ID=$(gh run list --workflow "$WORKFLOW_FILE_NAME" --branch "$BASE_BRANCH_NAME" --limit 1 --json databaseId --jq '.[0].databaseId // empty')
81
+
82
+ # If we found a newer run ID than what we were tracking, switch to it
83
+ if [ "$LATEST_RUN_ID" != "$CURRENT_RUN_ID" ]; then
84
+ echo "Detected a newer workflow run ($LATEST_RUN_ID) on '$BASE_BRANCH_NAME'. Switching monitoring target."
85
+ CURRENT_RUN_ID=$LATEST_RUN_ID
86
+ fi
87
+
88
+ # Check the status of the current run we're monitoring
89
+ RUN_INFO=$(gh run view "$CURRENT_RUN_ID" --json status,conclusion --jq '{status: .status, conclusion: .conclusion}')
90
+ STATUS=$(echo "$RUN_INFO" | jq -r '.status')
91
+ CONCLUSION=$(echo "$RUN_INFO" | jq -r '.conclusion')
92
+
93
+ echo "Run $CURRENT_RUN_ID status: $STATUS, conclusion: $CONCLUSION"
94
+ if [ "$STATUS" == "completed" ]; then
95
+ if [ "$CONCLUSION" == "success" ]; then
96
+ echo "Run $CURRENT_RUN_ID completed successfully. Proceeding."
97
+ break
98
+ else
99
+ echo "Warning: Run $CURRENT_RUN_ID completed with conclusion '$CONCLUSION'. Proceeding anyway, but benchmark results may not be accurate."
100
+ break # Even though the run failed, we can still proceed, because some of changes not care about benchmark.
101
+ fi
102
+ fi
103
+
104
+ CURRENT_TIME=$(date +%s)
105
+ ELAPSED_TIME=$((CURRENT_TIME - WAIT_START_TIME))
106
+ if [ "$ELAPSED_TIME" -ge "$MAX_WAIT_SECONDS" ]; then
107
+ echo "Warning: Timeout waiting after ${MAX_WAIT_MINUTES} minutes. The current run $CURRENT_RUN_ID has status '$STATUS'. Proceeding anyway."
108
+ break
109
+ fi
110
+
111
+ echo "Waiting 30 seconds before checking again..."
112
+ sleep 30
113
+ done
114
+ fi
115
+ shell : bash
116
+
46
117
# Build and run benchmarks for all components except linter
47
118
benchmark :
48
119
name : Benchmark
120
+ needs : check-base-benchmark
121
+ if : always()
49
122
runs-on : ubuntu-latest
50
123
strategy :
51
124
fail-fast : true
@@ -123,7 +196,8 @@ jobs:
123
196
# Run linter benchmarks. Each fixture in a separate job.
124
197
benchmark-linter :
125
198
name : Benchmark linter
126
- needs : build-linter
199
+ needs : [check-base-benchmark, build-linter]
200
+ if : always() && needs.build-linter.result == 'success'
127
201
runs-on : ubuntu-latest
128
202
strategy :
129
203
fail-fast : true
0 commit comments