Bootstrap docker from js

This commit is contained in:
Webber 2019-12-17 22:48:54 +01:00 committed by Webber Takken
parent 0bb0dbd7be
commit dccdec9d3b
9 changed files with 183 additions and 90 deletions

View File

@ -1 +1,2 @@
**/node_modules/** **/node_modules/**
**/dist/**

View File

@ -31,24 +31,25 @@ jobs:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: webbertakken/unity-activate@v1 - uses: webbertakken/unity-activate@v1
- uses: ./ - uses: ./
with:
projectPath: test-project
- uses: webbertakken/unity-return-license@v1 - uses: webbertakken/unity-return-license@v1
if: always() if: always()
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: Build name: Build
path: build path: build
# buildForAndroid:
buildForAndroid: # name: Build for Android
name: Build for Android # # needs: [test]
# needs: [test] # runs-on: ubuntu-latest
runs-on: ubuntu-latest # steps: # webbertakken/unity-builder@v0.3-android
steps: # webbertakken/unity-builder@v0.3-android # - uses: actions/checkout@v1
- uses: actions/checkout@v1 # - uses: webbertakken/unity-activate@v1
- uses: webbertakken/unity-activate@v1 # - uses: ./
- uses: ./ # - uses: webbertakken/unity-return-license@v1
- uses: webbertakken/unity-return-license@v1 # if: always()
if: always() # - uses: actions/upload-artifact@v1
- uses: actions/upload-artifact@v1 # with:
with: # name: Build
name: Build # path: build
path: build

2
.prettierignore Normal file
View File

@ -0,0 +1,2 @@
**/node_modules/**
**/dist/**

BIN
dist/index.js vendored

Binary file not shown.

View File

@ -1,19 +1,73 @@
#!/usr/bin/env sh #!/bin/sh
#
# Input variables
#
PROJECT_PATH=$1 PROJECT_PATH=$1
UNITY_VERSION="2019.2.11f1"
BUILD_TARGET=$2 BUILD_TARGET=$2
BUILD_NAME=$3 BUILD_NAME=$3
BUILDS_PATH=$4 BUILDS_PATH=$4
BUILD_METHOD=$5 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 \ # Internal variables
--tag DOCKER_IMAGE_TAG \ #
../
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 \ docker run \
--workdir /github/workspace \ --workdir /github/workspace \
@ -23,7 +77,7 @@ docker run \
--env BUILD_NAME \ --env BUILD_NAME \
--env BUILDS_PATH \ --env BUILDS_PATH \
--env BUILD_METHOD \ --env BUILD_METHOD \
--env HOME \ --env HOME=/github/home \
--env GITHUB_REF \ --env GITHUB_REF \
--env GITHUB_SHA \ --env GITHUB_SHA \
--env GITHUB_REPOSITORY \ --env GITHUB_REPOSITORY \
@ -32,7 +86,7 @@ docker run \
--env GITHUB_HEAD_REF \ --env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \ --env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \ --env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE \ --env GITHUB_WORKSPACE=/github/workspace \
--env GITHUB_ACTION \ --env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \ --env GITHUB_EVENT_PATH \
--env RUNNER_OS \ --env RUNNER_OS \
@ -43,4 +97,4 @@ docker run \
--volume "/home/runner/work/_temp/_github_home":"/github/home" \ --volume "/home/runner/work/_temp/_github_home":"/github/home" \
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \ --volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
--volume "${PWD}":"/github/workspace" \ --volume "${PWD}":"/github/workspace" \
DOCKER_IMAGE_TAG $DOCKER_IMAGE_TAG

View File

@ -3,7 +3,9 @@
# #
# Set project path # Set project path
# #
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
echo "Using project path \"$UNITY_PROJECT_PATH\"."
# #
# Set the name for the build # Set the name for the build
@ -12,6 +14,7 @@ UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
if [ -z "$BUILD_NAME" ]; then if [ -z "$BUILD_NAME" ]; then
BUILD_NAME="build-$(date '+%F-%H%M')" BUILD_NAME="build-$(date '+%F-%H%M')"
fi fi
echo "Using build name \"$BUILD_NAME\"."
# #
# Set the builds target platform; # Set the builds target platform;
@ -28,6 +31,7 @@ fi
if [ -z "$BUILD_TARGET" ]; then if [ -z "$BUILD_TARGET" ]; then
BUILD_TARGET=WebGL BUILD_TARGET=WebGL
fi fi
echo "Using build target \"$BUILD_TARGET\"."
# #
# Set builds path # Set builds path
@ -37,13 +41,9 @@ if [ -z "$BUILDS_PATH" ]; then
BUILDS_PATH=build BUILDS_PATH=build
fi fi
BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH
#
# Set path for current build (relative and full)
#
CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_TARGET CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_TARGET
CURRENT_BUILD_FULL_PATH=$BUILDS_FULL_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: # 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 # Use the script from this action which builds the scenes that are enabled in
# the project. # the project.
# #
echo "Using built-in build method."
# Create Editor directory if it does not exist # Create Editor directory if it does not exist
mkdir -p $UNITY_PROJECT_PATH/Assets/Editor/ mkdir -p $UNITY_PROJECT_PATH/Assets/Editor/
# Copy the build script of Unity Builder action # Copy the build script of Unity Builder action

View File

@ -9,6 +9,7 @@
"scripts": { "scripts": {
"build": "ncc build src/index.js -o dist -m", "build": "ncc build src/index.js -o dist -m",
"watch": "yarn build -w", "watch": "yarn build -w",
"start": "node dist/index.js",
"lint": "prettier --check \"src/**/*.js\" && eslint src", "lint": "prettier --check \"src/**/*.js\" && eslint src",
"test": "jest --passWithNoTests" "test": "jest --passWithNoTests"
}, },
@ -48,7 +49,7 @@
"git add", "git add",
"jest --findRelatedTests" "jest --findRelatedTests"
], ],
"*.{json,sh,md,yaml,yml}": [ "*.{json,md,yaml,yml}": [
"prettier --write", "prettier --write",
"git add" "git add"
] ]

