Skip to content

Build the Twine game #6

Build the Twine game

Build the Twine game #6

Workflow file for this run

name: Build the Twine game
permissions:
contents: write
on:
push:
branches:
- main
schedule:
- cron: "0 0 */15 * *"
defaults:
run:
shell: bash
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- name: Set game configuration
env:
APP_NAME: My Twine game
DESCRIPTION: My Twine game description
# This must be of the format "N.N.N", where the N's are all numbers
VERSION: 1.0.0
# By default, the author will be your name on GitHub. You can manually change this.
AUTHOR: ${{ github.repository_owner }}
# If this to 'true', a copy of your game will also be hosted on the web at https://USERNAME.github.io/REPO_NAME
# Delete or comment out this line to disable that
PUBLISH_ON_WEB: true
run: |
echo "APP_NAME=${APP_NAME}" >> $GITHUB_ENV
echo "DESCRIPTION=${DESCRIPTION}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "AUTHOR=${AUTHOR}" >> $GITHUB_ENV
echo "PUBLISH_ON_WEB=${PUBLISH_ON_WEB}" >> $GITHUB_ENV
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Test for presence of Windows codesigning secrets
id: vars
shell: bash
run: |
unset HAS_WINDOWS_CREDS
if [[ -n $CERTIFICATE_WINDOWS_PFX ]]; then HAS_WINDOWS_CREDS='true' ; fi
echo set-output name=HAS_WINDOWS_CREDS::${HAS_WINDOWS_CREDS}
env:
CERTIFICATE_WINDOWS_PFX: ${{ secrets.CERTIFICATE_WINDOWS_PFX }}
- name: Check out Electron app template
uses: actions/checkout@v3
with:
repository: lazerwalker/electron-wrapper-template
ref: v1.1.0
path: app
- name: Set up Electron app environment
working-directory: ./app
run: npm install
- name: move webapp into Electron folder
run: |
cp -r ./src/* ./app/src
mv ./icon.png ./app
- name: Generate icons
working-directory: ./app
run: npm run build-icons
- name: Add MacOS certs
if: matrix.os == 'macos-latest'
shell: bash
run: |
if ! [[ -n $CERTIFICATE_OSX_APPLICATION && -n $CERTIFICATE_PASSWORD ]]; then exit 0 ; fi
KEY_CHAIN=build.keychain
CERTIFICATE_P12=certificate.p12
echo $CERTIFICATE_OSX_APPLICATION | base64 --decode > $CERTIFICATE_P12
security create-keychain -p actions $KEY_CHAIN
security default-keychain -s $KEY_CHAIN
security unlock-keychain -p actions $KEY_CHAIN
security import $CERTIFICATE_P12 -k $KEY_CHAIN -P $CERTIFICATE_PASSWORD -T /usr/bin/codesign;
security set-key-partition-list -S apple-tool:,apple: -s -k actions $KEY_CHAIN
rm -fr *.p12
env:
CERTIFICATE_OSX_APPLICATION: ${{ secrets.CERTIFICATE_OSX_APPLICATION }}
CERTIFICATE_PASSWORD: ${{ secrets.CERTIFICATE_PASSWORD }}
- name: Add Windows certificate
if: matrix.os == 'windows-latest' && steps.vars.outputs.HAS_WINDOWS_CREDS
id: write_file
uses: timheuer/base64-to-file@v1
with:
fileName: "win-certificate.pfx"
encodedString: ${{ secrets.CERTIFICATE_WINDOWS_PFX }}
- name: Set description and version number
run: |
node -e "\
const fs = require('fs');\
const pkg=require('./app/package.json');\
pkg.description=process.env.DESCRIPTION;\
pkg.version=process.env.VERSION;\
pkg.author=process.env.AUTHOR;\
fs.writeFileSync('./app/package.json',JSON.stringify(pkg,undefined,'\t'));"
- name: Build the app
working-directory: ./app
env:
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_ID_PASSWORD: ${{ secrets.APPLE_ID_PASSWORD }}
APPLE_PROVIDER: ${{ secrets.APPLE_PROVIDER }}
CERTIFICATE_NAME: ${{ secrets.CERTIFICATE_NAME }}
WINDOWS_PFX_FILE: ${{ steps.write_file.outputs.filePath }}
WINDOWS_PFX_PASSWORD: ${{ secrets.WINDOWS_PFX_PASSWORD }}
run: npm run make
- name: Publish to GitHub Pages
if: env.PUBLISH_ON_WEB
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./src
# If there is no passed-in tag, we auto-generate one based on run number
# This makes sure a different process (e.g. a Windows build vs Mac build) hasn't created it
- name: Check if auto-generated tag exists
uses: actions/github-script@v4
id: autogeneratedTagExists
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
const result = await github.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${context.runNumber}.0.0`
})
console.log("Found!")
console.log(result)
return true
} catch(e) {
console.log("Failed", e)
return false
}
# TODO: The previous GH script should just create the tag if needed
- name: Create tag if needed
uses: negz/create-tag@v1
if: ${{ !steps.autogeneratedTagExists.outputs.result && !startsWith(github.ref, 'refs/tags/v') }}
with:
version: ${{ format('{0}.0.0', github.run_number) }}
message: Auto-generated by GitHub Actions
token: ${{ secrets.GITHUB_TOKEN }}
# The next two steps are identical, except for explicitly passing in the tag name in the latter
# I wish I knew how to do this in a more elegant way.
# See also: I'd love to abstract out the startsWith() check and generated tag name into variable
- name: Release on GitHub (Built via Tag)
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: |
app/out/**/*.deb
app/out/**/*.dmg
app/out/**/*Setup.exe
app/out/**/*.rpm
app/out/**/*.zip
- name: Release on GitHub (Automated Tag)
uses: softprops/action-gh-release@v1
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ format('{0}.0.0', github.run_number) }}
files: |
app/out/**/*.deb
app/out/**/*.dmg
app/out/**/*Setup.exe
app/out/**/*.rpm
app/out/**/*.zip