From 349c738b20a8e9e6f7479a98848e215f85fadf42 Mon Sep 17 00:00:00 2001 From: Webber Takken Date: Tue, 20 Oct 2020 20:01:31 +0200 Subject: [PATCH] Special tactics (#31) * Special tactics * Create extra workflow for legacy images --- .../new-legacy-editor-image-requested.yml | 180 ++++++++++++++++++ ...ew-post-2019-2-editor-image-requested.yml} | 3 +- .github/workflows/pull-requests.yml | 1 + editor/Dockerfile | 6 +- 4 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/new-legacy-editor-image-requested.yml rename .github/workflows/{new-editor-image-requested.yml => new-post-2019-2-editor-image-requested.yml} (98%) diff --git a/.github/workflows/new-legacy-editor-image-requested.yml b/.github/workflows/new-legacy-editor-image-requested.yml new file mode 100644 index 00000000..2f75deec --- /dev/null +++ b/.github/workflows/new-legacy-editor-image-requested.yml @@ -0,0 +1,180 @@ +name: New Editor Version 🗔 + +on: + repository_dispatch: + types: [new_legacy_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: "🛠 Build unityci/editor (${{ matrix.targetPlatform }})" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + targetPlatform: + - base # Base is a special name, which indicates that no modules are installed, like with linux-mono on ubuntu + # - linux-il2cpp + - windows-mono + - mac-mono + - ios + - android + - webgl + steps: + - name: Checkout + uses: actions/checkout@v2 + ########################### + # Variables # + ########################### + - name: Show hook input + run: | + echo "Event ${{ github.event.event_type }}" + echo "jobId: ${{ github.event.client_payload.jobId }}" + 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: ${{ matrix.targetPlatform }} + ########################### + # Setup # + ########################### + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Check if image not already exists + 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 }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} ; then + echo "Image already exists. Exiting." + exit 1 + fi + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-editor-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.sha }} + restore-keys: | + ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-editor-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}- + ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-editor-${{ github.event.client_payload.editorVersion }}- + ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx-editor- + ${{ github.event.client_payload.repoVersionFull }}-${{ runner.os }}-buildx- + ########################### + # 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@v2 + id: build_editor_image + with: + context: . + file: ./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=${{ matrix.targetPlatform }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + push: true + tags: | + unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} + unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} + unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} + unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionMinor }} + unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} + unityci/editor:${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionMajor }} + ### Warning: If we once publish latest, we will have to do it forever. Lets not do that unless it's needed ### + - name: Inspect + run: | + docker buildx imagetools inspect unityci/editor:ubuntu-${{ github.event.client_payload.editorVersion }}-${{ matrix.targetPlatform }}-${{ github.event.client_payload.repoVersionFull }} + - name: Image digest + run: echo ${{ steps.build_editor_image.outputs.digest }} + - name: Update DockerHub description + uses: peter-evans/dockerhub-description@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + repository: unityci/editor + short-description: $(cat ./editor/100-characters-dockerhub-description.txt) + readme-filepath: ./editor/README.md + ########################### + # 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: ${{ matrix.targetPlatform }} + # Publication info + imageRepo: unityci + imageName: editor + friendlyTag: ${{ github.event.client_payload.repoVersionMinor }} + specificTag: ubuntu-${{ github.event.client_payload.repoVersionFull }} + digest: ${{ steps.build_editor_image.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: ${{ matrix.targetPlatform }} + # Failure info + reason: ${{ job.status }} + ########################### + # Metrics # + ########################### + - name: Disk space after + if: always() + run: df -h diff --git a/.github/workflows/new-editor-image-requested.yml b/.github/workflows/new-post-2019-2-editor-image-requested.yml similarity index 98% rename from .github/workflows/new-editor-image-requested.yml rename to .github/workflows/new-post-2019-2-editor-image-requested.yml index 42b1cf72..bd3f019a 100644 --- a/.github/workflows/new-editor-image-requested.yml +++ b/.github/workflows/new-post-2019-2-editor-image-requested.yml @@ -2,7 +2,7 @@ name: New Editor Version 🗔 on: repository_dispatch: - types: [new_editor_image_requested] + types: [new_2019_3_plus_editor_image_requested] # Further reading: # https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#repository_dispatch @@ -17,6 +17,7 @@ jobs: fail-fast: false matrix: targetPlatform: + - base # Base is a special name, which indicates that no modules are installed, like with linux-mono on ubuntu - linux-il2cpp - windows-mono - mac-mono diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index f39a59cf..3716de23 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -85,6 +85,7 @@ jobs: matrix: targetPlatform: # This list of target platforms is based on Ubuntu as a base platform + - base # Linux Build Support # - linux-mono # May not exist in newer versions / May be default for Ubuntu diff --git a/editor/Dockerfile b/editor/Dockerfile index 9c96bcbe..cfba0b76 100644 --- a/editor/Dockerfile +++ b/editor/Dockerfile @@ -14,7 +14,11 @@ RUN unity-hub install --version "$version" --changeset "$changeSet" | grep 'Erro # Install modules for that editor ARG module="non-existent-module" -RUN unity-hub install-modules --version "$version" --module "$module" --childModules | grep 'Missing module' | exit $(wc -l) +RUN if [[ "$module" == "base" ]] ; then \ + echo "running default modules for this baseOs" ; \ + else \ + unity-hub install-modules --version "$version" --module "$module" --childModules | grep 'Missing module' | exit $(wc -l) ; \ + fi ########################### # Editor #