-
-
Notifications
You must be signed in to change notification settings - Fork 125
185 lines (181 loc) · 10.2 KB
/
retry-ubuntu-editor-image-requested.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: Retry Building Ubuntu Editor Version 🗔
on:
repository_dispatch:
types:
- retry_ubuntu_editor_image_requested
# Further reading:
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch
# https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#create-a-repository-dispatch-event
# https://developer.github.com/webhooks/event-payloads/#repository_dispatch
jobs:
buildImage:
name: "🛠 Retry unityci/editor (${{ github.event.client_payload.targetPlatform }})"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
#################
# Variables #
#################
- name: Show hook input
run: |
echo "Event ${{ github.event.action }}"
echo "jobId: ${{ github.event.client_payload.jobId }}"
echo "Target platform to retry: ${{ github.event.client_payload.targetPlatform }}"
echo "Unity editor version: ${{ github.event.client_payload.editorVersion }}"
echo "Unity changeset: ${{ github.event.client_payload.changeSet }}"
echo "repoVersion (full): ${{ github.event.client_payload.repoVersionFull }}"
echo "repoVersion (only minor and major): ${{ github.event.client_payload.repoVersionMinor }}"
echo "repoVersion (only major): ${{ github.event.client_payload.repoVersionMajor }}"
- name: Report new build
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: started
# Build info
imageType: editor
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
editorVersion: ${{ github.event.client_payload.editorVersion }}
targetPlatform: ${{ github.event.client_payload.targetPlatform }}
#############
# Setup #
#############
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Check if image does not already exist
run: |
# Source: https://stackoverflow.com/a/39731444/3593896
function docker_tag_exists() {
curl --silent -f -lSL https://index.docker.io/v1/repositories/$1/tags/$2 > /dev/null
}
if docker_tag_exists unityci/editor ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} ; then
echo "Image already exists. Exiting."
exit 1
fi
#######################
# Free disk space #
#######################
- name: Free disk space
run: .github/workflows/scripts/free_disk_space.sh
############################
# Pull previous images #
############################
- name: Pull base image (must exist)
run: docker pull unityci/base:${{ github.event.client_payload.repoVersionFull }}
- name: Pull hub image (must exist)
run: docker pull unityci/hub:${{ github.event.client_payload.repoVersionFull }}
####################
# Editor image #
####################
- name: Build and publish
uses: docker/build-push-action@v5
id: build_ubuntu_editor_image
continue-on-error: true
with:
file: ./images/ubuntu/editor/Dockerfile
build-args: |
hubImage=unityci/hub:${{ github.event.client_payload.repoVersionFull }}
baseImage=unityci/base:${{ github.event.client_payload.repoVersionFull }}
version=${{ github.event.client_payload.editorVersion }}
changeSet=${{ github.event.client_payload.changeSet }}
module=${{ github.event.client_payload.targetPlatform }}
cache-from: type=local,src=/tmp/.buildx-cache
push: true
tags: |
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }}
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }}
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}
### Warning: If we once publish latest, we will have to do it forever. Lets not do that unless it's needed ###
### Another warning: order is important: We go from specific to unspecific with the exception of the most specific tag which is used to check if the image is already there ###
#######################
# Retry the above #
#######################
- name: Build and publish (retry)
uses: docker/build-push-action@v5
if: steps.build_ubuntu_editor_image.outcome=='failure'
id: build_ubuntu_editor_image_retry
with:
file: ./images/ubuntu/editor/Dockerfile
build-args: |
hubImage=unityci/hub:${{ github.event.client_payload.repoVersionFull }}
baseImage=unityci/base:${{ github.event.client_payload.repoVersionFull }}
version=${{ github.event.client_payload.editorVersion }}
changeSet=${{ github.event.client_payload.changeSet }}
module=${{ github.event.client_payload.targetPlatform }}
cache-from: type=local,src=/tmp/.buildx-cache
push: true
tags: |
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }}
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }}
unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }}
unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}
### Warning: If we once publish latest, we will have to do it forever. Lets not do that unless it's needed ###
### Another warning: order is important: We go from specific to unspecific with the exception of the most specific tag which is used to check if the image is already there ###
###########################
# Inspect publication #
###########################
- name: Inspect
run: |
docker buildx imagetools inspect unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}
- name: Image digest
id: image-digest
run: |
[ '${{ steps.build_ubuntu_editor_image.outcome }}' = 'success' ] && echo "digest=${{ steps.build_ubuntu_editor_image.outputs.digest }}" >> $GITHUB_OUTPUT || :
[ '${{ steps.build_ubuntu_editor_image_retry.outcome }}' = 'success' ] && echo "digest=${{ steps.build_ubuntu_editor_image_retry.outputs.digest }}" >> $GITHUB_OUTPUT || :
#################
# reporting #
#################
- name: Report publication
if: ${{ success() }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: published
# Build info
imageType: editor
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
editorVersion: ${{ github.event.client_payload.editorVersion }}
targetPlatform: ${{ github.event.client_payload.targetPlatform }}
# Publication info
imageRepo: unityci
imageName: editor
friendlyTag: ${{ github.event.client_payload.repoVersionMinor }}
specificTag: ubuntu-${{ github.event.client_payload.repoVersionFull }}
digest: ${{ steps.image-digest.outputs.digest }}
- name: Report failure
if: ${{ failure() || cancelled() }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ github.event.client_payload.jobId }}
status: failed
# Build info
imageType: editor
baseOs: ubuntu
repoVersion: ${{ github.event.client_payload.repoVersionFull }}
editorVersion: ${{ github.event.client_payload.editorVersion }}
targetPlatform: ${{ github.event.client_payload.targetPlatform }}
# Failure info
reason: ${{ job.status }} - ${{ steps.build_ubuntu_editor_image.outputs.metadata }}
###############
# Metrics #
###############
- name: Disk space after
if: always()
run: df -h