Skip to content

bumping version --publish #573

bumping version --publish

bumping version --publish #573

name: Build For Wasm 32-bit Web Browser
on:
push:
branches: ["main"]
workflow_dispatch:
inputs:
publish:
description: 'Publish engine'
required: true
default: 'no'
type: choice
options:
- 'no'
- 'yes'
runanyway:
description: 'Override --norun Flag'
required: true
default: 'no'
type: choice
options:
- 'no'
- 'yes'
jobs:
build:
if: (!endsWith(github.event.head_commit.message, '--norun') || inputs.runanyway == 'yes')
runs-on: ubuntu-latest
environment: general
env:
CARGO_TERM_COLOR: always
WORKSPACE: ${{ github.workspace }}
RUST_BACKTRACE: full
HOST: /pkg
steps:
# Setup Build Environment
- name: 🎉 The job was automatically triggered by a ${{ github.event_name }} event.
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- name: 🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- name: 🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
lfs: true
submodules: recursive
- name: 💡 The ${{ github.repository }} repository has been cloned to the runner.
run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
# Install Rust
- name: Make Tools Directory
run: mkdir -p ${{ github.workspace }}/tools
- name: Download Rust Installer
run: curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://sh.rustup.rs > ${{ github.workspace }}/tools/rust.sh
- name: Make Rust Installer Executable
run: chmod +x ${{ github.workspace }}/tools/rust.sh
- name: Install Rust
run: ${{ github.workspace }}/tools/rust.sh -y
- name: Load Cargo Environment
run: source "$HOME/.cargo/env"
# Install Rust Stable Toolchains
- name: Set Rust To The Stable Toolchains
run: $HOME/.cargo/bin/rustup default stable
# Setup Rust Build Caching
- uses: Swatinem/rust-cache@v2
with:
shared-key: "wasm32-rust"
# Add Build Targets
- name: Add 32-bit Wasm Build Target
run: $HOME/.cargo/bin/rustup target add wasm32-unknown-unknown
# Install Git Pre-Commit Hooks to Enforce Hooks
- name: Install Git Pre-Commit Hooks to Enforce Hooks
run: pip install pre-commit
# Check Pre-Commit Version
- name: Check Pre-Commit Version
run: pre-commit --version
# Install Pre-Commit Hooks
- name: Install Pre-Commit Hooks
run: pre-commit install
# Check Files with Pre-Commit Hooks
- name: Check Files with Pre-Commit Hooks
run: pre-commit run --all-files
# Install Wasm-Bindgen-CLI
- name: Install Wasm-Bindgen-CLI
run: |
# wasm-bindgen is currently unstable, so getting the exact version used is required
export WASM_BINDGEN_VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^wasm-bindgen' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
$HOME/.cargo/bin/cargo install wasm-bindgen-cli --version $WASM_BINDGEN_VERSION
# Install Wasm-Opt
- name: Install Wasm-Opt
run: $HOME/.cargo/bin/cargo install wasm-opt
# Install Wasm2Map
- name: Install Wasm2Map
run: $HOME/.cargo/bin/cargo install cargo-wasm2map
# Compile Program
- name: Build Engine (Release)
run: |
# Sets the build timestamp to the current commit to make builds reproducible
export SOURCE_DATE_EPOCH="`git --no-pager log -1 --format="%at"`"
$HOME/.cargo/bin/cargo build --target wasm32-unknown-unknown --verbose --release --lib
# Generate Bindings
- name: Generate Bindings
run: $HOME/.cargo/bin/wasm-bindgen ${{ github.workspace }}/target/wasm32-unknown-unknown/release/main.wasm --out-dir ${{ github.workspace }}/pkg --typescript --target web
# Optimize Program
- name: Optimize Program
run: |
$HOME/.cargo/bin/wasm-opt ${{ github.workspace }}/pkg/main_bg.wasm -o ${{ github.workspace }}/pkg/main_bg.opt.wasm -Oz
mv ${{ github.workspace }}/pkg/main_bg.opt.wasm ${{ github.workspace }}/pkg/main_bg.wasm
# Build Source Maps
# - name: Build Source Maps
# run: |
# $HOME/.cargo/bin/cargo wasm2map ${{ github.workspace }}/pkg/main_bg.wasm --patch --base-url $HOST
# Display Export Directory
- name: Display Git Staging
run: |
cd ${{ github.workspace }}
git status -v -s -b
# Generate Service Worker
- name: Generate Service Worker
run: /usr/bin/sed "s/%CACHE_VERSION%/`/usr/bin/git rev-parse HEAD`/" ${{ github.workspace }}/examples/wasm/web/service-worker.js.template > ${{ github.workspace }}/examples/wasm/web/service-worker.js
# Display Export Directory
- name: Display Export Directory
run: ls -liallh ${{ github.workspace }}/target/wasm32-unknown-unknown/release
# Prepare Artifact Uploads
- name: Prepare Artifact Uploads (Client/Server)
run: |
mkdir -p ${{ github.workspace }}/upload/wasm/resources
cp -a ${{ github.workspace }}/pkg ${{ github.workspace }}/upload/wasm
cp -a ${{ github.workspace }}/examples/wasm/web/index.html ${{ github.workspace }}/upload/wasm
cp -a ${{ github.workspace }}/examples/wasm/web/manifest.json ${{ github.workspace }}/upload/wasm
cp -a ${{ github.workspace }}/examples/wasm/web/service-worker.js ${{ github.workspace }}/upload/wasm
cp -a ${{ github.workspace }}/target/binding ${{ github.workspace }}/upload/wasm
# cp -af ${{ github.workspace }}/resources/wasm ${{ github.workspace }}/upload/wasm/resources
cp -a ${{ github.workspace }}/resources/assets ${{ github.workspace }}/upload/wasm/resources
# Extract/Import GPG Signing Key
- name: Extract GPG Signing Key
run: |
echo "${{ secrets.GPG_SIGNING_KEY }}" > $HOME/signing.gpg
gpg --import $HOME/signing.gpg
rm -rf $HOME/signing.gpg
# Sign Files
- name: Sign Files (Client/Server)
run: |
cd ${{ github.workspace }}/upload/wasm
find . -type f -not -name "checksums.sha512" -exec shasum -a 512 {} \; > checksums.sha512
gpg --sign checksums.sha512
# Remove GPG Signing Key
- name: Remove GPG Signing Key
run: rm -rf $HOME/.gnupg
# Compress Files
- name: Compress Files as Tar (Client/Server)
run: |
export XZ_OPT=-e9
cd ${{ github.workspace }}/upload/wasm
tar cvJf ${{ github.workspace }}/upload/CatgirlEngine-Wasm-32-bit-Web.tar.xz .
# Compress Files
- name: Compress Files as Zip (Client/Server)
run: |
cd ${{ github.workspace }}/upload/wasm
zip -r9 ${{ github.workspace }}/upload/CatgirlEngine-Wasm-32-bit-Web.zip .
# Upload Engine
- name: Upload Engine Tar (Release)
uses: actions/upload-artifact@v4
with:
name: CatgirlEngine-Wasm-32-bit-Tar
path: ${{ github.workspace }}/upload/CatgirlEngine-Wasm-32-bit-Web.tar.xz
# Upload Engine
- name: Upload Engine Zip (Release)
uses: actions/upload-artifact@v4
with:
name: CatgirlEngine-Wasm-32-bit-Zip
path: ${{ github.workspace }}/upload/CatgirlEngine-Wasm-32-bit-Web.zip
# List Environment
- name: List Environment
run: env
- name: List All Installed Packages
run: |
apt list --installed | wc -l
apt list --installed
- name: List All Files
run: find ${{ github.workspace }}
# Display Build Status
- name: 🍏 This job's status is ${{ job.status }}.
run: echo "🍏 This job's status is ${{ job.status }}."
deploy:
if: ${{ success() && (endsWith(github.event.head_commit.message, '--publish') || inputs.publish == 'yes') }}
needs: [Build]
runs-on: ubuntu-latest
permissions:
# See https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
# See https://docs.github.com/en/rest/overview/permissions-required-for-fine-grained-personal-access-tokens
contents: write
environment: itch.io
steps:
# Setup Build Environment
- name: 🎉 The job was automatically triggered by a ${{ github.event_name }} event.
run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- name: 🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!
run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- name: 🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}.
run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
with:
lfs: true
submodules: recursive
- name: 💡 The ${{ github.repository }} repository has been cloned to the runner.
run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
# Install Dependencies
- name: Install and Cache APT Packages
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq # coreutils gitsome
version: 1.0
execute_install_scripts: true
# Download Engine
- name: Download Engine (Release)
uses: actions/download-artifact@v4
with:
name: CatgirlEngine-Wasm-32-bit-Tar
path: ${{ github.workspace }}/artifacts/wasm-32-bit-web
# Download Engine
- name: Download Engine (Release)
uses: actions/download-artifact@v4
with:
name: CatgirlEngine-Wasm-32-bit-Zip
path: ${{ github.workspace }}/artifacts/wasm-32-bit-web-zip
# Create Tag and Github Release
- name: 👩‍💻 Create Tag and Github Release
env:
GH_TOKEN: ${{ github.token }}
run: |
# TODO: Consider checking for -alpha and -beta to filter onto other packages
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export VERSION_STRING="Catgirl Engine v$VERSION"
export BODY="Autogenerated Release From Github Actions..."
export DRAFT="false"
export PRERELEASE="false"
export LATEST="true"
export GENERATE_RELEASE_NOTES="true"
export BRANCH=`git branch --show-current --format="%s" | tr -d '\n'`
# export COMMIT=`git log -1 --oneline | cut -d' ' -f1 | tr -d '\n'`
gh api --method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/${{ github.repository }}/releases \
-f tag_name="v$VERSION" \
-f target_commitish="$BRANCH" \
-f name="$VERSION_STRING" \
-f body="$BODY" \
-f make_latest="$LATEST" \
-F draft="$DRAFT" \
-F prerelease="$PRERELEASE" \
-F generate_release_notes="$GENERATE_RELEASE_NOTES" || echo "Already Exists"
# Publish to Github Release
- name: 👩‍💻 Publish to Github Release
env:
GH_TOKEN: ${{ github.token }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
export ARTIFACT_PATH="${{ github.workspace }}/artifacts/wasm-32-bit-web/CatgirlEngine-Wasm-32-bit-Web.tar.xz"
export DISPLAY_LABEL="Wasm Web Tar (wasm32)"
gh release upload v$VERSION "$ARTIFACT_PATH"#"$DISPLAY_LABEL" -R ${{ github.repository }}
# Install Butler (For Uploading to Itch.io)
- name: Install Butler (Upload to Itch.io)
id: download-butler
continue-on-error: true
run: |
# https://itch.io/docs/butler/pushing.html#channel-names
# Setup For Installation
mkdir -p ${{ github.workspace }}/tools/butler
# Install Butler
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://broth.itch.zone/butler/linux-amd64/LATEST/archive/default > ${{ github.workspace }}/tools/butler-linux-amd64.zip
unzip -o ${{ github.workspace }}/tools/butler-linux-amd64.zip -d ${{ github.workspace }}/tools/butler
# Fallback to deal with DDOS attack on Itch.io at the time of writing
- name: Install Butler (Fallback)
if: steps.download-butler.outcome == 'failure'
run: |
# Setup For Installation
mkdir -p ${{ github.workspace }}/tools/butler
# Install Butler
curl --proto '=https' --tlsv1.2 --silent --show-error --fail --location https://github.com/lexi-the-cute/butler/releases/download/v15.23.0/butler-linux-amd64.zip > ${{ github.workspace }}/tools/butler-linux-amd64.zip
unzip -o ${{ github.workspace }}/tools/butler-linux-amd64.zip -d ${{ github.workspace }}/tools/butler
# Publish to Itch.io
- name: 🎮 Publish to Itch.io
env:
BUTLER_API_KEY: ${{ secrets.ITCH_IO_API_KEY }}
run: |
export VERSION=`cat ${{ github.workspace }}/Cargo.toml | grep '^version' | head -n1 | cut -d'"' -f2 | tr -d '\n'`
# Upload App
${{ github.workspace }}/tools/butler/butler push ${{ github.workspace }}/artifacts/wasm-32-bit-web-zip/CatgirlEngine-Wasm-32-bit-Web.zip foxgirl-labs/catgirl-engine:wasm-32-bit-web --userversion $VERSION