Skip to content

Commit 473df02

Browse files
authored
Merge pull request #44 from uyjulian/ci_improvements_20250918
CI improvements 20250918
2 parents 2124267 + 87a176b commit 473df02

File tree

4 files changed

+203
-24
lines changed

4 files changed

+203
-24
lines changed

.github/workflows/compilation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111
runs-on: ubuntu-latest
12-
container: ${{ github.repository_owner }}/ps2sdk:latest
12+
container: ghcr.io/ps2dev/ps2sdk:latest
1313
steps:
1414
- uses: actions/checkout@v4
1515

.github/workflows/docker.yml

100644100755
Lines changed: 198 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,227 @@ 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]
11-
15+
types:
16+
- run_build
1217

1318
jobs:
1419
build:
15-
runs-on: ubuntu-latest
16-
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+
1730
steps:
18-
- 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 }}
1945

2046
- name: Extract DOCKER_TAG using tag name
2147
if: startsWith(github.ref, 'refs/tags/')
2248
run: |
23-
echo "DOCKER_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
49+
printf 'DOCKER_TAG=%s\n' "${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
2450
2551
- name: Use default DOCKER_TAG
2652
if: startsWith(github.ref, 'refs/tags/') != true
2753
run: |
28-
echo "DOCKER_TAG=latest" >> $GITHUB_ENV
29-
30-
- name: Login to Github registry
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
123+
124+
- name: Login to DockerHub
125+
uses: docker/login-action@v3
126+
if: env.DOCKER_USERNAME != null
127+
with:
128+
username: ${{ env.DOCKER_USERNAME }}
129+
password: ${{ env.DOCKER_PASSWORD }}
130+
131+
- name: Login to Github Container Registry
31132
uses: docker/login-action@v3
32133
with:
33-
username: ${{ github.actor }}
34-
password: ${{ secrets.GITHUB_TOKEN }}
35134
registry: ghcr.io
135+
username: ${{ github.actor }}
136+
password: ${{ secrets.GITHUB_TOKEN }}
137+
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
36142
37-
- uses: docker/build-push-action@v5
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+
148+
- name: Set docker tag list to include DockerHub if credentials available
149+
if: env.DOCKER_USERNAME != null
150+
run: |
151+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}"$'\n'"${{ github.repository }}" >> $GITHUB_ENV
152+
153+
- name: Set docker tag list to not include DockerHub if credentials not available
154+
if: env.DOCKER_USERNAME == null
155+
run: |
156+
printf 'DOCKER_CONTAINER_LIST<<EOF\n%s\nEOF\n' "ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
157+
158+
- name: Docker meta
159+
id: meta
160+
uses: docker/metadata-action@v5
38161
with:
39-
push: true
40-
tags: ghcr.io/${{ github.repository }}:${{ env.DOCKER_TAG }}
41-
build-args: |
42-
BASE_DOCKER_IMAGE=${{ github.repository_owner }}/ps2sdk:${{ env.DOCKER_TAG }}
43-
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
208+
44209
- name: Send Compile action
45210
run: |
46-
export DISPATCH_ACTION="$(echo run_build)"
47-
echo "NEW_DISPATCH_ACTION=$DISPATCH_ACTION" >> $GITHUB_ENV
48-
49-
- name: Repository Dispatch to ps2link
211+
export DISPATCH_ACTION="$(printf 'run_build\n')"
212+
printf 'NEW_DISPATCH_ACTION=%s\n' "$DISPATCH_ACTION" >> $GITHUB_ENV
213+
214+
- name: Repository Dispatch to ${{ matrix.dest-repo }}
215+
uses: peter-evans/repository-dispatch@v3
216+
if: env.DISPATCH_TOKEN != null && !contains(matrix.dest-repo, '/')
217+
with:
218+
repository: ${{ github.repository_owner }}/${{ matrix.dest-repo }}
219+
token: ${{ secrets.DISPATCH_TOKEN }}
220+
event-type: ${{ env.NEW_DISPATCH_ACTION }}
221+
client-payload: '{"ref": "${{ github.ref }}", "parent_name": "${{ env.PAYLOAD_REPO_PARENT_NAME }}", "parent_sha": "${{ env.PAYLOAD_REPO_PARENT_SHA }}"}'
222+
223+
- name: Repository Dispatch to specific ${{ matrix.dest-repo }}
50224
uses: peter-evans/repository-dispatch@v3
225+
if: env.DISPATCH_TOKEN != null && contains(matrix.dest-repo, '/')
51226
with:
52-
repository: ${{ github.repository_owner }}/ps2link
227+
repository: ${{ matrix.dest-repo }}
53228
token: ${{ secrets.DISPATCH_TOKEN }}
54229
event-type: ${{ env.NEW_DISPATCH_ACTION }}
55-
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/ps2sdk:$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=["ps2link"]

0 commit comments

Comments
 (0)