Skip to content

Commit 3b6cb7f

Browse files
committed
feat(ci): extract nix build setup into reusable action and split builds by architecture
Extract AWS credential setup and nix build steps into a composite action to reduce duplication. Split extension builds into separate jobs per architecture (aarch64-linux, aarch64-darwin, x86_64-linux) and update matrix generation to group packages by system.
1 parent fda80a1 commit 3b6cb7f

File tree

3 files changed

+106
-59
lines changed

3 files changed

+106
-59
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Nix Build Setup'
2+
description: 'Sets up AWS credentials and builds a Nix package'
3+
inputs:
4+
attr:
5+
description: 'The Nix attribute to build'
6+
required: true
7+
aws-role-duration:
8+
description: 'AWS role session duration in seconds'
9+
required: false
10+
default: '3600'
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- name: aws-oidc
16+
uses: aws-actions/[email protected]
17+
with:
18+
aws-region: us-east-2
19+
role-to-assume: arn:aws:iam::279559813984:role/supabase-github-oidc-role # Shared Services
20+
role-session-name: gha-oidc-${{ github.run_id }}
21+
- name: aws-creds
22+
uses: aws-actions/[email protected]
23+
with:
24+
disable-retry: true
25+
aws-region: us-east-2
26+
role-to-assume: arn:aws:iam::436098097459:role/nix-artifacts-deploy-role # supabase-dev
27+
role-session-name: gha-oidc-${{ github.run_id }}
28+
role-chaining: true
29+
role-skip-session-tagging: true
30+
role-duration-seconds: ${{ inputs.aws-role-duration }}
31+
- name: Write creds files
32+
shell: bash
33+
run: |
34+
umask 006
35+
cat > /etc/nix/aws/nix-aws-credentials <<EOF
36+
[ci-uploader]
37+
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
38+
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
39+
aws_session_token = ${AWS_SESSION_TOKEN}
40+
EOF
41+
- name: nix build
42+
shell: bash
43+
run: nix build -L .#${{ inputs.attr }}

.github/workflows/nix-build.yml

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,50 +30,63 @@ jobs:
3030
run: |
3131
set -Eeu
3232
echo matrix="$(python scripts/github-matrix.py extensions)" >> "$GITHUB_OUTPUT"
33+
# XXX debugging
34+
exit 1
3335
34-
build-extensions:
35-
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (${{ matrix.system }})
36+
build-extensions-aarch64-linux:
37+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (aarch64-linux)
3638
needs: extensions-matrix
3739
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
40+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_linux != null }}
3841
strategy:
3942
fail-fast: false
4043
max-parallel: 3
41-
matrix: ${{fromJSON(needs.extensions-matrix.outputs.matrix)}}
44+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_linux }}
4245
steps:
4346
- name: Checkout Repo
4447
uses: actions/checkout@v4
45-
- name: aws-oidc
46-
uses: aws-actions/[email protected]
48+
- name: Build Nix Package
49+
uses: ./.github/actions/nix-build-setup
4750
with:
48-
aws-region: us-east-2
49-
role-to-assume: arn:aws:iam::279559813984:role/supabase-github-oidc-role # Shared Services
50-
role-session-name: gha-oidc-${{ github.run_id }}
51-
- name: aws-creds
52-
uses: aws-actions/[email protected]
51+
attr: ${{ matrix.attr }}
52+
53+
build-extensions-aarch64-darwin:
54+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (aarch64-darwin)
55+
needs: extensions-matrix
56+
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
57+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_darwin != null }}
58+
strategy:
59+
fail-fast: false
60+
max-parallel: 3
61+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_darwin }}
62+
steps:
63+
- name: Checkout Repo
64+
uses: actions/checkout@v4
65+
- name: Build Nix Package
66+
uses: ./.github/actions/nix-build-setup
5367
with:
54-
disable-retry: true
55-
aws-region: us-east-2
56-
role-to-assume: arn:aws:iam::436098097459:role/nix-artifacts-deploy-role # supabase-dev
57-
role-session-name: gha-oidc-${{ github.run_id }}
58-
role-chaining: true
59-
role-skip-session-tagging: true
60-
role-duration-seconds: 3600
61-
- name: Write creds files
62-
run: |
63-
umask 006
64-
cat > /etc/nix/aws/nix-aws-credentials <<EOF
65-
[ci-uploader]
66-
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
67-
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
68-
aws_session_token = ${AWS_SESSION_TOKEN}
69-
EOF
70-
- name: nix build
71-
run: |
72-
nix build -L .#${{ matrix.attr }}
68+
attr: ${{ matrix.attr }}
69+
70+
build-extensions-x86_64-linux:
71+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (x86_64-linux)
72+
needs: extensions-matrix
73+
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
74+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).x86_64_linux != null }}
75+
strategy:
76+
fail-fast: false
77+
max-parallel: 3
78+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).x86_64_linux }}
79+
steps:
80+
- name: Checkout Repo
81+
uses: actions/checkout@v4
82+
- name: Build Nix Package
83+
uses: ./.github/actions/nix-build-setup
84+
with:
85+
attr: ${{ matrix.attr }}
7386

7487

7588
checks-matrix:
76-
needs: [build-extensions]
89+
needs: [build-extensions-aarch64-linux, build-extensions-aarch64-darwin, build-extensions-x86_64-linux]
7790
runs-on:
7891
group: self-hosted-runners-nix
7992
labels:
@@ -92,42 +105,18 @@ jobs:
92105
93106
build-checks:
94107
name: ${{ matrix.name }} (${{ matrix.system }})
95-
needs: [checks-matrix, build-extensions]
108+
needs: [checks-matrix]
96109
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
97110
strategy:
98111
fail-fast: false
99112
matrix: ${{fromJSON(needs.checks-matrix.outputs.matrix)}}
100113
steps:
101114
- name: Checkout Repo
102115
uses: actions/checkout@v4
103-
- name: aws-oidc
104-
uses: aws-actions/[email protected]
116+
- name: Build Nix Package
117+
uses: ./.github/actions/nix-build-setup
105118
with:
106-
aws-region: us-east-2
107-
role-to-assume: arn:aws:iam::279559813984:role/supabase-github-oidc-role # Shared Services
108-
role-session-name: gha-oidc-${{ github.run_id }}
109-
- name: aws-creds
110-
uses: aws-actions/[email protected]
111-
with:
112-
disable-retry: true
113-
aws-region: us-east-2
114-
role-to-assume: arn:aws:iam::436098097459:role/nix-artifacts-deploy-role # supabase-dev
115-
role-session-name: gha-oidc-${{ github.run_id }}
116-
role-chaining: true
117-
role-skip-session-tagging: true
118-
role-duration-seconds: 3600
119-
- name: Write creds files
120-
run: |
121-
umask 006
122-
cat > /etc/nix/aws/nix-aws-credentials <<EOF
123-
[ci-uploader]
124-
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
125-
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
126-
aws_session_token = ${AWS_SESSION_TOKEN}
127-
EOF
128-
- name: nix build
129-
run: |
130-
nix build -L .#${{ matrix.attr }}
119+
attr: ${{ matrix.attr }}
131120

132121
run-tests:
133122
needs: build-checks

scripts/github-matrix.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ def run_nix_eval_jobs(
134134
for line in process.stdout:
135135
package = parse_nix_eval_line(line, drv_paths, target)
136136
if package and not package["already_cached"]:
137+
print(f"Found package: {package['attr']}", file=sys.stderr)
137138
yield package
138139

139140
if process.returncode and process.returncode != 0:
@@ -177,7 +178,21 @@ def main() -> None:
177178
if is_extension_pkg(pkg)
178179
]
179180

180-
gh_output = {"include": gh_action_packages}
181+
# Group packages by system
182+
grouped_by_system = {}
183+
for pkg in gh_action_packages:
184+
system = pkg["system"]
185+
if system not in grouped_by_system:
186+
grouped_by_system[system] = []
187+
grouped_by_system[system].append(pkg)
188+
189+
# Create output with system-specific matrices
190+
gh_output = {}
191+
for system, packages in grouped_by_system.items():
192+
gh_output[system.replace("-", "_")] = {"include": packages}
193+
else:
194+
gh_output = {"include": gh_action_packages}
195+
181196
print(json.dumps(gh_output))
182197

183198

0 commit comments

Comments
 (0)