Skip to content

Commit

Permalink
feat: Add support for macos game-ci#211
Browse files Browse the repository at this point in the history
  • Loading branch information
Kariaro committed Dec 29, 2022
1 parent d982116 commit 9997a79
Show file tree
Hide file tree
Showing 35 changed files with 152,040 additions and 10,016 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ jobs:
# - run: yarn build --quiet && git diff --quiet action || { echo "ERROR - index.js is different from repository version. Forgot to run `yarn build`?" ; exit 62; }

testAllModesLikeInTheReadme:
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
runs-on: ubuntu-latest
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }} on system ${{ matrix.system }}
runs-on: ${{ matrix.system }}
strategy:
fail-fast: false
matrix:
Expand All @@ -36,6 +36,9 @@ jobs:
testMode:
- playmode
- editmode
system:
- ubuntu-latest
- macos-latest
steps:
###########################
# Checkout #
Expand Down Expand Up @@ -64,7 +67,7 @@ jobs:
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
- uses: actions/upload-artifact@v3
with:
name: Test results for ${{ matrix.testMode }}
name: Test results for ${{ matrix.testMode }} on ${{ matrix.system }}
path: ${{ steps.tests.outputs.artifactsPath }}
retention-days: 14

Expand Down
160,101 changes: 150,263 additions & 9,838 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1,276 changes: 1,135 additions & 141 deletions dist/licenses.txt

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions dist/platforms/mac/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash
set -x
#
# Create directory for license activation
#

sudo mkdir /Library/Application\ Support/Unity
sudo chmod -R 777 /Library/Application\ Support/Unity

ACTIVATE_LICENSE_PATH="$GITHUB_WORKSPACE/_activate-license"
mkdir -p "$ACTIVATE_LICENSE_PATH"

#
# Run steps
#

source "$ACTION_FOLDER/platforms/mac/steps/activate.sh"
source "$ACTION_FOLDER/platforms/mac/steps/set_gitcredential.sh"
source "$ACTION_FOLDER/platforms/mac/steps/run_tests.sh"
source "$ACTION_FOLDER/platforms/mac/steps/return_license.sh"

#
# Remove license activation directory
#

sudo rm -r /Library/Application\ Support/Unity
rm -r "$ACTIVATE_LICENSE_PATH"

#
# Instructions for debugging
#

if [[ $TEST_RUNNER_EXIT_CODE -gt 0 ]]; then
echo ""
echo "###########################"
echo "# Failure #"
echo "###########################"
echo ""
echo "Please note that the exit code is not very descriptive."
echo "Most likely it will not help you solve the issue."
echo ""
echo "To find the reason for failure: please search for errors in the log above."
echo ""
fi;

#
# Exit with code from the build step.
#

if [[ $USE_EXIT_CODE == true || $TEST_RUNNER_EXIT_CODE -ne 2 ]]; then
exit $TEST_RUNNER_EXIT_CODE
fi;
110 changes: 110 additions & 0 deletions dist/platforms/mac/steps/activate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env bash

# Run in ACTIVATE_LICENSE_PATH directory
echo "Changing to \"$ACTIVATE_LICENSE_PATH\" directory."
pushd "$ACTIVATE_LICENSE_PATH"

if [[ -n "$UNITY_LICENSE" ]] || [[ -n "$UNITY_LICENSE_FILE" ]]; then
#
# PERSONAL LICENSE MODE
#
# This will activate Unity, using a license file
#
# Note that this is the ONLY WAY for PERSONAL LICENSES in 2020.
# * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478
#
# The license file can be acquired using `game-ci/request-manual-activation-file` action.
echo "Requesting activation (personal license)"

# Set the license file path
FILE_PATH=UnityLicenseFile.ulf

if [[ -n "$UNITY_LICENSE" ]]; then
# Copy license file from Github variables
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
elif [[ -n "$UNITY_LICENSE_FILE" ]]; then
# Copy license file from file system
cat "$UNITY_LICENSE_FILE" | tr -d '\r' > $FILE_PATH
fi

