Nerd For Tech
Published in

Nerd For Tech

git it on the page!

Setting up Continuous Integration with GitHub Actions

Photo by Thought Catalog on Unsplash

Publish to GitHub pages

In my last article, we looked at setting up the continuous delivery portion of our pipeline using GitHub Actions so that our project would release to our itch.io account every time we created a new release in our GitHub repository. itch.io isn’t the only place we have available to us for releases though! In fact, GitHub has a service that we can turn on in our repository called GitHub Pages that will allow us to host our repository (or a branch of our repository) as a website. This feature is more commonly used to publish web site based project repositories directly into a hosted state. In our case we are going to setup a special branch in our repository that holds a WebGL build of our game and the requisite template files to display it in the browser. Then we’re going to use GitHub actions to create and publish our games build into this branch for GitHub Pages.

Generate personal access token

  1. In the upper-right corner of any page, click your profile photo, then click Settings.
  2. In the left sidebar, click Developer settings.
  3. In the left sidebar, click Personal access tokens.
  4. Click Generate new token.
  5. Give your token a descriptive name.
  6. To give your token an expiration, select the Expiration drop-down menu, then click a default or use the calendar picker.
  7. Select the scopes, or permissions, you’d like to grant this token. To use your token to access repositories from the command line, select repo.
  8. Click Generate token.
  9. Copy Token and Store in a safe place (like a password vault application) as this will not be displayed again

Create GitHub Secret

We don’t want anyone to have access to our Personal Access Token for security reasons, so we are going to store it as a Secret in our GitHub repository.

  1. Navigate to your Repository on GitHub
  2. Select Settings
  3. Select Secrets
  4. Click the “New Repository Secret” button
  5. Create a secret called GH_CREDENTIALS and paste the value of your token into it.
  6. Click the ‘Add Secret’ Button

** ENSURE UNITY IS CLOSED BEFORE CONTINUING **

Create clean(orphan) ‘gh-pages’ branch

** An orphan branch is not connected to the other branches and commits, and its working tree has no files at all.**

To create the orphan gh-pages branch: In a terminal, navigate to your repositories folder Ensure that you have credentials setup for your git provider from the command line then type the following:

git checkout --orphan gh-pages
git reset --hard
git commit --allow-empty -m "Initializing gh-pages branch"
git config lfs.locksverify false
git push origin gh-pages
git checkout develop (or whatever your previous branch was)

Enable GitHub Pages

  1. Navigate to your Repository on GitHub
  2. Select Settings
  3. Select Pages
  4. Select ‘gh-pages’ repo from dropdown under ‘Source’ section (if it’s not already selected)
  5. Select ‘/ (root)’ from the folder dropdown (if it’s not already selected)

Add the GitHub Pages Deployment Block to Main.yml

releaseToGitHubPages:
name: Release to GitHub Pages
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Web'))
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Download WebGL Artifact
uses: actions/download-artifact@v2
with:
name: build-WebGL
path: build/WebGL
- name: Deploy to GitHub Pages 🚀
uses: JamesIves/github-pages-deploy-action@4.1.3
with:
branch: gh-pages # The branch the action should deploy to.
folder: build/WebGL # The folder the action should deploy.
target-folder: build # The folder the action should be deployed to within the deployment branch

The completed file

Below is the complete Actions workflow file with additional platforms included.

