From 27724004d93511a70df2eb653de00a45934b1915 Mon Sep 17 00:00:00 2001 From: "Saad A. Bazaz" Date: Thu, 19 Sep 2024 17:33:08 +0500 Subject: [PATCH 1/2] Create deploy-main.yml --- .github/workflows/deploy-main.yml | 114 ++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .github/workflows/deploy-main.yml diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml new file mode 100644 index 00000000..d68fa592 --- /dev/null +++ b/.github/workflows/deploy-main.yml @@ -0,0 +1,114 @@ +name: Unity WebGL Automatic Build 👽✨🚀 +on: + # push: + # branches: + # - 'main' + 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: + # Checkout (without LFS) + - name: Checkout repository + uses: actions/checkout@v2 + with: + token: ${{secrets.PAT}} + # Git LFS + - 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@v2 + id: lfs-cache + with: + path: .git/lfs + key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }} + + - name: Git LFS Pull + run: | + git lfs pull + git add . + git reset --hard + + # # Cache + - uses: actions/cache@v2 + with: + path: Library + key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} + restore-keys: | + Library- + + # # Build + - name: Build project + uses: game-ci/unity-builder@v2 + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} + with: + targetPlatform: ${{ vars.TARGET_PLATFORM }} + buildsPath: ${{ vars.BUILD_PATH }} + allowDirtyBuild: true + # Output: Artifact + - name: Upload Build Artifact + uses: actions/upload-artifact@v2 + with: + name: ${{ vars.ARTIFACT_NAME }} + path: ${{ vars.BUILD_PATH }} + # Deployment + - name: Stash build result and reset local changes + run: | + echo "Applying initial configs" + sudo chown -R $USER:$USER ${{ vars.BUILD_PATH }} + git config --global user.email "${{ secrets.GH_EMAIL }}" + git config --global user.name "${{ secrets.GH_USERNAME }}" + echo "Stash and reset" + git add ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }} + git stash push ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }} + git stash list + git reset --hard + sudo git clean -d -x -f + # Deployment + - name: Cleaning gh-pages branch + run: | + echo "Switch to ${{ vars.DEPLOYMENT_BRANCH }}" + git switch -f ${{ vars.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 ${{ vars.DEPLOYMENT_BRANCH }} + run: | + echo "Applying stash" + git stash apply stash@{0} + - name: Copying files to root directory + run: | + cd ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }}/${{ vars.TARGET_PLATFORM }} + ls + cp -r * ../../../ + cd ../../../ + rm -r ${{ vars.BUILD_PATH }} + ls + pwd + - name: Pushing deployment to gh-pages branch + run: | + pwd + git status + git add * + git commit -m "Deployment" + git push + git reset --hard + sudo git clean -d -x -f From f21528ca0b32a4c2f1fbabaab528bf8de7c440d0 Mon Sep 17 00:00:00 2001 From: "Saad A. Bazaz" Date: Thu, 19 Sep 2024 17:37:32 +0500 Subject: [PATCH 2/2] Update checkout to v4 --- .github/workflows/deploy-main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index d68fa592..b3a01c4f 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -21,7 +21,7 @@ jobs: steps: # Checkout (without LFS) - name: Checkout repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: token: ${{secrets.PAT}} # Git LFS