Skip to content

new: divided action in jobs #165

new: divided action in jobs

new: divided action in jobs #165

Workflow file for this run

name: Unity WebGL Automatic Build 👽✨🚀
on:
push:
branches:
- '1-configure-as-a-unity-package'
pull_request:
branches:
- 'main'
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
# Checkout Repository Job
checkout:
name: Checkout Repository
runs-on: ubuntu-22.04 # Ensure Ubuntu version is consistent
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}
- name: Echo Checkout Completed
run: echo "Repository has been successfully checked out."
# Git LFS Cache and Pull Job
lfs:
name: Git LFS Setup and Pull
runs-on: ubuntu-22.04
needs: checkout # This job depends on the "checkout" job
steps:
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
restore-keys: |
${{ runner.os }}-lfs-
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
- name: Echo LFS Pull Completed
run: echo "Git LFS has been pulled and reset successfully."
# Cache Unity Library Job
cache-library:
name: Unity Library Cache
runs-on: ubuntu-22.04
needs: lfs # This job depends on the "lfs" job
steps:
- uses: actions/cache@v3
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
- name: Echo Unity Library Cache Completed
run: echo "Unity Library has been successfully cached."
# Build Project Job
build:
name: Build Unity Project
runs-on: ubuntu-22.04
needs: cache-library # This job depends on the "cache-library" job
steps:
- name: Pull Unity Image and Build Project
run: |
echo "Starting to pull Unity image and build project"
docker pull unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0
docker run --rm \
-v $GITHUB_WORKSPACE:/workspace \
-e UNITY_LICENSE=$UNITY_LICENSE \
-e UNITY_EMAIL=$UNITY_EMAIL \
-e UNITY_PASSWORD=$UNITY_PASSWORD \
-e UNITY_SERIAL=$UNITY_SERIAL \
-e UNITY_VERSION=2022.3.10f1 \
-e BUILD_PATH=$BUILD_PATH \
-e BUILD_NAME=WebGL \
-e BUILD_TARGET=WebGL \
unityci/editor:ubuntu-2022.3.10f1-webgl-3.1.0 /bin/bash -c "/workspace/entrypoint.sh"
- name: Echo Build Completed
run: echo "Unity build has completed successfully."
# Upload Build Artifact Job
upload:
name: Upload Build Artifact
runs-on: ubuntu-22.04
needs: build # This job depends on the "build" job
steps:
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: ${{ secrets.BUILD_PATH }}
- name: Echo Upload Completed
run: echo "Build artifact has been uploaded successfully."
# Stash and Reset Job
stash-reset:
name: Stash Build Result and Reset Local Changes
runs-on: ubuntu-22.04
needs: upload # This job depends on the "upload" job
steps:
- name: Stash build result and reset local changes
run: |
echo "Applying initial configs"
sudo chown -R $USER:$USER ${{ secrets.BUILD_PATH }}
git config --global user.email "${{ secrets.GH_EMAIL }}"
git config --global user.name "${{ secrets.GH_USERNAME }}"
git add ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
git stash push ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}
git reset --hard
sudo git clean -d -x -f
- name: Echo Stash and Reset Completed
run: echo "Build result has been stashed and local changes have been reset."
# Clean and Deploy Job
deploy:
name: Clean and Deploy to gh-pages
runs-on: ubuntu-22.04
needs: stash-reset # This job depends on the "stash-reset" job
steps:
- name: Cleaning gh-pages branch
run: |
echo "Switching to the deployment branch: ${{ secrets.DEPLOYMENT_BRANCH }}"
git switch -f ${{ secrets.DEPLOYMENT_BRANCH }}
git reset --hard
sudo git clean -d -x -f
rm -r *
git add *
git commit -m "cleaning branch"
git push
- name: Applying stashed files to gh-pages
run: |
echo "Applying stashed files to gh-pages"
git stash apply stash@{0}
- name: Copying files to root directory
run: |
cd ${{ secrets.BUILD_PATH }}/${{ secrets.TARGET_PLATFORM }}/${{ secrets.TARGET_PLATFORM }}
ls
cp -r * ../../../
cd ../../../
rm -r ${{ secrets.BUILD_PATH }}
ls
pwd
- name: Pushing deployment to gh-pages branch
run: |
echo "Pushing deployment to gh-pages branch"
pwd
git status
git add *
git commit -m "Deployment"
git push
env:
GH_TOKEN: ${{ secrets.PAT }} # Use the authentication token for git push
- name: Echo Deployment Completed
run: echo "Deployment to gh-pages branch has been successfully completed."