Skip to content

Commit 113e6c7

Browse files
committed
test matrix build
1 parent aeba3e0 commit 113e6c7

1 file changed

Lines changed: 80 additions & 26 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ jobs:
1919
docker:
2020
needs: test
2121
runs-on: ubuntu-latest
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
platform:
26+
- linux/amd64
27+
- linux/arm64
28+
outputs:
29+
version: ${{ steps.package-version.outputs.current-version }}
2230
steps:
2331
- name: Checkout
2432
uses: actions/checkout@v4
@@ -49,42 +57,88 @@ jobs:
4957
username: phalcode
5058
password: ${{ secrets.GITHUB_TOKEN }}
5159

52-
- name: Determine Docker tags
53-
id: tags
60+
- name: Build and Push by digest
61+
id: build
62+
uses: docker/build-push-action@v6
63+
with:
64+
platforms: ${{ matrix.platform }}
65+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
69+
- name: Export digest
70+
run: |
71+
mkdir -p /tmp/digests
72+
digest="${{ steps.build.outputs.digest }}"
73+
touch "/tmp/digests/${digest#sha256:}"
74+
75+
- name: Upload digest
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: digests-${{ strategy.job-index }}
79+
path: /tmp/digests/*
80+
if-no-files-found: error
81+
retention-days: 1
82+
83+
manifest:
84+
needs: docker
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Download digests
88+
uses: actions/download-artifact@v4
89+
with:
90+
path: /tmp/digests
91+
pattern: digests-*
92+
merge-multiple: true
93+
94+
- name: Set up Docker Buildx
95+
uses: docker/setup-buildx-action@v3
96+
97+
- name: Login to Docker Hub
98+
uses: docker/login-action@v3
99+
with:
100+
username: phalcode
101+
password: ${{ secrets.DOCKERHUB_TOKEN }}
102+
103+
- name: Login to GitHub Container Registry
104+
uses: docker/login-action@v3
105+
with:
106+
registry: ghcr.io
107+
username: phalcode
108+
password: ${{ secrets.GITHUB_TOKEN }}
109+
110+
- name: Create manifest list and push
54111
run: |
55112
BRANCH="${GITHUB_REF#refs/heads/}"
113+
VERSION="${{ needs.docker.outputs.version }}"
114+
115+
push_manifest() {
116+
local REPO=$1
117+
local TAGS=$2
118+
local ARGS=""
119+
for tag in $TAGS; do
120+
ARGS="$ARGS -t $REPO:$tag"
121+
done
122+
123+
docker buildx imagetools create $ARGS \
124+
$(printf "$REPO@sha256:%s " $(ls /tmp/digests))
125+
}
126+
56127
case "$BRANCH" in
57128
master|hotfix)
58-
echo "tags<<EOF" >> $GITHUB_OUTPUT
59-
echo "phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT
60-
echo "phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT
61-
echo "ghcr.io/phalcode/gamevault-backend:latest" >> $GITHUB_OUTPUT
62-
echo "ghcr.io/phalcode/gamevault-backend:${{ steps.package-version.outputs.current-version }}" >> $GITHUB_OUTPUT
63-
echo "EOF" >> $GITHUB_OUTPUT
129+
push_manifest "phalcode/gamevault-backend" "latest $VERSION"
130+
push_manifest "ghcr.io/phalcode/gamevault-backend" "latest $VERSION"
64131
;;
65132
develop)
66-
echo "tags<<EOF" >> $GITHUB_OUTPUT
67-
echo "phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT
68-
echo "ghcr.io/phalcode/gamevault-backend:unstable" >> $GITHUB_OUTPUT
69-
echo "EOF" >> $GITHUB_OUTPUT
133+
push_manifest "phalcode/gamevault-backend" "unstable"
134+
push_manifest "ghcr.io/phalcode/gamevault-backend" "unstable"
70135
;;
71136
early-access)
72-
echo "tags<<EOF" >> $GITHUB_OUTPUT
73-
echo "phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT
74-
echo "ghcr.io/phalcode/gamevault-backend:early-access" >> $GITHUB_OUTPUT
75-
echo "EOF" >> $GITHUB_OUTPUT
137+
push_manifest "phalcode/gamevault-backend" "early-access"
138+
push_manifest "ghcr.io/phalcode/gamevault-backend" "early-access"
76139
;;
77140
esac
78141
79-
- name: Build and Push
80-
uses: docker/build-push-action@v6
81-
with:
82-
platforms: linux/amd64,linux/arm64
83-
push: true
84-
tags: ${{ steps.tags.outputs.tags }}
85-
cache-from: type=gha
86-
cache-to: type=gha,mode=max
87-
88142
- name: Create Github Tag & Release
89143
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/hotfix'
90144
id: release
@@ -98,7 +152,7 @@ jobs:
98152
env:
99153
DISCORD_WEBHOOK: ${{ secrets.DISCORD_RELEASE_BOT_WEBHOOK }}
100154
with:
101-
args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v${{ steps.package-version.outputs.current-version }} has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/${{ steps.package-version.outputs.current-version }}"
155+
args: "<@&1128857090090340382> New Release: {{ EVENT_PAYLOAD.repository.full_name }} v$VERSION has been deployed. Here are the changes: https://github.com/{{ EVENT_PAYLOAD.repository.full_name }}/releases/tag/$VERSION"
102156

103157
sonarcloud:
104158
needs: test

0 commit comments

Comments
 (0)