Skip to content

Commit a7ae1ad

Browse files
committed
fix: setup_baseline_version only runs once, and fails often on network instability
1 parent f851736 commit a7ae1ad

File tree

2 files changed

+73
-51
lines changed

2 files changed

+73
-51
lines changed

.github/actions/setup_baseline_version/action.yml

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,86 @@ inputs:
44
node_version:
55
description: node version used to configure environment with
66
required: true
7+
max_retry_attempts:
8+
description: maximum number of retry attempts for network operations
9+
required: false
10+
default: '5'
11+
initial_wait_time:
12+
description: initial wait time in seconds before first retry (increases by this amount each retry)
13+
required: false
14+
default: '30'
715
outputs:
816
baseline_dir:
917
description: 'Path where baseline project directory is setup'
1018
value: ${{ steps.move_baseline_version.outputs.baseline_dir }}
1119
runs:
1220
using: composite
1321
steps:
22+
- name: Setup retry function
23+
shell: bash
24+
run: |
25+
# Create a shared retry function that can be used in other steps
26+
cat > /tmp/retry_function.sh << 'EOF'
27+
retry_with_backoff() {
28+
local max_attempts=$1
29+
local initial_wait=$2
30+
shift 2
31+
local command="$@"
32+
33+
local attempt=1
34+
local wait_time=$initial_wait
35+
36+
while [ $attempt -le $max_attempts ]; do
37+
echo "Attempt $attempt of $max_attempts"
38+
39+
if eval "$command"; then
40+
echo "Command completed successfully"
41+
return 0
42+
fi
43+
44+
if [ $attempt -lt $max_attempts ]; then
45+
echo "Command failed. Waiting ${wait_time} seconds before retry..."
46+
sleep $wait_time
47+
wait_time=$((wait_time + initial_wait))
48+
fi
49+
50+
attempt=$((attempt + 1))
51+
done
52+
53+
echo "All retry attempts failed"
54+
return 1
55+
}
56+
EOF
1457
- name: Get baseline commit sha
1558
id: get_baseline_commit_sha
1659
shell: bash
1760
env:
1861
GH_TOKEN: ${{ github.token }}
1962
run: |
20-
if [[ ${{ github.event_name }} == 'push' ]]; then
21-
# The SHA of the most recent commit on ref before the push.
22-
baseline_commit_sha="${{ github.event.before }}"
23-
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
24-
# The SHA of the HEAD commit on base branch.
25-
baseline_commit_sha="${{ github.event.pull_request.base.sha }}"
26-
elif [[ ${{ github.event_name }} == 'schedule' ]] || [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
27-
# The SHA of the parent of HEAD commit on main branch.
28-
# This assumes linear history of main branch, i.e. one parent.
29-
# These events have only information about HEAD commit, hence the need for lookup.
30-
baseline_commit_sha=$(gh api /repos/${{ github.repository }}/commits/${{ github.sha }} | jq -r '.parents[0].sha')
31-
else
32-
echo Unable to determine baseline commit sha;
33-
exit 1;
34-
fi
35-
echo baseline commit sha is $baseline_commit_sha;
36-
echo "baseline_commit_sha=$baseline_commit_sha" >> "$GITHUB_OUTPUT";
63+
source /tmp/retry_function.sh
64+
65+
get_baseline_commit() {
66+
if [[ ${{ github.event_name }} == 'push' ]]; then
67+
# The SHA of the most recent commit on ref before the push.
68+
baseline_commit_sha="${{ github.event.before }}"
69+
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
70+
# The SHA of the HEAD commit on base branch.
71+
baseline_commit_sha="${{ github.event.pull_request.base.sha }}"
72+
elif [[ ${{ github.event_name }} == 'schedule' ]] || [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
73+
# The SHA of the parent of HEAD commit on main branch.
74+
# This assumes linear history of main branch, i.e. one parent.
75+
# These events have only information about HEAD commit, hence the need for lookup.
76+
baseline_commit_sha=$(gh api /repos/${{ github.repository }}/commits/${{ github.sha }} | jq -r '.parents[0].sha')
77+
else
78+
echo "Unable to determine baseline commit sha"
79+
return 1
80+
fi
81+
}
82+
83+
# Execute with retries
84+
retry_with_backoff ${{ inputs.max_retry_attempts }} ${{ inputs.initial_wait_time }} get_baseline_commit
85+
echo "baseline commit sha is $baseline_commit_sha"
86+
echo "baseline_commit_sha=$baseline_commit_sha" >> "$GITHUB_OUTPUT"
3787
- name: Checkout baseline version
3888
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
3989
with:
@@ -44,8 +94,10 @@ runs:
4494
- name: Install and build baseline version
4595
shell: bash
4696
run: |
47-
npm ci
48-
npm run build
97+
source /tmp/retry_function.sh
98+
99+
# Execute npm ci and build with retries
100+
retry_with_backoff ${{ inputs.max_retry_attempts }} ${{ inputs.initial_wait_time }} "npm ci && npm run build"
49101
- name: Move baseline version
50102
id: move_baseline_version
51103
shell: bash

.github/workflows/health_checks.yml

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -404,41 +404,11 @@ jobs:
404404
# See https://github.com/actions/checkout/issues/692
405405
- name: Checkout version for baseline
406406
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
407-
- name: Setup baseline version (attempt 1)
408-
id: setup_baseline_version_attempt1
409-
uses: ./.github/actions/setup_baseline_version
410-
with:
411-
node_version: 18
412-
continue-on-error: true
413-
414-
- name: Setup baseline version (attempt 2)
415-
id: setup_baseline_version_attempt2
416-
if: steps.setup_baseline_version_attempt1.outcome == 'failure'
417-
uses: ./.github/actions/setup_baseline_version
418-
with:
419-
node_version: 18
420-
continue-on-error: true
421-
422-
- name: Setup baseline version (attempt 3)
423-
id: setup_baseline_version_attempt3
424-
if: steps.setup_baseline_version_attempt2.outcome == 'failure'
407+
- name: Setup baseline version
408+
id: setup_baseline_version
425409
uses: ./.github/actions/setup_baseline_version
426410
with:
427411
node_version: 18
428-
429-
- name: Set baseline directory output
430-
id: setup_baseline_version
431-
run: |
432-
if [[ "${{ steps.setup_baseline_version_attempt1.outcome }}" == "success" ]]; then
433-
echo "✅ Setup baseline version succeeded on attempt 1"
434-
echo "baseline_dir=${{ steps.setup_baseline_version_attempt1.outputs.baseline_dir }}" >> "$GITHUB_OUTPUT"
435-
elif [[ "${{ steps.setup_baseline_version_attempt2.outcome }}" == "success" ]]; then
436-
echo "⚠️ Setup baseline version succeeded on attempt 2 (after 1 failure)"
437-
echo "baseline_dir=${{ steps.setup_baseline_version_attempt2.outputs.baseline_dir }}" >> "$GITHUB_OUTPUT"
438-
else
439-
echo "⚠️ Setup baseline version succeeded on attempt 3 (after 2 failures)"
440-
echo "baseline_dir=${{ steps.setup_baseline_version_attempt3.outputs.baseline_dir }}" >> "$GITHUB_OUTPUT"
441-
fi
442412
- name: Checkout current version
443413
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
444414
- name: Run e2e amplify outputs backwards compatibility test

0 commit comments

Comments
 (0)