Skip to content

Commit f010105

Browse files
authored
Merge pull request #784 from uyjulian/ci_improvements_20250918
CI improvements 20250918
2 parents 6e1c57b + de4ac43 commit f010105

File tree

4 files changed

+179
-31
lines changed

4 files changed

+179
-31
lines changed

.github/workflows/compilation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
matrix:
1414
debug: [all, debug]
1515
runs-on: ubuntu-latest
16-
container: ps2dev/ps2toolchain:latest
16+
container: ghcr.io/ps2dev/ps2toolchain:latest
1717
steps:
1818
- uses: actions/checkout@v4
1919

.github/workflows/docker.yml

100644100755
Lines changed: 174 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,129 @@ on:
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

1218
jobs:
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
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 }}
2245

2346
- name: Extract DOCKER_TAG using tag name
2447
if: startsWith(github.ref, 'refs/tags/')
2548
run: |
26-
printf '%s\n' "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
27-
49+
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
50+
2851
- name: Use default DOCKER_TAG
2952
if: startsWith(github.ref, 'refs/tags/') != true
3053
run: |
31-
printf '%s\n' "DOCKER_TAG=latest" >> $GITHUB_ENV
54+
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
55+
56+
- name: Prepare additional environment variables from repo
57+
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
58+
59+
- name: Extract DOCKER_TAG using tag name
60+
if: env.BUILD_ARGS_LIST != null
61+
run: |
62+
printf 'BUILD_ARGS_LIST_NEWLINES<<EOF\n%s\nEOF\n' "${{ env.BUILD_ARGS_LIST }}" | tr ' ' $'\n' >> $GITHUB_ENV
63+
64+
- name: Docker meta
65+
id: meta
66+
uses: docker/metadata-action@v5
67+
with:
68+
images: ghcr.io/${{ github.repository }}
69+
70+
- name: Set up Docker Buildx
71+
uses: docker/setup-buildx-action@v3
72+
73+
- name: Build and Push to container registry
74+
id: build
75+
uses: docker/build-push-action@v6
76+
with:
77+
platforms: ${{ matrix.platform.container-platform }}
78+
labels: ${{ steps.meta.outputs.labels }}
79+
tags: ghcr.io/${{ github.repository }}
80+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
81+
build-args: ${{ env.BUILD_ARGS_LIST_NEWLINES }}
82+
83+
- name: Export digest
84+
run: |
85+
mkdir -p ${{ runner.temp }}/digests
86+
digest="${{ steps.build.outputs.digest }}"
87+
touch "${{ runner.temp }}/digests/${digest#sha256:}"
88+
89+
- name: Upload digest
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: digests-${{ env.PLATFORM_PAIR }}
93+
path: ${{ runner.temp }}/digests/*
94+
if-no-files-found: error
95+
retention-days: 1
96+
97+
merge:
98+
needs:
99+
- build
100+
runs-on: ubuntu-latest
101+
timeout-minutes: 20
102+
env:
103+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
104+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
105+
outputs:
106+
dest-repo: ${{ steps.dest-repo.outputs.DEST_REPO }}
107+
108+
steps:
109+
- name: Checkout repository
110+
uses: actions/checkout@v4
111+
112+
- name: Install Ubuntu packages
113+
run: |
114+
sudo apt-get -y update
115+
sudo apt-get -y -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' install jq
116+
117+
- name: Download digests
118+
uses: actions/download-artifact@v4
119+
with:
120+
path: ${{ runner.temp }}/digests
121+
pattern: digests-*
122+
merge-multiple: true
32123

33124
- name: Login to DockerHub
34125
uses: docker/login-action@v3
35126
if: env.DOCKER_USERNAME != null
36127
with:
37-
username: ${{ secrets.DOCKER_USERNAME }}
38-
password: ${{ secrets.DOCKER_PASSWORD }}
128+
username: ${{ env.DOCKER_USERNAME }}
129+
password: ${{ env.DOCKER_PASSWORD }}
39130

40131
- name: Login to Github Container Registry
41132
uses: docker/login-action@v3
@@ -44,43 +135,96 @@ jobs:
44135
username: ${{ github.actor }}
45136
password: ${{ secrets.GITHUB_TOKEN }}
46137

138+
- name: Extract DOCKER_TAG using tag name
139+
if: startsWith(github.ref, 'refs/tags/')
140+
run: |
141+
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
142+
143+
- name: Use default DOCKER_TAG
144+
if: startsWith(github.ref, 'refs/tags/') != true
145+
run: |
146+
printf 'DOCKER_TAG=%s\n' "latest" >> $GITHUB_ENV
147+
47148
- name: Set docker tag list to include DockerHub if credentials available
48149
if: env.DOCKER_USERNAME != null
49150
run: |
50-
printf '%s\n' "DOCKER_TAG_LIST=ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }},${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
151+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}"$'\n'"${{ github.repository }}" >> $GITHUB_ENV
51152
52153
- name: Set docker tag list to not include DockerHub if credentials not available
53154
if: env.DOCKER_USERNAME == null
54155
run: |
55-
printf '%s\n' "DOCKER_TAG_LIST=ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}" >> $GITHUB_ENV
156+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
56157
57-
- name: Build and Push to container registry
58-
uses: docker/build-push-action@v5
158+
- name: Docker meta
159+
id: meta
160+
uses: docker/metadata-action@v5
59161
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 }}
162+
images: ${{ env.DOCKER_CONTAINER_LIST }}
163+
tags: |
164+
type=raw,value=${{ env.DOCKER_TAG }}
165+
166+
- name: Set up Docker Buildx
167+
uses: docker/setup-buildx-action@v3
168+
169+
- name: Create manifest list and push
170+
working-directory: ${{ runner.temp }}/digests
171+
run: |
172+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *)
173+
174+
- name: Inspect image
175+
run: |
176+
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:${{ steps.meta.outputs.version }}
177+
178+
- name: Gather information for repository dispatch
179+
id: dest-repo
180+
run: if test -f ./config/repository-dispatch.ini; then cat ./config/repository-dispatch.ini >> $GITHUB_OUTPUT; fi
181+
182+
perform-repository-dispatch:
183+
needs:
184+
- merge
185+
runs-on: ubuntu-latest
186+
container:
187+
image: ubuntu:20.04
188+
options: "--user 0"
189+
timeout-minutes: 20
190+
env:
191+
DISPATCH_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
192+
strategy:
193+
matrix:
194+
dest-repo: ${{ fromJson(needs.merge.outputs.dest-repo) }}
195+
196+
steps:
197+
- name: Gather environment variables (normal)
198+
if: github.event_name != 'repository_dispatch'
199+
run: |
200+
printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.repository }}" >> $GITHUB_ENV
201+
printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.sha }}" >> $GITHUB_ENV
202+
203+
- name: Gather environment variables (dispatch)
204+
if: github.event_name == 'repository_dispatch'
205+
run: |
206+
printf 'PAYLOAD_REPO_PARENT_NAME=%s\n' "${{ github.event.client_payload.parent_name }}" >> $GITHUB_ENV
207+
printf 'PAYLOAD_REPO_PARENT_SHA=%s\n' "${{ github.event.client_payload.parent_sha }}" >> $GITHUB_ENV
64208
65209
- name: Send Compile action
66210
run: |
67-
export DISPATCH_ACTION="$(printf '%s\n' run_build)"
68-
printf '%s\n' "NEW_DISPATCH_ACTION=$DISPATCH_ACTION" >> $GITHUB_ENV
211+
export DISPATCH_ACTION="$(printf 'run_build\n')"
212+
printf 'NEW_DISPATCH_ACTION=%s\n' "$DISPATCH_ACTION" >> $GITHUB_ENV
69213
70-
- name: Repository Dispatch to ps2sdk-ports
214+
- name: Repository Dispatch to ${{ matrix.dest-repo }}
71215
uses: peter-evans/repository-dispatch@v3
72-
if: env.DISPATCH_TOKEN != null
216+
if: env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/')
73217
with:
74-
repository: ${{ github.repository_owner }}/ps2sdk-ports
218+
repository: ${{ github.repository_owner }}/${{ matrix.dest-repo }}
75219
token: ${{ secrets.DISPATCH_TOKEN }}
76220
event-type: ${{ env.NEW_DISPATCH_ACTION }}
77-
client-payload: '{"ref": "${{ github.ref }}"}'
221+
client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'
78222

79-
- name: Repository Dispatch to ps2-packer
223+
- name: Repository Dispatch to specific ${{ matrix.dest-repo }}
80224
uses: peter-evans/repository-dispatch@v3
81-
if: env.DISPATCH_TOKEN != null
225+
if: env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/')
82226
with:
83-
repository: ${{ github.repository_owner }}/ps2-packer
227+
repository: ${{ matrix.dest-repo }}
84228
token: ${{ secrets.DISPATCH_TOKEN }}
85229
event-type: ${{ env.NEW_DISPATCH_ACTION }}
86-
client-payload: '{"ref": "${{ github.ref }}"}'
230+
client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'

config/ci-docker-env.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
BASE_DOCKER_IMAGE=ghcr.io/$REPOSITORY_OWNER/ps2toolchain:$DOCKER_TAG
3+
BUILD_ARGS_LIST=BASE_DOCKER_IMAGE

config/repository-dispatch.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DEST_REPO=["ps2sdk-ports", "ps2-packer"]

0 commit comments

Comments
 (0)