retry_windows_editor_image_requested #936
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Retry Building Windows Editor Version 🗔 | |
on: | |
repository_dispatch: | |
types: | |
- retry_windows_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: windows-2022 | |
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: windows | |
repoVersion: ${{ github.event.client_payload.repoVersionFull }} | |
editorVersion: ${{ github.event.client_payload.editorVersion }} | |
targetPlatform: ${{ github.event.client_payload.targetPlatform }} | |
############# | |
# 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/editor -Tag windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }}) ) { | |
echo "Image already exists. Exiting." | |
exit 1 | |
} | |
####################### | |
# Free disk space # | |
####################### | |
# TODO: Determine what we can free on windows | |
############################ | |
# Pull previous images # | |
############################ | |
- name: Pull windows base image (must exist) | |
run: docker pull unityci/base:windows-${{ github.event.client_payload.repoVersionFull }} | |
- name: Pull windows hub image (must exist) | |
run: docker pull unityci/hub:windows-${{ github.event.client_payload.repoVersionFull }} | |
############################ | |
# Windows Editor image # | |
############################ | |
- name: Build and Publish Windows Editor Image | |
id: build_windows_editor_image | |
continue-on-error: true | |
run: | | |
docker build ./images/windows/editor/ ` | |
--build-arg hubImage=unityci/hub:windows-${{ github.event.client_payload.repoVersionFull }} ` | |
--build-arg baseImage=unityci/base:windows-${{ github.event.client_payload.repoVersionFull }} ` | |
--build-arg version=${{ github.event.client_payload.editorVersion }} ` | |
--build-arg changeSet=${{ github.event.client_payload.changeSet }} ` | |
--build-arg module=${{ github.event.client_payload.targetPlatform }} ` | |
--tag unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} ` | |
--tag unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} ` | |
--tag unityci/editor:windows-${{ 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 ### | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} | |
####################### | |
# Retry the above # | |
####################### | |
- name: Build and Publish Windows Editor Image (retry) | |
if: steps.build_windows_editor_image.outcome=='failure' | |
id: build_windows_editor_image_retry | |
run: | | |
docker build ./images/windows/editor/ ` | |
--build-arg hubImage=unityci/hub:windows-${{ github.event.client_payload.repoVersionFull }} ` | |
--build-arg baseImage=unityci/base:windows-${{ github.event.client_payload.repoVersionFull }} ` | |
--build-arg version=${{ github.event.client_payload.editorVersion }} ` | |
--build-arg changeSet=${{ github.event.client_payload.changeSet }} ` | |
--build-arg module=${{ github.event.client_payload.targetPlatform }} ` | |
--tag unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} ` | |
--tag unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} ` | |
--tag unityci/editor:windows-${{ 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 ### | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} | |
docker push unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} | |
########################### | |
# Inspect publication # | |
########################### | |
- name: Inspect | |
run: | | |
docker inspect unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} | |
- name: Image digest | |
id: image-digest | |
if: ${{ success() }} | |
run: | | |
$MetaData = docker inspect unityci/editor:windows-${{ github.event.client_payload.editorVersion }}-${{ github.event.client_payload.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} | |
$ImageDetails = $MetaData | ConvertFrom-Json | |
$Digest = $ImageDetails.Config.Image | |
echo "digest=$Digest" >> $Env:GITHUB_OUTPUT | |
echo "metadata=$MetaData" >> $Env: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: windows | |
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: windows-${{ github.event.client_payload.repoVersionMinor }} | |
specificTag: windows-${{ 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: windows | |
repoVersion: ${{ github.event.client_payload.repoVersionFull }} | |
editorVersion: ${{ github.event.client_payload.editorVersion }} | |
targetPlatform: ${{ github.event.client_payload.targetPlatform }} | |
# Failure info | |
reason: ${{ job.status }} - ${{ steps.image-digest.outputs.metadata }} | |
############### | |
# Metrics # | |
############### | |
- name: Disk space after | |
if: always() | |
run: get-PSDrive |