updloajssjsjs #171
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 repository without LFS | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| with: | |
| token: ${{ secrets.PAT }} | |
| # Step 2: Git LFS: Restore LFS files | |
| - 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 | |
| # Step 3: Cache Unity Library | |
| - uses: actions/cache@v2 | |
| with: | |
| path: Library | |
| key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} | |
| restore-keys: | | |
| Library- | |
| # Step 4: Build Unity Project | |
| - 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 | |
| # Step 5: Upload Build Artifact | |
| - name: Upload Build Artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: ${{ vars.ARTIFACT_NAME }} | |
| path: ${{ vars.BUILD_PATH }} | |
| # Step 6: Stash the build result and reset local changes | |
| - name: Stash build result and reset local changes | |
| run: | | |
| echo "Stashing build result and resetting local changes" | |
| sudo chown -R $USER:$USER ${{ vars.BUILD_PATH }} | |
| git config --global user.email "${{ secrets.GH_EMAIL }}" | |
| git config --global user.name "${{ secrets.GH_USERNAME }}" | |
| git add ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }} | |
| git stash push ${{ vars.BUILD_PATH }}/${{ vars.TARGET_PLATFORM }} | |
| git reset --hard | |
| sudo git clean -d -x -f | |
| # Step 7: Checkout gh-pages branch | |
| - name: Checkout gh-pages branch | |
| run: | | |
| echo "Switching to gh-pages branch" | |
| git switch -f ${{ secrets.DEPLOYMENT_BRANCH }} | |
| git reset --hard | |
| sudo git clean -d -x -f | |
| # Step 8: Apply stashed changes to gh-pages branch | |
| - name: Apply stashed changes to gh-pages | |
| run: | | |
| echo "Applying stashed changes to gh-pages" | |
| git stash apply stash@{0} | |
| git add * | |
| git commit -m "Deploying latest build to gh-pages" | |
| # Step 9: Push changes to gh-pages branch | |
| - name: Push changes to gh-pages branch | |
| run: | | |
| echo "Pushing changes to gh-pages branch" | |
| git push origin ${{ secrets.DEPLOYMENT_BRANCH }} | |
| # Step 10: Clean up: Delete stashed changes (if any) | |
| - name: Clean up stashed changes | |
| run: | | |
| echo "Cleaning up stashed changes" | |
| git stash clear |