This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
build: | |
name: Unity Build 👽 | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
# Step 2: Stash any local changes (if needed) and apply them later if necessary | |
- name: Stash any local changes (if needed) | |
run: | | |
echo "Stashing local changes" | |
git stash push --include-untracked | |
# Step 3: Pull the latest changes from main | |
- name: Pull latest changes from main | |
run: | | |
echo "Pulling latest changes from main" | |
git pull origin main --no-rebase | |
# Step 4: Pull Unity image and build the project using Unity Builder | |
- name: Build project | |
run: | | |
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" | |
env: | |
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} | |
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} | |
BUILD_PATH: ${{ secrets.BUILD_PATH }} | |
GITHUB_WORKSPACE: ${{ github.workspace }} | |
# Step 5: Upload build artifact | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifact | |
path: ${{ secrets.BUILD_PATH }} | |
# Step 6: Checkout the gh-pages branch | |
- name: Checkout gh-pages branch | |
run: | | |
echo "Switching to gh-pages branch" | |
git checkout ${ secrets.DEPLOYMENT_BRANCH } | |
# Step 7: Apply the stashed changes to the gh-pages branch | |
- name: Apply stashed changes to gh-pages | |
run: | | |
echo "Applying stashed changes to gh-pages" | |
git stash apply | |
git add -A | |
git commit -m "Deploying latest build to gh-pages" | |
# Step 8: Push the changes to gh-pages | |
- name: Push changes to gh-pages branch | |
run: | | |
echo "Pushing changes to gh-pages branch" | |
git push origin ${ secrets.DEPLOYMENT_BRANCH } | |
# Step 9: Clean up: Delete stashed changes (if any) | |
- name: Clean up stashed changes | |
run: | | |
echo "Cleaning up stashed changes (if any)" | |
git stash clear |