Skip to content

Instantly share code, notes, and snippets.

@montao
Created June 26, 2021 07:11
Show Gist options
  • Save montao/fe80519da233fb2a717541aba1a86172 to your computer and use it in GitHub Desktop.
Save montao/fe80519da233fb2a717541aba1a86172 to your computer and use it in GitHub Desktop.
name: Build project for Unity 2020.x in GitHub actions
on:
workflow_dispatch:
inputs:
webgl-required:
description: 'webgl-required'
required: false
default: 'false'
android-required:
description: 'android-required'
required: false
default: 'false'
ios-required:
description: 'ios-required'
required: false
default: 'false'
pc-required:
description: 'pc-required'
required: false
default: 'false'
macos-required:
description: 'macos-required'
required: false
default: 'false'
linux-required:
description: 'linux-required'
required: false
default: 'false'
all-required:
description: 'all-required'
required: false
default: 'false'
jobs:
data:
name: Prepare build info
runs-on: ubuntu-latest
outputs:
build-matrix: ${{ steps.build-matrix.outputs.matrix }}
steps:
- name: Prepare build matrix
id: build-matrix-prep
run: |
echo "Create new target array"
stargets=''
if [ "${{ github.event.inputs.ios-required }}" == "true" ]; then
stargets='\"iOS\"'
fi
if [[ "${{ github.event.inputs.android-required }}" == "true" && $stargets == '' ]]; then
stargets="\"Android\""
elif [ "${{ github.event.inputs.android-required }}" == "true" ]; then
stargets=$stargets,'\"Android\"'
fi
if [[ "${{ github.event.inputs.pc-required }}" == "true" && $stargets == '' ]]; then
stargets="\"StandaloneWindows64\""
elif [ "${{ github.event.inputs.pc-required }}" == "true" ]; then
stargets=$stargets,'\"StandaloneWindows64\"'
fi
if [[ "${{ github.event.inputs.webgl-required }}" == "true" && $stargets == '' ]]; then
stargets="\"WebGL\""
elif [ "${{ github.event.inputs.webgl-required }}" == "true" ]; then
stargets=$stargets,'\"WebGL\"'
fi
if [[ "${{ github.event.inputs.macos-required }}" == "true" && $stargets == '' ]]; then
stargets="\"StandaloneWindows64\""
elif [ "${{ github.event.inputs.macos-required }}" == "true" ]; then
stargets=$stargets,'\"StandaloneOSX\"'
fi
if [[ "${{ github.event.inputs.linux-required }}" == "true" && $stargets == '' ]]; then
stargets='\"StandaloneLinux64\"'
elif [ "${{ github.event.inputs.linux-required }}" == "true" ]; then
stargets=$stargets,'\"StandaloneLinux64\"'
fi
echo $stargets
echo "action_trg=${stargets}" >> $GITHUB_ENV
- name: Use the value
id: build-matrix
run: |
echo "::set-output name=matrix::{\"targetPlatform\":[${{ env.action_trg }}]}"
build:
name: ${{ matrix.targetPlatform }} - build project
runs-on: ubuntu-latest
needs: [data]
if: github.event.inputs.all-required == 'true' || github.event.inputs.android-required == 'true' || github.event.inputs.ios-required == 'true' || github.event.inputs.webgl-required == 'true' || github.event.inputs.pc-required == 'true' || github.event.inputs.linux-required == 'true' || github.event.inputs.macos-required == 'true'
strategy:
fail-fast: false
matrix: ${{fromJson(needs.data.outputs.build-matrix)}}
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
fetch-depth: 0
lfs: true
- uses: actions/cache@v2
with:
path: Library
key: Library-${{ matrix.targetPlatform }}
restore-keys: Library-
- name: Free disk space
run: .github/workflows/scripts/free_disk_space.sh
- uses: game-ci/unity-builder@v2
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: ${{ matrix.targetPlatform }}
- uses: actions/upload-artifact@v2
with:
name: Build-${{ matrix.targetPlatform }}
path: build/${{ matrix.targetPlatform }}
- name: ${{ matrix.targetPlatform }} - build project
if: github.event.inputs.webgl-required == 'true'
uses: actions/download-artifact@v2
with:
name: Build-WebGL
- name: Commit release
if: github.event.inputs.webgl-required == 'true'
run: |
git stash
git checkout webgl
rm -rf docs
mv WebGL docs
git config --global user.name 'Niklas'
git config --global user.email 'montao@users.noreply.github.com'
git add docs
git commit -m "Automated commit" docs
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment