Skip to content

Commit 20cb24e

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 20cb24e

File tree

3 files changed

+103
-63
lines changed

3 files changed

+103
-63
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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: Checkout Repo
16+
uses: actions/checkout@v4
17+
- name: aws-oidc
18+
uses: aws-actions/[email protected]
19+
with:
20+
aws-region: us-east-2
21+
role-to-assume: arn:aws:iam::279559813984:role/supabase-github-oidc-role # Shared Services
22+
role-session-name: gha-oidc-${{ github.run_id }}
23+
- name: aws-creds
24+
uses: aws-actions/[email protected]
25+
with:
26+
disable-retry: true
27+
aws-region: us-east-2
28+
role-to-assume: arn:aws:iam::436098097459:role/nix-artifacts-deploy-role # supabase-dev
29+
role-session-name: gha-oidc-${{ github.run_id }}
30+
role-chaining: true
31+
role-skip-session-tagging: true
32+
role-duration-seconds: ${{ inputs.aws-role-duration }}
33+
- name: Write creds files
34+
shell: bash
35+
run: |
36+
umask 006
37+
cat > /etc/nix/aws/nix-aws-credentials <<EOF
38+
[ci-uploader]
39+
aws_access_key_id = ${AWS_ACCESS_KEY_ID}
40+
aws_secret_access_key = ${AWS_SECRET_ACCESS_KEY}
41+
aws_session_token = ${AWS_SESSION_TOKEN}
42+
EOF
43+
- name: nix build
44+
shell: bash
45+
run: nix build -L .#${{ inputs.attr }}

.github/workflows/nix-build.yml

Lines changed: 41 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,54 @@ jobs:
3131
set -Eeu
3232
echo matrix="$(python scripts/github-matrix.py extensions)" >> "$GITHUB_OUTPUT"
3333
34-
build-extensions:
35-
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (${{ matrix.system }})
34+
build-extensions-aarch64-linux:
35+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (aarch64-linux)
3636
needs: extensions-matrix
3737
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
38+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_linux != null }}
3839
strategy:
3940
fail-fast: false
4041
max-parallel: 3
41-
matrix: ${{fromJSON(needs.extensions-matrix.outputs.matrix)}}
42+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_linux }}
4243
steps:
43-
- name: Checkout Repo
44-
uses: actions/checkout@v4
45-
- name: aws-oidc
46-
uses: aws-actions/[email protected]
44+
- name: Build Nix Package
45+
uses: ./.github/actions/nix-build-setup
4746
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]
47+
attr: ${{ matrix.attr }}
48+
49+
build-extensions-aarch64-darwin:
50+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (aarch64-darwin)
51+
needs: extensions-matrix
52+
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
53+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_darwin != null }}
54+
strategy:
55+
fail-fast: false
56+
max-parallel: 3
57+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).aarch64_darwin }}
58+
steps:
59+
- name: Build Nix Package
60+
uses: ./.github/actions/nix-build-setup
5361
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 }}
62+
attr: ${{ matrix.attr }}
63+
64+
build-extensions-x86_64-linux:
65+
name: ${{matrix.postgresql_version}}.${{ matrix.name }} (x86_64-linux)
66+
needs: extensions-matrix
67+
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
68+
if: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).x86_64_linux != null }}
69+
strategy:
70+
fail-fast: false
71+
max-parallel: 3
72+
matrix: ${{ fromJSON(needs.extensions-matrix.outputs.matrix).x86_64_linux }}
73+
steps:
74+
- name: Build Nix Package
75+
uses: ./.github/actions/nix-build-setup
76+
with:
77+
attr: ${{ matrix.attr }}
7378

7479

7580
checks-matrix:
76-
needs: [build-extensions]
81+
needs: [build-extensions-aarch64-linux, build-extensions-aarch64-darwin, build-extensions-x86_64-linux]
7782
runs-on:
7883
group: self-hosted-runners-nix
7984
labels:
@@ -92,42 +97,16 @@ jobs:
9297
9398
build-checks:
9499
name: ${{ matrix.name }} (${{ matrix.system }})
95-
needs: [checks-matrix, build-extensions]
100+
needs: [checks-matrix, build-extensions-aarch64-linux, build-extensions-aarch64-darwin, build-extensions-x86_64-linux]
96101
runs-on: ${{ matrix.runs_on.group && matrix.runs_on || matrix.runs_on.labels }}
97102
strategy:
98103
fail-fast: false
99104
matrix: ${{fromJSON(needs.checks-matrix.outputs.matrix)}}
100105
steps:
101-
- name: Checkout Repo
102-
uses: actions/checkout@v4
103-
- name: aws-oidc
104-
uses: aws-actions/[email protected]
106+
- name: Build Nix Package
107+
uses: ./.github/actions/nix-build-setup
105108
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 }}
109+
attr: ${{ matrix.attr }}
131110

132111
run-tests:
133112
needs: build-checks

scripts/github-matrix.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ def parse_nix_eval_line(
114114
"system": data["system"],
115115
"already_cached": data.get("cacheStatus") != "notBuilt",
116116
"runs_on": runs_on_config,
117+
"drv": data["drvPath"], # For debugging purposes
118+
"outputs": data.get("outputs", {}), # For debugging purposes
117119
}
118120
except json.JSONDecodeError:
119121
print(f"Skipping invalid JSON line: {line}", file=sys.stderr)
@@ -177,7 +179,21 @@ def main() -> None:
177179
if is_extension_pkg(pkg)
178180
]
179181

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

183199

0 commit comments

Comments
 (0)