Game build CI/CD #1
This file contains 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: | |
# - '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 |