@@ -4,36 +4,86 @@ inputs:
4
4
node_version :
5
5
description : node version used to configure environment with
6
6
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'
7
15
outputs :
8
16
baseline_dir :
9
17
description : ' Path where baseline project directory is setup'
10
18
value : ${{ steps.move_baseline_version.outputs.baseline_dir }}
11
19
runs :
12
20
using : composite
13
21
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
14
57
- name : Get baseline commit sha
15
58
id : get_baseline_commit_sha
16
59
shell : bash
17
60
env :
18
61
GH_TOKEN : ${{ github.token }}
19
62
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"
37
87
- name : Checkout baseline version
38
88
uses : actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # version 4.1.4
39
89
with :
44
94
- name : Install and build baseline version
45
95
shell : bash
46
96
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"
49
101
- name : Move baseline version
50
102
id : move_baseline_version
51
103
shell : bash
0 commit comments