-
-
Notifications
You must be signed in to change notification settings - Fork 125
184 lines (164 loc) · 7.22 KB
/
new-windows-hub-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
name: New Windows Hub Version ⚙
on:
repository_dispatch:
types:
- new_hub_images_requested
- new_windows_hub_image_requested
workflow_dispatch:
inputs:
jobId:
description: "Job ID"
required: true
default: "dryRun"
repoVersionFull:
description: "All digits of the latest tag of this repository, e.g. `1.23.45`"
required: true
repoVersionMinor:
description: "Minor digit of that tag, e.g. `23`"
required: true
repoVersionMajor:
description: "Major digit of that tag, e.g. `1`"
required: true
# 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:
build:
name: "🛠 Build unityci/hub"
runs-on: windows-2022
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout latest release tag
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $LATEST_TAG
shell: bash
#################
# Variables #
#################
- name: Setup Build Parameters
id: buildParameters
run: |
if ("${{ github.event.inputs.jobId }}")
{
# Workflow Dispatch
echo "jobId={{ github.event.inputs.jobId }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionFull={{ github.event.inputs.repoVersionFull }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionMinor={{ github.event.inputs.repoVersionMinor }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionMajor={{ github.event.inputs.repoVersionMajor }}" >> $Env:GITHUB_OUTPUT
} else
{
# Repo Dispatch
echo "jobId=${{ github.event.client_payload.jobId }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionFull=${{ github.event.client_payload.repoVersionFull }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionMinor=${{ github.event.client_payload.repoVersionMinor }}" >> $Env:GITHUB_OUTPUT
echo "repoVersionMajor=${{ github.event.client_payload.repoVersionMajor }}" >> $Env:GITHUB_OUTPUT
}
- name: Show hook input
run: |
echo "Event ${{ github.event.action }}"
echo "jobId: ${{ steps.buildParameters.outputs.jobId }}"
echo "repoVersion (full): ${{ steps.buildParameters.outputs.repoVersionFull }}"
echo "repoVersion (only minor and major): ${{ steps.buildParameters.outputs.repoVersionMinor }}"
echo "repoVersion (only major): ${{ steps.buildParameters.outputs.repoVersionMajor }}"
- name: Report new build
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ steps.buildParameters.outputs.jobId }}
status: started
# Build info
imageType: hub
baseOs: windows
repoVersion: ${{ steps.buildParameters.outputs.repoVersionFull }}
#############
# Setup #
#############
- name: Login to DockerHub
env:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
run: docker login --username $Env:username --password $Env:password
- name: Check if image does not already exist
run: |
# Source: https://gist.github.com/webbertakken/1789a4683a99e2a62b975ff436a85382
function Docker-Tag-Exists {
[CmdletBinding()]
param([string] $Repository, [string] $Tag)
Try {
Invoke-RestMethod "https://index.docker.io/v1/repositories/$Repository/tags/$Tag"
} Catch {} # Assume image does not exist on erroneous response
return $?
}
if (Docker-Tag-Exists -Repository "unityci/hub" -Tag "windows-${{ steps.buildParameters.outputs.repoVersionFull }}") {
echo "Image already exists. Exiting."
exit 1
}
# TODO: Cache layers, currently not supported on windows
############################
# Pull previous images #
############################
- name: Pull base image (must exist)
run: docker pull unityci/base:windows-${{ steps.buildParameters.outputs.repoVersionFull }}
#################
# Hub image #
#################
- name: Build and Publish Windows Hub Image
id: build_windows_hub_image
run: |
docker build ./images/windows/hub/ `
--tag unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionFull }} `
--tag unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionMinor }} `
--tag unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionMajor }} `
--tag unityci/hub:windows-latest
docker push unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionFull }}
docker push unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionMinor }}
docker push unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionMajor }}
docker push unityci/hub:windows-latest
$MetaData = docker inspect unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionFull }}
$ImageDetails = $MetaData | ConvertFrom-Json
$Digest = $ImageDetails.Config.Image
echo "digest=$Digest" >> $Env:GITHUB_OUTPUT
echo "metadata=$MetaData" >> $Env:GITHUB_OUTPUT
- name: Inspect
run: |
docker inspect unityci/hub:windows-${{ steps.buildParameters.outputs.repoVersionFull }}
- name: Image digest
run: echo ${{ steps.build_windows_hub_image.outputs.digest }}
#################
# reporting #
#################
- name: Report publication
if: ${{ success() }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ steps.buildParameters.outputs.jobId }}
status: published
# Build info
imageType: hub
baseOs: windows
repoVersion: ${{ steps.buildParameters.outputs.repoVersionFull }}
# Publication info
imageRepo: unityci
imageName: hub
friendlyTag: windows-${{ steps.buildParameters.outputs.repoVersionMinor }}
specificTag: windows-${{ steps.buildParameters.outputs.repoVersionFull }}
digest: ${{ steps.build_windows_hub_image.outputs.digest }}
- name: Report failure
if: ${{ failure() || cancelled() }}
uses: ./.github/workflows/actions/report-to-backend
with:
token: ${{ secrets.VERSIONING_TOKEN }}
jobId: ${{ steps.buildParameters.outputs.jobId }}
status: failed
# Build info
imageType: hub
baseOs: windows
repoVersion: ${{ steps.buildParameters.outputs.repoVersionFull }}
# Failure info
reason: ${{ job.status }} - ${{ steps.build_windows_hub_image.outputs.metadata }}