# Build and upload the project by pushing tags name: Build project & release on: push: tags: - '*' branches: - master jobs: variables: name: Define variables ๐Ÿ”— runs-on: ubuntu-latest outputs: UNITY_VERSION: ${{ steps.set_unity_version.outputs.VERSION }} TAG: ${{ steps.set_tag.outputs.VERSION }} BUILD_NAME: ${{ steps.set_build_name.outputs.VERSION }} steps: - uses: actions/checkout@v4 with: sparse-checkout: | ProjectSettings/ProjectVersion.txt - name: Set unity version id: set_unity_version run: | UNITY_VERSION=$(sed -n 's/^\m_EditorVersion: //p'< ./ProjectSettings/ProjectVersion.txt) echo "VERSION=$UNITY_VERSION" >> $GITHUB_OUTPUT - name: Set tag id: set_tag run: | if [[ $GITHUB_REF == refs/tags/* ]]; then echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT else echo "VERSION=${{ steps.set_unity_version.outputs.VERSION }}-webgl2-master" >> $GITHUB_OUTPUT fi - name: Set target name id: set_build_name run: echo "VERSION=WebGL-${{ steps.set_tag.outputs.VERSION }}" >> $GITHUB_OUTPUT - name: Log variables run: | echo "UNITY_VERSION -> ${{ steps.set_unity_version.outputs.VERSION }}" echo "TAG -> ${{ steps.set_tag.outputs.VERSION }}" echo "BUILD_NAME -> ${{ steps.set_build_name.outputs.VERSION }}" tagVersionMatchTest: needs: [ variables ] name: Check tag version match โ˜‘ runs-on: ubuntu-latest steps: - name: Log tag and version run: echo "Github tag '${{ needs.variables.outputs.TAG }}' has to start with unity version '${{ needs.variables.outputs.UNITY_VERSION }}'" - name: Version match โœ” if: startsWith(${{ needs.variables.outputs.TAG }}, {{ needs.variables.outputs.UNITY_VERSION }} run: echo "Versions are matching ๐Ÿฅณ" - name: Version missmatch โŒ if: ${{ !startsWith(needs.variables.outputs.TAG, needs.variables.outputs.UNITY_VERSION) }} uses: actions/github-script@v4 with: script: | core.setFailed('Unity version does not match tag version') buildProject: name: Create Unity WebGL Build ๐Ÿ— # Build if it's a master push or if the tag is not just the unity version if: ${{ github.ref == 'refs/heads/master' || needs.variables.outputs.TAG != needs.variables.outputs.UNITY_VERSION }} needs: [ variables ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: lfs: true # Avoid running into space issues for github runners - Docker images can take up quite some space - name: Free Disk Space run: | echo "Disk space before cleanup:" df -h sudo rm -rf /usr/share/dotnet sudo rm -rf /opt/ghc sudo rm -rf /usr/local/share/boost sudo rm -rf "$AGENT_TOOLSDIRECTORY" echo "Disk space after cleanup:" df -h # Unity 2020 cache is not compatible with older versions - name: Unity Library Cache 2020 or higher if: ${{ !startsWith(needs.variables.outputs.UNITY_VERSION, '201') }} uses: actions/cache@v4 with: path: Library key: Library-202x-WebGL restore-keys: Library-202x- - name: Unity Library Cache 2019 or lower if: ${{ startsWith(needs.variables.outputs.UNITY_VERSION, '201') }} uses: actions/cache@v4 with: path: Library key: Library-201x-WebGL restore-keys: Library-201x- - name: Build project uses: game-ci/unity-builder@v4 env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} with: buildMethod: UnityBuilderAction.BuildScript.BuildWithCommandlineArgs customParameters: -tag ${{ needs.variables.outputs.TAG }} targetPlatform: WebGL versioning: None buildName: ${{ needs.variables.outputs.BUILD_NAME }} - name: Check Disk Space After Build run: | echo "Disk space after build:" df -h AVAILABLE=$(df / | tail -1 | awk '{print $4}') AVAILABLE_GB=$(echo $AVAILABLE | sed 's/G//') echo "Available space: ${AVAILABLE_GB}GB" if (( $(echo "$AVAILABLE_GB < 1" | bc -l) )); then echo "::warning::Low disk space! Less than 1GB remaining." fi - uses: actions/upload-artifact@v4 with: name: ${{ needs.variables.outputs.BUILD_NAME }} path: build/WebGL createRelease: name: Create Github release ๐Ÿ™ # only run for the pure tag without build parameters if: ${{ github.ref_type == 'tag' && needs.variables.outputs.TAG == needs.variables.outputs.UNITY_VERSION }} needs: [ variables ] runs-on: ubuntu-latest steps: - name: Create Release uses: softprops/action-gh-release@v2 with: body: | ## Changes * [${{ needs.variables.outputs.UNITY_VERSION }}-webgl2](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-webgl2/) [${{ needs.variables.outputs.UNITY_VERSION }}-webgl1](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-webgl1/) [${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl2 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl2/) [${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl1 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-urp-webgl1/) [${{ needs.variables.outputs.UNITY_VERSION }}-minsize-webgl1 Demo](https://deml.io/experiments/unity-webgl/${{ needs.variables.outputs.UNITY_VERSION }}-minsize-webgl1/) draft: true deployOnServer: name: Deploy on server ๐Ÿš€ needs: [ variables, buildProject ] # Guarded by username, you will need to remove or replace the line for your fork if: ${{ github.repository_owner == 'JohannesDeml' }} runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v4 with: name: ${{ needs.variables.outputs.BUILD_NAME }} path: build - name: Display structure of root files run: ls -R working-directory: build/${{ needs.variables.outputs.BUILD_NAME }} - name: Deploy โคด uses: SamKirkland/FTP-Deploy-Action@v4.3.5 with: server: ${{ secrets.FTP_SERVER }} username: ${{ secrets.FTP_USER }} password: ${{ secrets.FTP_PASSWORD }} port: 21 protocol: ftps local-dir: ./build/${{ needs.variables.outputs.BUILD_NAME }}/ server-dir: ./${{ needs.variables.outputs.TAG }}/ # Make sure old files are deleted (e.g. created with name files as hashes) dangerous-clean-slate: true