# Activate license
ACTIVATION_OUTPUT=$(/Applications/Unity/Hub/Editor/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity \
-batchmode \
-nographics \
-logFile \
-quit \
-manualLicenseFile $FILE_PATH)

# Store the exit code from the verify command
UNITY_EXIT_CODE=$?

# The exit code for personal activation is always 1;
# Determine whether activation was successful.
#
# Successful output should include the following:
#
# "LICENSE SYSTEM [2020120 18:51:20] Next license update check is after 2019-11-25T18:23:38"
#
ACTIVATION_SUCCESSFUL=$(echo $ACTIVATION_OUTPUT | grep 'Next license update check is after' | wc -l)

# Set exit code to 0 if activation was successful
if [[ $ACTIVATION_SUCCESSFUL -eq 1 ]]; then
UNITY_EXIT_CODE=0
fi;

# Remove license file
# rm -f $FILE_PATH

elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
#
# PROFESSIONAL (SERIAL) LICENSE MODE
#
# This will activate unity, using the activating process.
#
# Note: This is the preferred way for PROFESSIONAL LICENSES.
#
echo "Requesting activation (professional license)"

# Activate license
/Applications/Unity/Hub/Editor/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity \
-batchmode \
-nographics \
-logFile \
-quit \
-serial "$UNITY_SERIAL" \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD"

# Store the exit code from the verify command
UNITY_EXIT_CODE=$?
else
#
# NO LICENSE ACTIVATION STRATEGY MATCHED
#
# This will exit since no activation strategies could be matched.
#
echo "License activation strategy could not be determined."
echo ""
echo "Visit https://game.ci/docs/github/getting-started for more"
echo "details on how to set up one of the possible activation strategies."

# Immediately exit as no UNITY_EXIT_CODE can be derived.
exit 1;

fi

#
# Display information about the result
#
if [ $UNITY_EXIT_CODE -eq 0 ]; then
# Activation was a success
echo "Activation complete."
else
# Activation failed so exit with the code from the license verification step
echo "Unclassified error occured while trying to activate license."
echo "Exit code was: $UNITY_EXIT_CODE"
exit $UNITY_EXIT_CODE
fi

# Return to previous working directory
popd
18 changes: 18 additions & 0 deletions dist/platforms/mac/steps/return_license.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

# Run in ACTIVATE_LICENSE_PATH directory
echo "Changing to \"$ACTIVATE_LICENSE_PATH\" directory."
pushd "$ACTIVATE_LICENSE_PATH"

/Applications/Unity/Hub/Editor/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity \
-logFile - \
-batchmode \
-nographics \
-quit \
-username "$UNITY_EMAIL" \
-password "$UNITY_PASSWORD" \
-returnlicense \
-projectPath "$ACTIVATE_LICENSE_PATH"

# Return to previous working directory
popd
142 changes: 142 additions & 0 deletions dist/platforms/mac/steps/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#!/usr/bin/env bash

#
# Fix for kqueue error
#

export EVENT_NOKQUEUE=1

#
# Set and display project path
#

UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH"
echo "Using project path \"$UNITY_PROJECT_PATH\"."

#
# Set and display the artifacts path
#

echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results."
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH

#
# Set and display the coverage results path
#

echo "Using coverage results path \"$COVERAGE_RESULTS_PATH\" to save test coverage results."
FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH

#
# Display custom parameters
#

echo "Using custom parameters $CUSTOM_PARAMETERS."

# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html

#
# Display the unity version
#

echo "Using Unity version \"$UNITY_VERSION\" to test."

#
# Overall info
#

echo ""
echo "###########################"
echo "# Artifacts folder #"
echo "###########################"
echo ""
echo "Creating \"$FULL_ARTIFACTS_PATH\" if it does not exist."
mkdir -p $FULL_ARTIFACTS_PATH

echo ""
echo "###########################"
echo "# Project directory #"
echo "###########################"
echo ""
ls -alh $UNITY_PROJECT_PATH

#
# Testing for each platform
#
for platform in ${TEST_PLATFORMS//;/ }; do
echo ""
echo "###########################"
echo "# Testing in $platform #"
echo "###########################"
echo ""

if [[ "$platform" != "COMBINE_RESULTS" ]]; then
runTests="-runTests -testPlatform $platform -testResults $FULL_ARTIFACTS_PATH/$platform-results.xml"
else
runTests="-quit"
fi

/Applications/Unity/Hub/Editor/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity \
-batchmode \
-silent-crashes \
-logFile "$FULL_ARTIFACTS_PATH/$platform.log" \
-projectPath "$UNITY_PROJECT_PATH" \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
$runTests \
-enableCodeCoverage \
-debugCodeOptimization \
-coverageOptions "$COVERAGE_OPTIONS" \
-manualLicenseFile "${ACTIVATE_LICENSE_PATH}/UnityLicenseFile.ulf" \
$CUSTOM_PARAMETERS

# Catch exit code
TEST_EXIT_CODE=$?

cat ~/Library/Logs/Unity/Unity.Licensing.Client.log

# Print unity log output
cat "$FULL_ARTIFACTS_PATH/$platform.log"

# Display results
if [ $TEST_EXIT_CODE -eq 0 ]; then
echo "Run succeeded, no failures occurred";
elif [ $TEST_EXIT_CODE -eq 2 ]; then
echo "Run succeeded, some tests failed";
elif [ $TEST_EXIT_CODE -eq 3 ]; then
echo "Run failure (other failure)";
else
echo "Unexpected exit code $TEST_EXIT_CODE";
fi

if [ $TEST_EXIT_CODE -ne 0 ]; then
TEST_RUNNER_EXIT_CODE=$TEST_EXIT_CODE
fi

echo ""
echo "###########################"
echo "# $platform Results #"
echo "###########################"
echo ""

if [[ "$platform" != "COMBINE_RESULTS" ]]; then
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml"
cat "$FULL_ARTIFACTS_PATH/$platform-results.xml" | grep test-run | grep Passed
fi
done

#
# Permissions
#

# Make a given user owner of all artifacts
if [[ -n "$CHOWN_FILES_TO" ]]; then
chown -R "$CHOWN_FILES_TO" "$UNITY_PROJECT_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_ARTIFACTS_PATH"
chown -R "$CHOWN_FILES_TO" "$FULL_COVERAGE_RESULTS_PATH"
fi

# Add read permissions for everyone to all artifacts
chmod -R a+r "$UNITY_PROJECT_PATH"
chmod -R a+r "$FULL_ARTIFACTS_PATH"
chmod -R a+r "$FULL_COVERAGE_RESULTS_PATH"
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/entrypoint.sh → dist/platforms/ubuntu/entrypoint.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash

set -x
#
# Create directory for license activation
#
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions dist/steps/run_tests.sh → dist/platforms/ubuntu/steps/run_tests.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ for platform in ${TEST_PLATFORMS//;/ }; do
# Catch exit code
TEST_EXIT_CODE=$?

cat ~/.config/UnityHub/logs/info-log.json
cat ~/.config/unity3d/Unity/Unity.Licensing.Client.log

# Print unity log output
cat "$FULL_ARTIFACTS_PATH/$platform.log"

Expand Down
23 changes: 23 additions & 0 deletions dist/platforms/ubuntu/steps/set_gitcredential.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

if [ -z "${GIT_PRIVATE_TOKEN}" ]
then
echo "GIT_PRIVATE_TOKEN unset skipping"
else
echo "GIT_PRIVATE_TOKEN is set configuring git credentials"

git config --global credential.helper store
git config --global --replace-all url.https://github.com/.insteadOf ssh://git@github.com/
git config --global --add url.https://github.com/.insteadOf git@github.com

git config --global url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "https://github.com/"
git config --global url."https://ssh:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "ssh://git@github.com/"
git config --global url."https://git:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "git@github.com:"

fi

echo "---------- git config --list -------------"
git config --list

echo "---------- git config --list --show-origin -------------"
git config --list --show-origin
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 9997a79

Please sign in to comment.