name: CI - Build All Platforms
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
release:
types: [ published ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
mode:
description: 'check OR release (platform)'
required: true
default: 'check'
permissions:
contents: write
jobs:
#-------------------------------------------------------------------
# Build Project (with Linux)
#-------------------------------------------------------------------
buildWithLinux:
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
unityVersion:
- 2020.3.15f2
targetPlatform:
- StandaloneWindows # build a Windows Standalone
- StandaloneOSX # build a MacOS Standalone (Intel 64-bit)
- StandaloneLinux64 # build a Linux 64-bit Standalone
- WebGL # WebGL
steps:
- name: Free Disk Space for Android
if: matrix.targetPlatform == 'Android'
run: |
df -h
sudo swapoff -a
sudo rm -f /swapfile
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
df -h
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0
lfs: true
- name: Cache Library
uses: actions/cache@v3
with:
path: Library
key: Library-${{ matrix.targetPlatform }}
restore-keys: Library-
- name: Build Unity Project
uses: game-ci/unity-builder@v2.0-alpha-10
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
unityVersion: ${{ matrix.unityVersion }}
targetPlatform: ${{ matrix.targetPlatform }}
buildName: ${{ matrix.targetPlatform }}
versioning: Semantic
- name: Upload Build
uses: actions/upload-artifact@v3
if: github.event.action == 'published' || contains(github.event.inputs.mode, 'release')
with:
name: build-${{ matrix.targetPlatform }}
path: build/${{ matrix.targetPlatform }}
- name: Zip build/${{ matrix.targetPlatform }}
uses: montudor/action-zip@v1
if: (github.event.action == 'published' || contains(github.event.inputs.mode, 'release'))
with:
args: zip -qq -r build/build-${{ matrix.targetPlatform }}.zip build/${{ matrix.targetPlatform }}
- name: Upload build-${{ matrix.targetPlatform }}.zip to GitHub Release
uses: svenstaro/upload-release-action@v2
if: (github.event.action == 'published' || contains(github.event.inputs.mode, 'release'))
with:
repo_token: ${{ secrets.GH_CREDENTIALS }}
asset_name: build-${{ matrix.targetPlatform }}.zip
file: build/build-${{ matrix.targetPlatform }}.zip
tag: ${{ github.ref }}
overwrite: true
body: ${{ github.event.release.body }}
#-------------------------------------------------------------------
# Deploy to GitHub Pages
#-------------------------------------------------------------------
releaseToGitHubPages:
name: Release to GitHub Pages
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Web'))
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Download WebGL Artifact
uses: actions/download-artifact@v3
with:
name: build-WebGL
path: build/WebGL
- name: Deploy to GitHub Pages 🚀
uses: JamesIves/github-pages-deploy-action@v4.3.3
with:
branch: gh-pages # The branch the action should deploy to.
folder: build/WebGL # The folder the action should deploy.
target-folder: build # The folder the action should be deployed to within the deployment branch
#-------------------------------------------------------------------
# Deploy to itch.io
#-------------------------------------------------------------------
release_webgl_to_itch:
name: Release WebGL to itch.io
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Web'))
steps:
- name: download WEBGL
id: download-webgl
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "latest"
file: build-WebGL.zip
token: "${{ secrets.GH_CREDENTIALS }}"
- name: deploy to itch.io (WEBGL)
uses: josephbmanley/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
CHANNEL: html
ITCH_GAME: space-shooter-pro-redux
ITCH_USER: Arynoyn
PACKAGE: build-WebGL.zip
VERSION: ${{ steps.download-webgl.outputs.version }}
release_windows_to_itch:
name: Release Windows (32-Bit) to itch.io
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Windows'))
steps:
- name: download Windows
id: download-windows
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "latest"
file: build-StandaloneWindows.zip
token: "${{ secrets.GH_CREDENTIALS }}"
- name: deploy to itch.io (Windows)
uses: josephbmanley/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
CHANNEL: windows
ITCH_GAME: space-shooter-pro-redux
ITCH_USER: Arynoyn
PACKAGE: build-StandaloneWindows.zip
VERSION: ${{ steps.download-windows.outputs.version }}
release_macos_to_itch:
name: Release Mac OSX to itch.io
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Mac'))
steps:
- name: download MacOS
id: download-macos
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "latest"
file: build-StandaloneOSX.zip
token: "${{ secrets.GH_CREDENTIALS }}"
- name: deploy to itch.io (MacOS)
uses: josephbmanley/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
CHANNEL: mac
ITCH_GAME: space-shooter-pro-redux
ITCH_USER: Arynoyn
PACKAGE: build-StandaloneOSX.zip
VERSION: ${{ steps.download-macos.outputs.version }}

release_linux_to_itch:
name: Release Linux (64-bit) to itch.io
runs-on: ubuntu-latest
needs: buildWithLinux
if: github.event.action == 'published' || (contains(github.event.inputs.mode, 'release') && contains(github.event.inputs.mode, 'Linux'))
steps:
- name: download Linux
id: download-linux
uses: dsaltares/fetch-gh-release-asset@master
with:
version: "latest"
file: build-StandaloneLinux64.zip
token: "${{ secrets.GH_CREDENTIALS }}"
- name: deploy to itch.io (Linux)
uses: josephbmanley/butler-publish-itchio-action@master
env:
BUTLER_CREDENTIALS: ${{ secrets.BUTLER_CREDENTIALS }}
CHANNEL: linux
ITCH_GAME: space-shooter-pro-redux
ITCH_USER: Arynoyn
PACKAGE: build-StandaloneLinux64.zip
VERSION: ${{ steps.download-linux.outputs.version }}

Next Time!

If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store