View File

@ -3,44 +3,23 @@ const path = require('path');
const { exec } = require('@actions/exec'); const { exec } = require('@actions/exec');
async function action() { async function action() {
// Path to the project to open with Unity // Explicitly notify about platform support
const projectPath = core.getInput('projectPath', { if (process.platform !== 'linux') {
required: false, throw new Error('Currently only Linux-based platforms are supported');
default: './', }
});
// Target platform for the build // Input variables specified in workflows using "with" prop.
const buildTarget = core.getInput('buildTarget', { const projectPath = core.getInput('projectPath', { default: './' });
required: false, const buildTarget = core.getInput('buildTarget', { default: 'WebGL' });
default: 'WebGL', const buildName = core.getInput('buildName', { default: 'TestBuild' });
}); const buildsPath = core.getInput('buildsPath', { default: 'build' });
const buildMethod = core.getInput('buildMethod', { default: '' });
// 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: '',
});
// Run appropriate docker image with given args // Run appropriate docker image with given args
await exec(path.join(__dirname, 'run-unity-builder.sh'), [ const bootstrapper = path.join(__dirname, 'run-unity-builder.sh');
projectPath, await exec(`ls ${bootstrapper}`);
buildTarget, await exec(`chmod +x ${bootstrapper}`);
buildName, await exec(bootstrapper, [projectPath, buildTarget, buildName, buildsPath, buildMethod]);
buildsPath,
buildMethod,
]);
} }
action().catch(error => { action().catch(error => {

View File

@ -1,19 +1,73 @@
#!/usr/bin/env sh #!/bin/sh
#
# Input variables
#
PROJECT_PATH=$1 PROJECT_PATH=$1
UNITY_VERSION="2019.2.11f1"
BUILD_TARGET=$2 BUILD_TARGET=$2
BUILD_NAME=$3 BUILD_NAME=$3
BUILDS_PATH=$4 BUILDS_PATH=$4
BUILD_METHOD=$5 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 \ # Internal variables
--tag DOCKER_IMAGE_TAG \ #
../
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 \ docker run \
--workdir /github/workspace \ --workdir /github/workspace \
@ -23,7 +77,7 @@ docker run \
--env BUILD_NAME \ --env BUILD_NAME \
--env BUILDS_PATH \ --env BUILDS_PATH \
--env BUILD_METHOD \ --env BUILD_METHOD \
--env HOME \ --env HOME=/github/home \
--env GITHUB_REF \ --env GITHUB_REF \
--env GITHUB_SHA \ --env GITHUB_SHA \
--env GITHUB_REPOSITORY \ --env GITHUB_REPOSITORY \
@ -32,7 +86,7 @@ docker run \
--env GITHUB_HEAD_REF \ --env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \ --env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \ --env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE \ --env GITHUB_WORKSPACE=/github/workspace \
--env GITHUB_ACTION \ --env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \ --env GITHUB_EVENT_PATH \
--env RUNNER_OS \ --env RUNNER_OS \
@ -43,4 +97,4 @@ docker run \
--volume "/home/runner/work/_temp/_github_home":"/github/home" \ --volume "/home/runner/work/_temp/_github_home":"/github/home" \
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \ --volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
--volume "${PWD}":"/github/workspace" \ --volume "${PWD}":"/github/workspace" \
DOCKER_IMAGE_TAG $DOCKER_IMAGE_TAG