@@ -19,124 +19,69 @@ jobs:
1919 - name : Checkout Repo
2020 uses : actions/checkout@v3
2121
22- - uses : DeterminateSystems/nix-installer-action@main
22+ - name : Install Nushell
23+ run : |
24+ sudo apt update
25+ sudo apt install -y nushell
2326
2427 - name : Generate build matrix
2528 id : set-matrix
2629 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'
5749 build :
5850 needs : prepare
5951 strategy :
6052 matrix : ${{ fromJson(needs.prepare.outputs.matrix_config) }}
6153 runs-on : ubuntu-latest
6254 outputs :
63- versions : ${{ steps.combine-outputs.outputs.versions }}
64- image_tags : ${{ steps.combine-outputs.outputs.image_tags }}
6555 build_args : ${{ steps.args.outputs.result }}
6656 steps :
6757 - uses : actions/checkout@v3
68-
69- - uses : DeterminateSystems/nix-installer-action@main
70-
58+
7159 - name : Set PostgreSQL version environment variable
7260 run : echo "POSTGRES_MAJOR_VERSION=${{ matrix.version }}" >> $GITHUB_ENV
7361
7462 - name : Generate common-nix.vars.pkr.hcl
7563 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'
8067 - 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
9068 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
10271 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+ '
13480 build_release_image :
135- needs : build
81+ needs : [prepare, build]
13682 strategy :
13783 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 }}
14085 arch : [amd64, arm64]
14186 runs-on : ${{ matrix.arch == 'amd64' && fromJson('["self-hosted", "X64"]') || 'arm-runner' }}
14287 timeout-minutes : 180
@@ -150,18 +95,30 @@ jobs:
15095 with :
15196 username : ${{ secrets.DOCKER_USERNAME }}
15297 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+ '
153110 - id : build
154111 uses : docker/build-push-action@v5
155112 with :
156113 push : true
157114 build-args : |
158115 ${{ needs.build.outputs.build_args }}
159116 target : production
160- tags : ${{ matrix.image_tag }}_${{ matrix.arch }}
117+ tags : ${{ env.pg_version }}_${{ matrix.arch }}
161118 platforms : linux/${{ matrix.arch }}
162119 cache-from : type=gha,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
163120 cache-to : type=gha,mode=max,scope=${{ github.ref_name }}-latest-${{ matrix.arch }}
164- file : Dockerfile- ${{ matrix.version }}
121+ file : ${{ matrix.dockerfile }}
165122 - name : Slack Notification
166123 if : ${{ failure() }}
167124 uses : rtCamp/action-slack-notify@v2
@@ -173,50 +130,69 @@ jobs:
173130 SLACK_FOOTER : " "
174131
175132 merge_manifest :
176- needs : [build, build_release_image]
133+ needs : [prepare, build, build_release_image]
177134 strategy :
178135 matrix :
179- image_tag : ${{ fromJson(needs.build .outputs.image_tags) }}
136+ include : ${{ fromJson(needs.prepare .outputs.matrix_config).include }}
180137 runs-on : ubuntu-latest
181138 steps :
139+ - uses : actions/checkout@v3
182140 - uses : docker/setup-buildx-action@v3
183141 - uses : docker/login-action@v2
184142 with :
185143 username : ${{ secrets.DOCKER_USERNAME }}
186144 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+ '
187157 - name : Merge multi-arch manifests
188158 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
202162 get_publish_version :
203- needs : [build , merge_manifest]
163+ needs : [prepare , merge_manifest]
204164 strategy :
205165 matrix :
206- image_tag : ${{ fromJson(needs.build .outputs.image_tags) }}
166+ include : ${{ fromJson(needs.prepare .outputs.matrix_config).include }}
207167 runs-on : ubuntu-latest
208168 outputs :
209- version : ${{ steps.get_version .outputs.version }}
169+ matrix : ${{ steps.get_versions .outputs.matrix }}
210170 steps :
211- - id : get_version
171+ - uses : actions/checkout@v3
172+ - name : Get versions
173+ id : get_versions
212174 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+
217191 publish :
218192 needs : get_publish_version
193+ strategy :
194+ matrix : ${{ fromJson(needs.get_publish_version.outputs.matrix) }}
219195 uses : ./.github/workflows/mirror.yml
220196 with :
221- version : ${{ needs.get_publish_version.outputs .version }}
222- secrets : inherit
197+ version : ${{ matrix .version }}
198+ secrets : inherit
0 commit comments