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 :
14- runs-on : ubuntu-latest
15- env :
16- DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
17- DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
18- DISPATCH_TOKEN : ${{ secrets.DISPATCH_TOKEN }}
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
1929
2030 steps :
21- - uses : actions/checkout@v4
31+ - name : Checkout repository
32+ uses : actions/checkout@v4
2233
23- - name : Extract DOCKER_TAG using tag name
24- if : startsWith(github.ref, 'refs/tags/')
34+ - name : Prepare
2535 run : |
26- echo "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
36+ platform=${{ matrix.platform.container-platform }}
37+ printf 'PLATFORM_PAIR=%s\n' "${platform//\//-}" >> $GITHUB_ENV
2738
28- - name : Use default DOCKER_TAG
29- if : startsWith(github.ref, 'refs/tags/') != true
30- run : |
31- echo "DOCKER_TAG=latest" >> $GITHUB_ENV
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
3248
33- - name : Set up QEMU
34- uses : docker/setup-qemu-action@v3
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 }}
3559
3660 - name : Set up Docker Buildx
3761 uses : docker/setup-buildx-action@v3
3862
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
90+ runs-on : ubuntu-latest
91+ timeout-minutes : 20
92+ env :
93+ DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
94+ DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
95+ outputs :
96+ dest-repo : ${{ steps.dest-repo.outputs.DEST_REPO }}
97+
98+ steps :
99+ - name : Checkout repository
100+ uses : actions/checkout@v4
101+
102+ - name : Install Ubuntu packages
103+ run : |
104+ sudo apt-get -y update
105+ sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq
106+
107+ - name : Download digests
108+ uses : actions/download-artifact@v4
109+ with :
110+ path : ${{ runner.temp }}/digests
111+ pattern : digests-*
112+ merge-multiple : true
113+
39114 - name : Login to DockerHub
40115 uses : docker/login-action@v3
41116 if : env.DOCKER_USERNAME != null
42117 with :
43- username : ${{ secrets .DOCKER_USERNAME }}
44- password : ${{ secrets .DOCKER_PASSWORD }}
118+ username : ${{ env .DOCKER_USERNAME }}
119+ password : ${{ env .DOCKER_PASSWORD }}
45120
46121 - name : Login to Github Container Registry
47122 uses : docker/login-action@v3
@@ -50,36 +125,96 @@ jobs:
50125 username : ${{ github.actor }}
51126 password : ${{ secrets.GITHUB_TOKEN }}
52127
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+
53138 - name : Set docker tag list to include DockerHub if credentials available
54139 if : env.DOCKER_USERNAME != null
55140 run : |
56- echo "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
57142
58143 - name : Set docker tag list to not include DockerHub if credentials not available
59144 if : env.DOCKER_USERNAME == null
60145 run : |
61- echo "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
62147
63- - name : Build and Push to container registry
64- uses : docker/build-push-action@v5
148+ - name : Docker meta
149+ id : meta
150+ uses : docker/metadata-action@v5
65151 with :
66- push : true
67- tags : ${{ env.DOCKER_TAG_LIST }}
68- build-args : |
69- BASE_DOCKER_DVP_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-dvp:${{ env.DOCKER_TAG }}
70- BASE_DOCKER_IOP_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-iop:${{ env.DOCKER_TAG }}
71- BASE_DOCKER_EE_IMAGE=ghcr.io/${{ github.repository_owner }}/ps2toolchain-ee:${{ 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
72198
73199 - name : Send Compile action
74200 run : |
75- export DISPATCH_ACTION="$(echo run_build)"
76- echo "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
203+
204+ - name : Repository Dispatch to ${{ matrix.dest-repo }}
205+ uses : peter-evans/repository-dispatch@v3
206+ if : env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/')
207+ with :
208+ repository : ${{ github.repository_owner }}/${{ matrix.dest-repo }}
209+ token : ${{ secrets.DISPATCH_TOKEN }}
210+ event-type : ${{ env.NEW_DISPATCH_ACTION }}
211+ client-payload : ' {"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'
77212
78- - name : Repository Dispatch
213+ - name : Repository Dispatch to specific ${{ matrix.dest-repo }}
79214 uses : peter-evans/repository-dispatch@v3
80- if : env.DISPATCH_TOKEN != null
215+ if : env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/')
81216 with :
82- repository : ${{ github.repository_owner }}/ps2sdk
217+ repository : ${{ matrix.dest-repo }}
83218 token : ${{ secrets.DISPATCH_TOKEN }}
84219 event-type : ${{ env.NEW_DISPATCH_ACTION }}
85- 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