@@ -19,124 +19,69 @@ jobs:
19
19
- name : Checkout Repo
20
20
uses : actions/checkout@v3
21
21
22
- - uses : DeterminateSystems/nix-installer-action@main
22
+ - name : Install Nushell
23
+ run : |
24
+ sudo apt update
25
+ sudo apt install -y nushell
23
26
24
27
- name : Generate build matrix
25
28
id : set-matrix
26
29
run : |
27
- # Get all postgres versions from vars.yml
28
- VERSIONS=$(nix run nixpkgs#yq -- '.postgres_major[]' ansible/vars.yml)
29
-
30
- # Create matrix config
31
- MATRIX_CONFIG="{"
32
- MATRIX_CONFIG+="\"include\":["
33
- FIRST=true
34
-
35
- while IFS= read -r version; do
36
- # Remove quotes from version
37
- version=$(echo "$version" | tr -d '"')
38
-
39
- # Simply look for Dockerfile-{version}
40
- dockerfile="Dockerfile-${version}"
41
-
42
- # Check if Dockerfile exists
43
- if [ -f "$dockerfile" ]; then
44
- if [ "$FIRST" = true ]; then
45
- FIRST=false
46
- else
47
- MATRIX_CONFIG+=","
48
- fi
49
- MATRIX_CONFIG+="{\"version\":\"$version\",\"dockerfile\":\"$dockerfile\"}"
50
- fi
51
- done <<< "$VERSIONS"
52
-
53
- MATRIX_CONFIG+="]}"
54
-
55
- # Output the matrix configuration
56
- echo "matrix_config=$MATRIX_CONFIG" >> $GITHUB_OUTPUT
30
+ nu -c 'let versions = (open ansible/vars.yml | get postgres_major)
31
+ let matrix = ($versions | each { |ver|
32
+ let version = ($ver | str trim)
33
+ let dockerfile = $"Dockerfile-($version)"
34
+ if ($dockerfile | path exists) {
35
+ {
36
+ version: $version,
37
+ dockerfile: $dockerfile
38
+ }
39
+ } else {
40
+ null
41
+ }
42
+ } | compact)
43
+
44
+ let matrix_config = {
45
+ include: $matrix
46
+ }
47
+
48
+ "matrix_config=" + ($matrix_config | to json) | save --append $env.GITHUB_OUTPUT'
57
49
build :
58
50
needs : prepare
59
51
strategy :
60
52
matrix : ${{ fromJson(needs.prepare.outputs.matrix_config) }}
61
53
runs-on : ubuntu-latest
62
54
outputs :
63
- versions : ${{ steps.combine-outputs.outputs.versions }}
64
- image_tags : ${{ steps.combine-outputs.outputs.image_tags }}
65
55
build_args : ${{ steps.args.outputs.result }}
66
56
steps :
67
57
- uses : actions/checkout@v3
68
-
69
- - uses : DeterminateSystems/nix-installer-action@main
70
-
58
+
71
59
- name : Set PostgreSQL version environment variable
72
60
run : echo "POSTGRES_MAJOR_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
73
61
74
62
- name : Generate common-nix.vars.pkr.hcl
75
63
run : |
76
- PG_VERSION=$(nix run nixpkgs#yq -- '.postgres_release["postgres${{ matrix.version }}"]' ansible/vars.yml)
77
- PG_VERSION=$(echo $PG_VERSION | tr -d '"') # Remove any surrounding quotes
78
- echo 'postgres-version = "'$PG_VERSION'"' > common-nix.vars.pkr.hcl
79
- echo "" >> common-nix.vars.pkr.hcl
64
+ nu -c 'let pg_version = (open ansible/vars.yml | get postgres_release | get $"postgres${{ matrix.version }}" | str trim)
65
+ $"postgres-version = \"($pg_version)\"" | save common-nix.vars.pkr.hcl
66
+ "" | save --append common-nix.vars.pkr.hcl'
80
67
- id : settings
81
- run : sed -r 's/(\s|\")+//g' common-nix.vars.pkr.hcl >> $GITHUB_OUTPUT
82
-
83
- - id : args
84
- uses : mikefarah/yq@master
85
- with :
86
- cmd : yq 'to_entries | map(select(.value|type == "!!str")) | map(.key + "=" + .value) | join("\n")' 'ansible/vars.yml'
87
-
88
- # Create workflow artifact with this matrix run's version info
89
- - name : Save version info
90
68
run : |
91
- mkdir -p ./versions
92
- echo "${{ matrix.version }}" > ./versions/version.txt
93
- echo "supabase/postgres:${{ steps.settings.outputs.postgres-version }}" > ./versions/tag.txt
94
- - uses : actions/upload-artifact@v3
95
- with :
96
- name : version-info-${{ matrix.version }}
97
- path : ./versions/
98
-
99
- # Only run in first matrix job to combine all outputs
100
- - if : matrix.version == fromJson(needs.prepare.outputs.matrix_config).include[0].version
101
- id : combine-outputs
69
+ nu -c 'open common-nix.vars.pkr.hcl | str replace -a "[\\s\"]+" "" | save --append $env.GITHUB_OUTPUT'
70
+ - id : args
102
71
run : |
103
- # Wait for other matrix jobs to complete by sleeping briefly
104
- sleep 15
105
- # Create arrays to hold all versions and tags
106
- versions_array="["
107
- tags_array="["
108
- first=true
109
- # For each version in the matrix config
110
- for row in $(echo '${{ needs.prepare.outputs.matrix_config }}' | jq -c '.include[]'); do
111
- version=$(echo $row | jq -r '.version')
112
-
113
- if [ "$first" = true ]; then
114
- first=false
115
- else
116
- versions_array+=","
117
- tags_array+=","
118
- fi
119
-
120
- # Download and read artifacts
121
- mkdir -p ./download
122
- echo "Processing version $version"
123
-
124
- tag=$(cat ./versions/tag.txt)
125
-
126
- versions_array+="\"$version\""
127
- tags_array+="\"$tag\""
128
- done
129
- versions_array+="]"
130
- tags_array+="]"
131
- # Set outputs
132
- echo "versions=$versions_array" >> $GITHUB_OUTPUT
133
- echo "image_tags=$tags_array" >> $GITHUB_OUTPUT
72
+ nu -c '
73
+ open ansible/vars.yml
74
+ | items { |key value| {name: $key, item: $value} }
75
+ | where { |it| ($it.item | describe) == "string" }
76
+ | each { |it| $"($it.name)=($it.item)" }
77
+ | str join "\n"
78
+ | save --append $env.GITHUB_OUTPUT
79
+ '
134
80
build_release_image :
135
- needs : build
81
+ needs : [prepare, build]
136
82
strategy :
137
83
matrix :
138
- version : ${{ fromJson(needs.build.outputs.versions) }}
139
- image_tag : ${{ fromJson(needs.build.outputs.image_tags) }}
84
+ include : ${{ fromJson(needs.prepare.outputs.matrix_config).include }}
140
85
arch : [amd64, arm64]
141
86
runs-on : ${{ matrix.arch == 'amd64' && fromJson('["self-hosted", "X64"]') || 'arm-runner' }}
142
87
timeout-minutes : 180
@@ -150,18 +95,30 @@ jobs:
150
95
with :
151
96
username : ${{ secrets.DOCKER_USERNAME }}
152
97
password : ${{ secrets.DOCKER_PASSWORD }}
98
+ - name : Get image tag
99
+ run : |
100
+ nu -c '
101
+ let version = "${{ matrix.version }}"
102
+ let release_key = if ($version | str contains "orioledb") {
103
+ $"postgres($version | str replace "-" "")"
104
+ } else {
105
+ $"postgres($version)"
106
+ }
107
+ let pg_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
108
+ $"supabase/postgres:($pg_version)" | save --append $env.GITHUB_ENV
109
+ '
153
110
- id : build
154
111
uses : docker/build-push-action@v5
155
112
with :
156
113
push : true
157
114
build-args : |
158
115
${{ needs.build.outputs.build_args }}
159
116
target : production
160
- tags : ${{ matrix.image_tag }}_${{ matrix.arch }}
117
+ tags : ${{ env.pg_version }}_${{ matrix.arch }}
161
118
platforms : linux/${{ matrix.arch }}
162
119
cache-from : type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
163
120
cache-to : type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
164
- file : Dockerfile- ${{ matrix.version }}
121
+ file : ${{ matrix.dockerfile }}
165
122
- name : Slack Notification
166
123
if : ${{ failure() }}
167
124
uses : rtCamp/action-slack-notify@v2
@@ -173,50 +130,69 @@ jobs:
173
130
SLACK_FOOTER : " "
174
131
175
132
merge_manifest :
176
- needs : [build, build_release_image]
133
+ needs : [prepare, build, build_release_image]
177
134
strategy :
178
135
matrix :
179
- image_tag : ${{ fromJson(needs.build .outputs.image_tags) }}
136
+ include : ${{ fromJson(needs.prepare .outputs.matrix_config).include }}
180
137
runs-on : ubuntu-latest
181
138
steps :
139
+ - uses : actions/checkout@v3
182
140
- uses : docker/setup-buildx-action@v3
183
141
- uses : docker/login-action@v2
184
142
with :
185
143
username : ${{ secrets.DOCKER_USERNAME }}
186
144
password : ${{ secrets.DOCKER_PASSWORD }}
145
+ - name : Get image tag
146
+ run : |
147
+ nu -c '
148
+ let version = "${{ matrix.version }}"
149
+ let release_key = if ($version | str contains "orioledb") {
150
+ $"postgres($version | str replace "-" "")"
151
+ } else {
152
+ $"postgres($version)"
153
+ }
154
+ let pg_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
155
+ $"supabase/postgres:($pg_version)" | save --append $env.GITHUB_ENV
156
+ '
187
157
- name : Merge multi-arch manifests
188
158
run : |
189
- docker buildx imagetools create -t ${{ matrix.image_tag }} \
190
- ${{ matrix.image_tag }}_amd64 \
191
- ${{ matrix.image_tag }}_arm64
192
- - name : Slack Notification
193
- if : ${{ failure() }}
194
- uses : rtCamp/action-slack-notify@v2
195
- env :
196
- SLACK_WEBHOOK : ${{ secrets.SLACK_NOTIFICATIONS_WEBHOOK }}
197
- SLACK_USERNAME : " gha-failures-notifier"
198
- SLACK_COLOR : " danger"
199
- SLACK_MESSAGE : " Building Postgres image failed for version ${{ matrix.version }}"
200
- SLACK_FOOTER : " "
201
-
159
+ docker buildx imagetools create -t ${{ env.pg_version }} \
160
+ ${{ env.pg_version }}_amd64 \
161
+ ${{ env.pg_version }}_arm64
202
162
get_publish_version :
203
- needs : [build , merge_manifest]
163
+ needs : [prepare , merge_manifest]
204
164
strategy :
205
165
matrix :
206
- image_tag : ${{ fromJson(needs.build .outputs.image_tags) }}
166
+ include : ${{ fromJson(needs.prepare .outputs.matrix_config).include }}
207
167
runs-on : ubuntu-latest
208
168
outputs :
209
- version : ${{ steps.get_version .outputs.version }}
169
+ matrix : ${{ steps.get_versions .outputs.matrix }}
210
170
steps :
211
- - id : get_version
171
+ - uses : actions/checkout@v3
172
+ - name : Get versions
173
+ id : get_versions
212
174
run : |
213
- VERSION=$(echo "${{ matrix.image_tag }}" | sed 's|supabase/postgres:||')
214
- # Changed to match the output name expected by the publish job
215
- echo "Extracted version: $VERSION"
216
- echo "version=$VERSION" >> $GITHUB_OUTPUT
175
+ nu -c '
176
+ let versions = ${{ fromJson(needs.prepare.outputs.matrix_config).include | select(.version) | to array }}
177
+ let versions_array = ($versions | each { |ver|
178
+ let version = $ver.version
179
+ let release_key = if ($version | str contains "orioledb") {
180
+ $"postgres($version | str replace "-" "")"
181
+ } else {
182
+ $"postgres($version)"
183
+ }
184
+ let pg_version = (open ansible/vars.yml | get postgres_release | get $release_key | str trim)
185
+ {version: $pg_version}
186
+ })
187
+ let matrix = {include: $versions_array}
188
+ $"matrix=($matrix | to json)" | save --append $env.GITHUB_OUTPUT
189
+ '
190
+
217
191
publish :
218
192
needs : get_publish_version
193
+ strategy :
194
+ matrix : ${{ fromJson(needs.get_publish_version.outputs.matrix) }}
219
195
uses : ./.github/workflows/mirror.yml
220
196
with :
221
- version : ${{ needs.get_publish_version.outputs .version }}
222
- secrets : inherit
197
+ version : ${{ matrix .version }}
198
+ secrets : inherit
0 commit comments