Skip to content

Commit

Permalink
Bootstrap docker from js
Browse files Browse the repository at this point in the history
  • Loading branch information
webbertakken committed Dec 22, 2019
1 parent 0bb0dbd commit dccdec9
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 90 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/node_modules/**
**/dist/**
57 changes: 29 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
# - 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/[email protected]
# - 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/[email protected]
- 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/[email protected]
- uses: actions/checkout@v1
- uses: webbertakken/unity-activate@v1
- uses: ./
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/[email protected]
# - 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
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/node_modules/**
**/dist/**
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

74 changes: 64 additions & 10 deletions dist/run-unity-builder.sh
Original file line number Diff line number Diff line change
@@ -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
#

# 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

#
# 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 "Running docker container with specific tag"
echo "Building docker images for $BUILD_TARGET"
docker build $GITHUB_WORKSPACE \
--file $ACTION_ROOT/Dockerfile \
--tag $DOCKER_IMAGE_TAG

docker build \
--file ../Dockerfile \
--tag DOCKER_IMAGE_TAG \
../
#
# Run specified container
#

docker run \
--workdir /github/workspace \
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
11 changes: 6 additions & 5 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -28,6 +31,7 @@ fi
if [ -z "$BUILD_TARGET" ]; then
BUILD_TARGET=WebGL
fi
echo "Using build target \"$BUILD_TARGET\"."

#
# Set builds path
Expand All @@ -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:
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -48,7 +49,7 @@
"git add",
"jest --findRelatedTests"
],
"*.{json,sh,md,yaml,yml}": [
"*.{json,md,yaml,yml}": [
"prettier --write",
"git add"
]
Expand Down
49 changes: 14 additions & 35 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Loading

0 comments on commit dccdec9

Please sign in to comment.