diff --git a/.eslintignore b/.eslintignore index 0979a6c0..cb3fd15f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ **/node_modules/** +**/dist/** diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5455fc3b..94000aea 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,46 +9,47 @@ env: PROJECT_PATH: test-project jobs: -# test: -# name: Test the project -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v1 -# - uses: webbertakken/unity-activate@v1 -# - uses: webbertakken/unity-test-runner@v1.1 -# - uses: webbertakken/unity-return-license@v1 -# if: always() -# - uses: actions/upload-artifact@v1 -# with: -# name: Test results -# path: artifacts/ + # test: + # name: Test the project + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v1 + # - uses: webbertakken/unity-activate@v1 + # - uses: webbertakken/unity-test-runner@v1.1 + # - uses: webbertakken/unity-return-license@v1 + # if: always() + # - uses: actions/upload-artifact@v1 + # with: + # name: Test results + # path: artifacts/ buildForWebGL: name: Build for WebGL -# needs: [test] + # needs: [test] runs-on: ubuntu-latest steps: # webbertakken/unity-builder@v0.3-webgl - uses: actions/checkout@v1 - uses: webbertakken/unity-activate@v1 - uses: ./ + with: + projectPath: test-project - uses: webbertakken/unity-return-license@v1 if: always() - uses: actions/upload-artifact@v1 with: name: Build path: build - - buildForAndroid: - name: Build for Android -# needs: [test] - runs-on: ubuntu-latest - steps: # webbertakken/unity-builder@v0.3-android - - uses: actions/checkout@v1 - - uses: webbertakken/unity-activate@v1 - - uses: ./ - - uses: webbertakken/unity-return-license@v1 - if: always() - - uses: actions/upload-artifact@v1 - with: - name: Build - path: build +# buildForAndroid: +# name: Build for Android +# # needs: [test] +# runs-on: ubuntu-latest +# steps: # webbertakken/unity-builder@v0.3-android +# - uses: actions/checkout@v1 +# - uses: webbertakken/unity-activate@v1 +# - uses: ./ +# - uses: webbertakken/unity-return-license@v1 +# if: always() +# - uses: actions/upload-artifact@v1 +# with: +# name: Build +# path: build diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..cb3fd15f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +**/node_modules/** +**/dist/** diff --git a/dist/index.js b/dist/index.js index 2350318a..f7a2843e 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/run-unity-builder.sh b/dist/run-unity-builder.sh index d4cc9f36..deba43bf 100644 --- a/dist/run-unity-builder.sh +++ b/dist/run-unity-builder.sh @@ -1,19 +1,73 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Input variables +# PROJECT_PATH=$1 +UNITY_VERSION="2019.2.11f1" BUILD_TARGET=$2 BUILD_NAME=$3 BUILDS_PATH=$4 BUILD_METHOD=$5 -DOCKER_IMAGE_TAG=unity-builder-image +# +# Default variables +# -echo "Running docker container with specific tag" +# PROJECT_PATH = test-project +# BUILD_TARGET = +# BUILD_NAME = +# BUILDS_PATH = +# BUILD_METHOD = +# HOME = /home/runner +# GITHUB_REF = refs/pull/8/merge +# GITHUB_SHA = 0e697e1f2d80e0e8505c0e0dcff76d24bc7a4f36 +# GITHUB_REPOSITORY = webbertakken/unity-builder +# GITHUB_ACTOR = webbertakken +# GITHUB_WORKFLOW = Actions 😎 +# GITHUB_HEAD_REF = prepare-for-multi-target +# GITHUB_BASE_REF = master +# GITHUB_EVENT_NAME = pull_request +# GITHUB_WORKSPACE = /home/runner/work/unity-builder/unity-builder +# GITHUB_ACTION = self +# GITHUB_EVENT_PATH = /home/runner/work/_temp/_github_workflow/event.json +# RUNNER_OS = Linux +# RUNNER_TOOL_CACHE = /opt/hostedtoolcache +# RUNNER_TEMP = /home/runner/work/_temp +# RUNNER_WORKSPACE = /home/runner/work/unity-builder -docker build \ - --file ../Dockerfile \ - --tag DOCKER_IMAGE_TAG \ - ../ +# +# Internal variables +# + +ACTION_ROOT=$(dirname $(dirname $(readlink -fm "$0"))) +DOCKER_IMAGE_TAG=webber-unity:$UNITY_VERSION-$BUILD_TARGET + +# TODO - Remove debug statements below + +echo "Listing ACTION_ROOT" +ls $ACTION_ROOT +echo "" +echo "Listing GITHUB_WORKSPACE" +ls $GITHUB_WORKSPACE +echo "" +echo "Listing RUNNER_WORKSPACE" +ls $RUNNER_WORKSPACE +echo "" + +# +# Build image +# + +echo "Building docker images for $BUILD_TARGET" +docker build $GITHUB_WORKSPACE \ + --file $ACTION_ROOT/Dockerfile \ + --tag $DOCKER_IMAGE_TAG + +# +# Run specified container +# docker run \ --workdir /github/workspace \ @@ -23,7 +77,7 @@ docker run \ --env BUILD_NAME \ --env BUILDS_PATH \ --env BUILD_METHOD \ - --env HOME \ + --env HOME=/github/home \ --env GITHUB_REF \ --env GITHUB_SHA \ --env GITHUB_REPOSITORY \ @@ -32,7 +86,7 @@ docker run \ --env GITHUB_HEAD_REF \ --env GITHUB_BASE_REF \ --env GITHUB_EVENT_NAME \ - --env GITHUB_WORKSPACE \ + --env GITHUB_WORKSPACE=/github/workspace \ --env GITHUB_ACTION \ --env GITHUB_EVENT_PATH \ --env RUNNER_OS \ @@ -43,4 +97,4 @@ docker run \ --volume "/home/runner/work/_temp/_github_home":"/github/home" \ --volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \ --volume "${PWD}":"/github/workspace" \ - DOCKER_IMAGE_TAG + $DOCKER_IMAGE_TAG diff --git a/entrypoint.sh b/entrypoint.sh index b7aade2f..2330355a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,7 +3,9 @@ # # Set project path # + UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH +echo "Using project path \"$UNITY_PROJECT_PATH\"." # # Set the name for the build @@ -12,6 +14,7 @@ UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH if [ -z "$BUILD_NAME" ]; then BUILD_NAME="build-$(date '+%F-%H%M')" fi +echo "Using build name \"$BUILD_NAME\"." # # Set the builds target platform; @@ -28,6 +31,7 @@ fi if [ -z "$BUILD_TARGET" ]; then BUILD_TARGET=WebGL fi +echo "Using build target \"$BUILD_TARGET\"." # # Set builds path @@ -37,13 +41,9 @@ if [ -z "$BUILDS_PATH" ]; then BUILDS_PATH=build fi BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH - -# -# Set path for current build (relative and full) -# - CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_TARGET CURRENT_BUILD_FULL_PATH=$BUILDS_FULL_PATH/$BUILD_TARGET +echo "Using build path \"$CURRENT_BUILD_PATH\"." # # Set the build method, must reference one of: @@ -62,6 +62,7 @@ if [ -z "$BUILD_METHOD" ]; then # Use the script from this action which builds the scenes that are enabled in # the project. # + echo "Using built-in build method." # Create Editor directory if it does not exist mkdir -p $UNITY_PROJECT_PATH/Assets/Editor/ # Copy the build script of Unity Builder action diff --git a/package.json b/package.json index c62b6f41..4cf7db46 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "scripts": { "build": "ncc build src/index.js -o dist -m", "watch": "yarn build -w", + "start": "node dist/index.js", "lint": "prettier --check \"src/**/*.js\" && eslint src", "test": "jest --passWithNoTests" }, @@ -48,7 +49,7 @@ "git add", "jest --findRelatedTests" ], - "*.{json,sh,md,yaml,yml}": [ + "*.{json,md,yaml,yml}": [ "prettier --write", "git add" ] diff --git a/src/index.js b/src/index.js index d0f80c8d..44c15b80 100644 --- a/src/index.js +++ b/src/index.js @@ -3,44 +3,23 @@ const path = require('path'); const { exec } = require('@actions/exec'); async function action() { - // Path to the project to open with Unity - const projectPath = core.getInput('projectPath', { - required: false, - default: './', - }); + // Explicitly notify about platform support + if (process.platform !== 'linux') { + throw new Error('Currently only Linux-based platforms are supported'); + } - // Target platform for the build - const buildTarget = core.getInput('buildTarget', { - required: false, - default: 'WebGL', - }); - - // Name of the build - const buildName = core.getInput('buildName', { - required: false, - default: 'TestBuild', - }); - - // Path where build will be stored - const buildsPath = core.getInput('buildsPath', { - required: false, - default: 'build', - }); - - // Method to execute within unity. Must be static - const buildMethod = core.getInput('buildMethod', { - required: false, - default: '', - }); + // Input variables specified in workflows using "with" prop. + const projectPath = core.getInput('projectPath', { default: './' }); + const buildTarget = core.getInput('buildTarget', { default: 'WebGL' }); + const buildName = core.getInput('buildName', { default: 'TestBuild' }); + const buildsPath = core.getInput('buildsPath', { default: 'build' }); + const buildMethod = core.getInput('buildMethod', { default: '' }); // Run appropriate docker image with given args - await exec(path.join(__dirname, 'run-unity-builder.sh'), [ - projectPath, - buildTarget, - buildName, - buildsPath, - buildMethod, - ]); + const bootstrapper = path.join(__dirname, 'run-unity-builder.sh'); + await exec(`ls ${bootstrapper}`); + await exec(`chmod +x ${bootstrapper}`); + await exec(bootstrapper, [projectPath, buildTarget, buildName, buildsPath, buildMethod]); } action().catch(error => { diff --git a/src/run-unity-builder.sh b/src/run-unity-builder.sh index d4cc9f36..deba43bf 100644 --- a/src/run-unity-builder.sh +++ b/src/run-unity-builder.sh @@ -1,19 +1,73 @@ -#!/usr/bin/env sh +#!/bin/sh + +# +# Input variables +# PROJECT_PATH=$1 +UNITY_VERSION="2019.2.11f1" BUILD_TARGET=$2 BUILD_NAME=$3 BUILDS_PATH=$4 BUILD_METHOD=$5 -DOCKER_IMAGE_TAG=unity-builder-image +# +# Default variables +# -echo "Running docker container with specific tag" +# PROJECT_PATH = test-project +# BUILD_TARGET = +# BUILD_NAME = +# BUILDS_PATH = +# BUILD_METHOD = +# HOME = /home/runner +# GITHUB_REF = refs/pull/8/merge +# GITHUB_SHA = 0e697e1f2d80e0e8505c0e0dcff76d24bc7a4f36 +# GITHUB_REPOSITORY = webbertakken/unity-builder +# GITHUB_ACTOR = webbertakken +# GITHUB_WORKFLOW = Actions 😎 +# GITHUB_HEAD_REF = prepare-for-multi-target +# GITHUB_BASE_REF = master +# GITHUB_EVENT_NAME = pull_request +# GITHUB_WORKSPACE = /home/runner/work/unity-builder/unity-builder +# GITHUB_ACTION = self +# GITHUB_EVENT_PATH = /home/runner/work/_temp/_github_workflow/event.json +# RUNNER_OS = Linux +# RUNNER_TOOL_CACHE = /opt/hostedtoolcache +# RUNNER_TEMP = /home/runner/work/_temp +# RUNNER_WORKSPACE = /home/runner/work/unity-builder -docker build \ - --file ../Dockerfile \ - --tag DOCKER_IMAGE_TAG \ - ../ +# +# Internal variables +# + +ACTION_ROOT=$(dirname $(dirname $(readlink -fm "$0"))) +DOCKER_IMAGE_TAG=webber-unity:$UNITY_VERSION-$BUILD_TARGET + +# TODO - Remove debug statements below + +echo "Listing ACTION_ROOT" +ls $ACTION_ROOT +echo "" +echo "Listing GITHUB_WORKSPACE" +ls $GITHUB_WORKSPACE +echo "" +echo "Listing RUNNER_WORKSPACE" +ls $RUNNER_WORKSPACE +echo "" + +# +# Build image +# + +echo "Building docker images for $BUILD_TARGET" +docker build $GITHUB_WORKSPACE \ + --file $ACTION_ROOT/Dockerfile \ + --tag $DOCKER_IMAGE_TAG + +# +# Run specified container +# docker run \ --workdir /github/workspace \ @@ -23,7 +77,7 @@ docker run \ --env BUILD_NAME \ --env BUILDS_PATH \ --env BUILD_METHOD \ - --env HOME \ + --env HOME=/github/home \ --env GITHUB_REF \ --env GITHUB_SHA \ --env GITHUB_REPOSITORY \ @@ -32,7 +86,7 @@ docker run \ --env GITHUB_HEAD_REF \ --env GITHUB_BASE_REF \ --env GITHUB_EVENT_NAME \ - --env GITHUB_WORKSPACE \ + --env GITHUB_WORKSPACE=/github/workspace \ --env GITHUB_ACTION \ --env GITHUB_EVENT_PATH \ --env RUNNER_OS \ @@ -43,4 +97,4 @@ docker run \ --volume "/home/runner/work/_temp/_github_home":"/github/home" \ --volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \ --volume "${PWD}":"/github/workspace" \ - DOCKER_IMAGE_TAG + $DOCKER_IMAGE_TAG