Skip to content

Commit 5766570

Browse files
authored
fix: wrap in retry on outer call (#2131)
1 parent 490c2b3 commit 5766570

3 files changed

Lines changed: 100 additions & 16 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: 'Nix build with retry'
2+
description: |
3+
Runs `nix build --accept-flake-config -L` and retries on transient network
4+
errors (codeload.github.com 5xx, DNS, TLS, connection resets). Genuine build
5+
failures exit immediately without retrying.
6+
inputs:
7+
attr:
8+
description: 'The flake attribute to build, including the leading `.#`, e.g. `.#psql_17_cli_portable`'
9+
required: true
10+
extra-args:
11+
description: 'Additional arguments inserted between `-L` and the attribute, e.g. `--system aarch64-linux`'
12+
required: false
13+
default: ''
14+
attempts:
15+
description: 'Maximum number of attempts'
16+
required: false
17+
default: '3'
18+
initial-delay-seconds:
19+
description: 'Backoff before the second attempt; doubled before each subsequent attempt'
20+
required: false
21+
default: '30'
22+
23+
runs:
24+
using: 'composite'
25+
steps:
26+
- name: nix build (with retry)
27+
shell: bash
28+
env:
29+
ATTR: ${{ inputs.attr }}
30+
EXTRA_ARGS: ${{ inputs.extra-args }}
31+
ATTEMPTS: ${{ inputs.attempts }}
32+
INITIAL_DELAY: ${{ inputs.initial-delay-seconds }}
33+
run: |
34+
set -uo pipefail
35+
36+
log_file=$(mktemp)
37+
trap 'rm -f "$log_file"' EXIT
38+
39+
# Patterns that indicate a transient network/upstream failure rather
40+
# than a real build error. Keep conservative — false positives waste
41+
# CI minutes by re-running deterministic build failures.
42+
transient_re='HTTP error 5[0-9][0-9]|error: unable to download|Failed to open archive|Connection (reset|refused|timed out)|Couldn'\''t resolve host|Could not resolve host|unexpected end[- ]of[- ]file|SSL connection|TLS connection|Resource temporarily unavailable|Temporary failure in name resolution'
43+
44+
delay="$INITIAL_DELAY"
45+
rc=0
46+
for attempt in $(seq 1 "$ATTEMPTS"); do
47+
echo "::group::nix build attempt ${attempt}/${ATTEMPTS}: ${ATTR} ${EXTRA_ARGS}"
48+
# Stream to console AND capture for post-hoc pattern matching.
49+
# PIPESTATUS preserves nix's exit code through the tee.
50+
nix build --accept-flake-config -L ${EXTRA_ARGS} "${ATTR}" 2>&1 | tee "$log_file"
51+
rc=${PIPESTATUS[0]}
52+
echo "::endgroup::"
53+
54+
if [ "$rc" -eq 0 ]; then
55+
exit 0
56+
fi
57+
58+
if [ "$attempt" -ge "$ATTEMPTS" ]; then
59+
echo "::error::nix build failed after ${attempt} attempt(s) (exit ${rc})"
60+
exit "$rc"
61+
fi
62+
63+
if grep -qE "$transient_re" "$log_file"; then
64+
echo "::warning::Transient error on attempt ${attempt}; sleeping ${delay}s then retrying"
65+
sleep "$delay"
66+
delay=$((delay * 2))
67+
else
68+
echo "::error::nix build failed with non-transient error on attempt ${attempt} (exit ${rc}); not retrying"
69+
exit "$rc"
70+
fi
71+
done
72+
73+
# Defensive — loop should always exit via one of the branches above.
74+
exit "$rc"

.github/workflows/cli-release.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@ jobs:
3737
uses: ./.github/actions/nix-install-ephemeral
3838

3939
- name: Run portability check
40-
run: |
41-
nix build .#checks.${{ matrix.system }}.psql_17_cli_portable --system ${{ matrix.system }} -L --accept-flake-config
40+
uses: ./.github/actions/nix-build-retry
41+
with:
42+
attr: .#checks.${{ matrix.system }}.psql_17_cli_portable
43+
extra-args: --system ${{ matrix.system }}
4244

4345
- name: Build portable CLI bundle
44-
run: |
45-
nix build .#psql_17_cli_portable --system ${{ matrix.system }} -L --accept-flake-config
46+
uses: ./.github/actions/nix-build-retry
47+
with:
48+
attr: .#psql_17_cli_portable
49+
extra-args: --system ${{ matrix.system }}
4650

4751
- name: Determine version
4852
id: version

.github/workflows/nix-build.yml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ jobs:
5353
uses: ./.github/actions/nix-install-self-hosted
5454
- name: nix build
5555
if: ${{ matrix.attr != '' }}
56-
shell: bash
57-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
56+
uses: ./.github/actions/nix-build-retry
57+
with:
58+
attr: .#${{ matrix.attr }}
5859

5960
nix-build-checks-aarch64-linux:
6061
name: >-
@@ -84,8 +85,9 @@ jobs:
8485
uses: ./.github/actions/nix-install-self-hosted
8586
- name: nix build
8687
if: ${{ matrix.attr != '' }}
87-
shell: bash
88-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
88+
uses: ./.github/actions/nix-build-retry
89+
with:
90+
attr: .#${{ matrix.attr }}
8991

9092
nix-build-packages-aarch64-darwin:
9193
name: >-
@@ -107,8 +109,9 @@ jobs:
107109
uses: ./.github/actions/nix-install-self-hosted
108110
- name: nix build
109111
if: ${{ matrix.attr != '' }}
110-
shell: bash
111-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
112+
uses: ./.github/actions/nix-build-retry
113+
with:
114+
attr: .#${{ matrix.attr }}
112115

113116
nix-build-checks-aarch64-darwin:
114117
name: >-
@@ -130,8 +133,9 @@ jobs:
130133
uses: ./.github/actions/nix-install-self-hosted
131134
- name: nix build
132135
if: ${{ matrix.attr != '' }}
133-
shell: bash
134-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
136+
uses: ./.github/actions/nix-build-retry
137+
with:
138+
attr: .#${{ matrix.attr }}
135139

136140
nix-build-packages-x86_64-linux:
137141
name: >-
@@ -158,8 +162,9 @@ jobs:
158162
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
159163
- name: nix build
160164
if: ${{ matrix.attr != '' }}
161-
shell: bash
162-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
165+
uses: ./.github/actions/nix-build-retry
166+
with:
167+
attr: .#${{ matrix.attr }}
163168

164169
nix-build-checks-x86_64-linux:
165170
name: >-
@@ -186,8 +191,9 @@ jobs:
186191
NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }}
187192
- name: nix build
188193
if: ${{ matrix.attr != '' }}
189-
shell: bash
190-
run: nix build --accept-flake-config -L .#${{ matrix.attr }}
194+
uses: ./.github/actions/nix-build-retry
195+
with:
196+
attr: .#${{ matrix.attr }}
191197

192198
run-testinfra:
193199
needs: [nix-eval, nix-build-packages-aarch64-linux, nix-build-checks-aarch64-linux, nix-build-packages-aarch64-darwin, nix-build-checks-aarch64-darwin, nix-build-packages-x86_64-linux, nix-build-checks-x86_64-linux]

0 commit comments

Comments
 (0)