44 push :
55 branches :
66 - master
7+ - main
78 tags :
89 - v*
10+ paths-ignore :
11+ - ' **.md'
12+ - ' **.rst'
13+ workflow_dispatch : {}
914 repository_dispatch :
10- types : [run_build]
15+ types :
16+ - run_build
1117
1218jobs :
1319 build :
20+ strategy :
21+ matrix :
22+ platform :
23+ - runs-on : ubuntu-latest
24+ container-platform : linux/amd64
25+ - runs-on : ubuntu-24.04-arm
26+ container-platform : linux/arm64
27+ runs-on : ${{ matrix.platform.runs-on }}
28+ timeout-minutes : 180
29+
30+ steps :
31+ - name : Checkout repository
32+ uses : actions/checkout@v4
33+
34+ - name : Prepare
35+ run : |
36+ platform=${{ matrix.platform.container-platform }}
37+ printf 'PLATFORM_PAIR=%s\n' "${platform//\//-}" >> $GITHUB_ENV
38+
39+ - name : Login to Github Container Registry
40+ uses : docker/login-action@v3
41+ with :
42+ registry : ghcr.io
43+ username : ${{ github.actor }}
44+ password : ${{ secrets.GITHUB_TOKEN }}
45+
46+ - name : Prepare additional environment variables from repo
47+ run : if test -f ./config/ci-docker-env.ini; then cat ./config/ci-docker-env.ini | sed -e 's/$REPOSITORY_OWNER/'"${{ github.repository_owner }}"'/g;s/$DOCKER_TAG/'"${{ env.DOCKER_TAG }}"'/g' >> $GITHUB_ENV; fi
48+
49+ - name : Extract DOCKER_TAG using tag name
50+ if : env.BUILD_ARGS_LIST != null
51+ run : |
52+ printf 'BUILD_ARGS_LIST_NEWLINES<<EOF\n%s\nEOF\n' "${{ env.BUILD_ARGS_LIST }}" | tr ' ' $'\n' >> $GITHUB_ENV
53+
54+ - name : Docker meta
55+ id : meta
56+ uses : docker/metadata-action@v5
57+ with :
58+ images : ghcr.io/${{ github.repository }}
59+
60+ - name : Set up Docker Buildx
61+ uses : docker/setup-buildx-action@v3
62+
63+ - name : Build and Push to container registry
64+ id : build
65+ uses : docker/build-push-action@v6
66+ with :
67+ platforms : ${{ matrix.platform.container-platform }}
68+ labels : ${{ steps.meta.outputs.labels }}
69+ tags : ghcr.io/${{ github.repository }}
70+ outputs : type=image,push-by-digest=true,name-canonical=true,push=true
71+ build-args : ${{ env.BUILD_ARGS_LIST_NEWLINES }}
72+
73+ - name : Export digest
74+ run : |
75+ mkdir -p ${{ runner.temp }}/digests
76+ digest="${{ steps.build.outputs.digest }}"
77+ touch "${{ runner.temp }}/digests/${digest#sha256:}"
78+
79+ - name : Upload digest
80+ uses : actions/upload-artifact@v4
81+ with :
82+ name : digests-${{ env.PLATFORM_PAIR }}
83+ path : ${{ runner.temp }}/digests/*
84+ if-no-files-found : error
85+ retention-days : 1
86+
87+ merge :
88+ needs :
89+ - build
1490 runs-on : ubuntu-latest
91+ timeout-minutes : 20
1592 env :
1693 DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
1794 DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
18- DISPATCH_TOKEN : ${{ secrets.DISPATCH_TOKEN }}
95+ outputs :
96+ dest-repo : ${{ steps.dest-repo.outputs.DEST_REPO }}
1997
2098 steps :
21- - uses : actions/checkout@v4
99+ - name : Checkout repository
100+ uses : actions/checkout@v4
22101
23- - name : Extract DOCKER_TAG using tag name
24- if : startsWith(github.ref, 'refs/tags/')
102+ - name : Install Ubuntu packages
25103 run : |
26- printf '%s\n' "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
104+ sudo apt-get -y update
105+ sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq
27106
28- - name : Use default DOCKER_TAG
29- if : startsWith(github.ref, 'refs/tags/') != true
30- run : |
31- printf '%s\n' "DOCKER_TAG=latest" >> $GITHUB_ENV
107+ - name : Download digests
108+ uses : actions/download-artifact@v4
109+ with :
110+ path : ${{ runner.temp }}/digests
111+ pattern : digests-*
112+ merge-multiple : true
32113
33114 - name : Login to DockerHub
34115 uses : docker/login-action@v3
35116 if : env.DOCKER_USERNAME != null
36117 with :
37- username : ${{ secrets .DOCKER_USERNAME }}
38- password : ${{ secrets .DOCKER_PASSWORD }}
118+ username : ${{ env .DOCKER_USERNAME }}
119+ password : ${{ env .DOCKER_PASSWORD }}
39120
40121 - name : Login to Github Container Registry
41122 uses : docker/login-action@v3
@@ -44,43 +125,96 @@ jobs:
44125 username : ${{ github.actor }}
45126 password : ${{ secrets.GITHUB_TOKEN }}
46127
128+ - name : Extract DOCKER_TAG using tag name
129+ if : startsWith(github.ref, 'refs/tags/')
130+ run : |
131+ printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
132+
133+ - name : Use default DOCKER_TAG
134+ if : startsWith(github.ref, 'refs/tags/') != true
135+ run : |
136+ printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
137+
47138 - name : Set docker tag list to include DockerHub if credentials available
48139 if : env.DOCKER_USERNAME != null
49140 run : |
50- printf '%s\n' "DOCKER_TAG_LIST= ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}, ${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
141+ printf 'DOCKER_CONTAINER_LIST<<EOF\n %s\nEOF\ n' "ghcr.io/${{ github.repository }}"$'\n'" ${{ github.repository }}" >> $GITHUB_ENV
51142
52143 - name : Set docker tag list to not include DockerHub if credentials not available
53144 if : env.DOCKER_USERNAME == null
54145 run : |
55- printf '%s\n' "DOCKER_TAG_LIST= ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
146+ printf 'DOCKER_CONTAINER_LIST<<EOF\n %s\nEOF\ n' "ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
56147
57- - name : Build and Push to container registry
58- uses : docker/build-push-action@v5
148+ - name : Docker meta
149+ id : meta
150+ uses : docker/metadata-action@v5
59151 with :
60- push : true
61- tags : ${{ env.DOCKER_TAG_LIST }}
62- build-args : |
63- BASE_DOCKER_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain:${{ env.DOCKER_TAG }}
152+ images : ${{ env.DOCKER_CONTAINER_LIST }}
153+ tags : |
154+ type=raw,value=${{ env.DOCKER_TAG }}
155+
156+ - name : Set up Docker Buildx
157+ uses : docker/setup-buildx-action@v3
158+
159+ - name : Create manifest list and push
160+ working-directory : ${{ runner.temp }}/digests
161+ run : |
162+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
163+
164+ - name : Inspect image
165+ run : |
166+ docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
167+
168+ - name : Gather information for repository dispatch
169+ id : dest-repo
170+ run : if test -f ./config/repository-dispatch.ini; then cat ./config/repository-dispatch.ini >> $GITHUB_OUTPUT; fi
171+
172+ perform-repository-dispatch :
173+ needs :
174+ - merge
175+ runs-on : ubuntu-latest
176+ container :
177+ image : ubuntu:20.04
178+ options : " --user 0"
179+ timeout-minutes : 20
180+ env :
181+ DISPATCH_TOKEN : ${{ secrets.DISPATCH_TOKEN }}
182+ strategy :
183+ matrix :
184+ dest-repo : ${{ fromJson(needs.merge.outputs.dest-repo) }}
185+
186+ steps :
187+ - name : Gather environment variables (normal)
188+ if : github.event_name != 'repository_dispatch'
189+ run : |
190+ printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.repository }}" >> $GITHUB_ENV
191+ printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.sha }}" >> $GITHUB_ENV
192+
193+ - name : Gather environment variables (dispatch)
194+ if : github.event_name == 'repository_dispatch'
195+ run : |
196+ printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.event.client_payload.parent_name }}" >> $GITHUB_ENV
197+ printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.event.client_payload.parent_sha }}" >> $GITHUB_ENV
64198
65199 - name : Send Compile action
66200 run : |
67- export DISPATCH_ACTION="$(printf '%s \n' run_build )"
68- printf '%s\n' "NEW_DISPATCH_ACTION= $DISPATCH_ACTION" >> $GITHUB_ENV
201+ export DISPATCH_ACTION="$(printf 'run_build \n')"
202+ printf 'NEW_DISPATCH_ACTION= %s\n' "$DISPATCH_ACTION" >> $GITHUB_ENV
69203
70- - name : Repository Dispatch to ps2sdk-ports
204+ - name : Repository Dispatch to ${{ matrix.dest-repo }}
71205 uses : peter-evans/repository-dispatch@v3
72- if : env.DISPATCH_TOKEN != null
206+ if : env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/')
73207 with :
74- repository : ${{ github.repository_owner }}/ps2sdk-ports
208+ repository : ${{ github.repository_owner }}/${{ matrix.dest-repo }}
75209 token : ${{ secrets.DISPATCH_TOKEN }}
76210 event-type : ${{ env.NEW_DISPATCH_ACTION }}
77- client-payload : ' {"ref": "${{ github.ref }}"}'
211+ client-payload : ' {"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}" }'
78212
79- - name : Repository Dispatch to ps2-packer
213+ - name : Repository Dispatch to specific ${{ matrix.dest-repo }}
80214 uses : peter-evans/repository-dispatch@v3
81- if : env.DISPATCH_TOKEN != null
215+ if : env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/')
82216 with :
83- repository : ${{ github.repository_owner }}/ps2-packer
217+ repository : ${{ matrix.dest-repo }}
84218 token : ${{ secrets.DISPATCH_TOKEN }}
85219 event-type : ${{ env.NEW_DISPATCH_ACTION }}
86- client-payload : ' {"ref": "${{ github.ref }}"}'
220+ client-payload : ' {"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}" }'
0 commit comments