commit 572fe09ebf310fa4021f5e970ce1601a1102786e Author: Scion Date: Sun Mar 12 17:11:02 2023 -0700 Initial Commit. diff --git a/unity-command/Dockerfile b/unity-command/Dockerfile new file mode 100644 index 0000000..d9de6d6 --- /dev/null +++ b/unity-command/Dockerfile @@ -0,0 +1,17 @@ +#Arg is replaced with the desired Unity container. +ARG IMAGE=debian:stable-slim +FROM ${IMAGE} + +RUN useradd -ms /bin/bash unity -u 1000 + +COPY entrypoint.sh / +RUN chmod +x /entrypoint.sh + +COPY install-dotnet.sh / +RUN bash /install-dotnet.sh + +COPY UnityBuilder /usr/local/bin/ +RUN chmod +x /usr/local/bin/UnityBuilder + +ENTRYPOINT ["/entrypoint.sh"] +USER unity \ No newline at end of file diff --git a/unity-command/UnityBuilder b/unity-command/UnityBuilder new file mode 100644 index 0000000..a3771a3 Binary files /dev/null and b/unity-command/UnityBuilder differ diff --git a/unity-command/action.yaml b/unity-command/action.yaml new file mode 100644 index 0000000..f7624f6 --- /dev/null +++ b/unity-command/action.yaml @@ -0,0 +1,52 @@ +name: unity-command +description: "Run a Unity command using a specified version of Unity." +inputs: + platform: + description: "Unity Platform. Options: windows, windows32bit, mac, linux, android" + required: true + version: + description: "Unity Version." + required: true + imageTag: + description: "Tag to use for the temporary version of Unity. Must refer to an existing public Docker image. Must be the same is in the Dockerfile of the called action." + required: true + default: unityci/base:latest + serial: + description: "Unity license serial number. Or 'public' for a public license." + required: true + default: public + email: + description: "Unity email." + required: true + password: + description: "Unity password." + required: true + command: + description: "Unity command to run." + required: false +runs: + using: "composite" + steps: + - name: "Get Unity container name." + id: getContainer + uses: act/unity/unity-get-container@master + with: + version: ${{ inputs.version }} + platform: ${{ inputs.platform }} + - name: "Pull Unity container." + run: | + CONTAINER=${{ steps.getContainer.outputs.container }} + + docker build -t ${{ inputs.imageTag }} --build-arg IMAGE=$CONTAINER ${{ github.action_path }} + shell: bash + - name: "Run Unity command." + uses: act/unity/unity@master + with: + serial: ${{ inputs.serial }} + email: ${{ inputs.email }} + password: ${{ inputs.password }} + command: ${{ inputs.command }} + - name: "Remove temporary image." + run: | + docker image rm ${{ inputs.imageTag }} + shell: bash diff --git a/unity-command/entrypoint.sh b/unity-command/entrypoint.sh new file mode 100644 index 0000000..92e9602 --- /dev/null +++ b/unity-command/entrypoint.sh @@ -0,0 +1,34 @@ +#!/bin/bash +SERIAL=$1; EMAIL=$2; PASSWORD=$3; COMMAND=$4 +DEFAULT_ARGS="-quit -logFile -" + +rm -rf $HOME/.config/unity3d +rm -rf /home/unity/.config/unity3d + +#Add ssh key information for resolving packages. +if [[ -n "$SSH_PUBLIC_KEY" && -n "$SSH_PRIVATE_KEY" ]]; then + echo "ADDING SSH KEYS!" + SSH_DIR="/home/$(whoami)/.ssh" + mkdir -p $SSH_DIR + + echo "$SSH_PUBLIC_KEY" > $SSH_DIR/id_rsa.pub + echo "$SSH_PRIVATE_KEY" > $SSH_DIR/id_rsa +cat << EOF > $SSH_DIR/config +Host * + StrictHostKeyChecking no +EOF + + chmod 600 $SSH_DIR/id_rsa + chmod 644 $SSH_DIR/id_rsa.pub + cat $SSH_DIR/config +fi + +#Activate Unity +if [[ "$SERIAL" == "public" ]]; then + unity-editor $DEFAULT_ARGS -serial $SERIAL -username $EMAIL -password $PASSWORD +else + UnityBuilder -i unity-editor -u $EMAIL -p $PASSWORD +fi + +#Run the command. +unity-editor $DEFAULT_ARGS $COMMAND \ No newline at end of file diff --git a/unity-command/install-dotnet.sh b/unity-command/install-dotnet.sh new file mode 100644 index 0000000..40946c7 --- /dev/null +++ b/unity-command/install-dotnet.sh @@ -0,0 +1,10 @@ +#!/bin/bash +wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +dpkg -i packages-microsoft-prod.deb +rm packages-microsoft-prod.deb + +apt update +apt install -y dotnet-sdk-6.0 + +#For UnityBuilder +apt install -y chromium-browser \ No newline at end of file diff --git a/unity-get-buildtarget/action.yaml b/unity-get-buildtarget/action.yaml new file mode 100644 index 0000000..3c761be --- /dev/null +++ b/unity-get-buildtarget/action.yaml @@ -0,0 +1,34 @@ +name: unity-get-buildtarget +description: "Get the correct Unity build target from a provided platform." +inputs: + platform: + description: "Unity Platform. Options: windows, windows32bit, mac, linux, android" + required: true +outputs: + buildTarget: + description: "Unity Build Target." + value: ${{ steps.getTarget.outputs.buildTarget }} +runs: + using: "composite" + steps: + - name: "Get Unity Build Target." + id: getTarget + run: | + #Choose the correct buildTarget: https://docs.unity3d.com/Manual/EditorCommandLineArguments.html + UNITY_PLATFORM=${{ inputs.platform }} + UNITY_TARGET=$UNITY_PLATFORM + + if [[ $UNITY_PLATFORM == "windows" ]]; then + UNITY_TARGET=Win64 + elif [[ $UNITY_PLATFORM == "windows32bit" ]]; then + UNITY_TARGET=Win + elif [[ $UNITY_PLATFORM == "mac" ]]; then + UNITY_TARGET=OSXUniversal + elif [[ $UNITY_PLATFORM == "linux" ]]; then + UNITY_TARGET=Linux64 + elif [[ $UNITY_PLATFORM == "android" ]]; then + UNITY_TARGET=Android + fi + + echo "::set-output name=buildTarget::$UNITY_TARGET" + shell: bash \ No newline at end of file diff --git a/unity-get-container/action.yaml b/unity-get-container/action.yaml new file mode 100644 index 0000000..1a400f6 --- /dev/null +++ b/unity-get-container/action.yaml @@ -0,0 +1,38 @@ +name: unity-get-container +description: "Get the correct Unity docker container from a provided platform." +inputs: + version: + description: "Unity Version." + required: true + platform: + description: "Unity Platform. Options: windows, windows32bit, mac, linux, android" + required: true +outputs: + container: + description: "Unity Docker Container" + value: ${{ steps.getContainer.outputs.container }} +runs: + using: "composite" + steps: + - name: "Get Unity Docker Container." + id: getContainer + run: | + #Choose the appropriate container from: https://hub.docker.com/r/unityci/editor + UNITY_VERSION=${{ inputs.version }} + UNITY_PLATFORM=${{ inputs.platform }} + + if [[ $UNITY_PLATFORM == "windows" || $UNITY_PLATFORM == "windows32bit" ]]; then + UNITY_PLATFORM=windows-mono-1.0.1 + elif [[ $UNITY_PLATFORM == "mac" ]]; then + UNITY_PLATFORM=mac-mono-1.0.1 + elif [[ $UNITY_PLATFORM == "linux" ]]; then + UNITY_PLATFORM=base-1.0.1 + UNITY_VERSION=ubuntu-$UNITY_VERSION + elif [[ $UNITY_PLATFORM == "android" ]]; then + UNITY_PLATFORM=$UNITY_PLATFORM-1.0.1 + fi + + CONTAINER=unityci/editor:$UNITY_VERSION-$UNITY_PLATFORM + + echo "::set-output name=container::$CONTAINER" + shell: bash \ No newline at end of file diff --git a/unity-get-version/action.yaml b/unity-get-version/action.yaml new file mode 100644 index 0000000..a719c86 --- /dev/null +++ b/unity-get-version/action.yaml @@ -0,0 +1,26 @@ +name: unity-get-version +description: "Get the correct Unity version from a provided project." +inputs: + projectPath: + description: "Path to the Unity project." + required: true + default: "." +outputs: + projectVersion: + description: "Unity project version." + value: ${{ steps.getVersion.outputs.projectVersion }} +runs: + using: "composite" + steps: + - name: "Get Unity project version." + id: getVersion + run: | + VERSION_KEY="m_EditorVersion" + VERSION_FILE="ProjectSettings/ProjectVersion.txt" + VERSION_FILE_PATH="${{ inputs.projectPath }}/$VERSION_FILE" + + VERSION=$(grep -w $VERSION_KEY $VERSION_FILE_PATH | cut -d ':' -f2 | xargs) + + echo "::set-output name=projectVersion::$VERSION" + shell: bash + \ No newline at end of file diff --git a/unity-project/action.yaml b/unity-project/action.yaml new file mode 100644 index 0000000..b6a0edd --- /dev/null +++ b/unity-project/action.yaml @@ -0,0 +1,44 @@ +name: unity-project +description: "Run a Unity command using a project's version and a build target." +inputs: + projectPath: + description: "Path to the Unity project." + required: true + default: "." + platform: + description: "Unity Platform. Options: windows, windows32bit, mac, linux, android" + required: true + serial: + description: "Unity license serial number." + required: true + email: + description: "Unity email." + required: true + password: + description: "Unity password." + required: true + command: + description: "Unity command to run." + required: false +runs: + using: "composite" + steps: + - name: "Get Unity Version." + id: getVersion + uses: act/unity/unity-get-version@master + with: + projectPath: ${{ inputs.projectPath }} + - name: "Get Unity buildTarget." + id: getTarget + uses: act/unity/unity-get-buildtarget@master + with: + platform: ${{ inputs.platform }} + - name: "Run Unity command." + uses: act/unity/unity-command@master + with: + platform: ${{ inputs.platform }} + version: ${{ steps.getVersion.outputs.projectVersion }} + serial: ${{ inputs.serial }} + email: ${{ inputs.email }} + password: ${{ inputs.password }} + command: -projectPath ${{ inputs.projectPath }} -buildTarget ${{ steps.getTarget.outputs.buildTarget }} ${{ inputs.command }} diff --git a/unity/action.yaml b/unity/action.yaml new file mode 100644 index 0000000..e6d2ded --- /dev/null +++ b/unity/action.yaml @@ -0,0 +1,24 @@ +name: unity +description: "Register Unity with the provided license and run a Unity command." +inputs: + serial: + description: "Unity license serial number." + required: true + email: + description: "Unity email." + required: true + password: + description: "Unity password." + required: true + command: + description: "Unity command to run." + required: false +runs: + using: docker + #This is a base "mock" image which is replaced by the correct image in the "unity-command" action at runtime. + image: docker://unityci/base:latest + args: + - ${{ inputs.serial }} + - ${{ inputs.email }} + - ${{ inputs.password }} + - ${{ inputs.command }}