Skip to content

Build

Build #26

Workflow file for this run

name: Build
on:
workflow_dispatch:
inputs:
version_type:
description: 'Type of version bump (patch, minor, major, or specific version)'
required: true
default: 'patch'
type: choice
options:
- 'patch'
- 'minor'
- 'major'
- 'custom' # Allows entering a specific version like v1.2.3
custom_version:
description: 'Enter custom version (e.g., v1.2.3) if "version_type" is "custom"'
required: false
type: string
version_info:
description: 'Info for Changelog'
required: false
type: string
default: ''
jobs:
create-version:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.get_version.outputs.new_version }} # Expose the new version as a job output
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to find the latest tag
- name: Get latest version and increment
id: get_version # Give this step an ID to reference its outputs
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag found: $LATEST_TAG"
MAJOR=0
MINOR=0
PATCH=0
# Extract major, minor, patch from latest tag
if [[ "$LATEST_TAG" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
fi
NEW_VERSION=""
VERSION_TYPE="${{ github.event.inputs.version_type }}"
if [ "$VERSION_TYPE" == "custom" ]; then
CUSTOM_VER="${{ github.event.inputs.custom_version }}"
if [[ "$CUSTOM_VER" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
NEW_VERSION="$CUSTOM_VER"
echo "Using custom version: $NEW_VERSION"
else
echo "Error: Custom version '$CUSTOM_VER' is not in 'X.Y.Z' format."
exit 1
fi
elif [ "$VERSION_TYPE" == "patch" ]; then
NEW_PATCH=$((PATCH + 1))
NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}"
elif [ "$VERSION_TYPE" == "minor" ]; then
NEW_MINOR=$((MINOR + 1))
NEW_VERSION="${MAJOR}.${NEW_MINOR}.0" # Reset patch to 0 for minor bumps
elif [ "$VERSION_TYPE" == "major" ]; then
NEW_MAJOR=$((MAJOR + 1))
NEW_VERSION="${NEW_MAJOR}.0.0" # Reset minor and patch to 0 for major bumps
else
echo "Error: Invalid version_type '$VERSION_TYPE'."
exit 1
fi
echo "Calculated new version: $NEW_VERSION"
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
build-web:
needs: create-version
environment: prod
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
- name: Clean Docker cache
run: |
docker system prune -a -f --volumes
df -h # Optional: Check available storage
# Build
- name: Build project
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: WebGL
versioning: Custom
version: ${{ needs.create-version.outputs.new_version }} # Use the new version from the previous job
# Output
- uses: actions/upload-artifact@v4
with:
name: Web_Build
path: build/WebGL
# Deploy auf GitHub Pages (Ziel: radulf321.github.io)
- name: Deploy to GitHub Pages (User Page)
uses: peaceiris/actions-gh-pages@v4
with:
# Dieses Token muss Schreibrechte für das ZIEL-Repository haben (radulf321.github.io)
personal_token: ${{ secrets.ACCESS_TOKEN }}
# Das ZIEL-Repository, auf das gepusht werden soll
external_repository: radulf321/radulf321.github.io
# Der Branch im ZIEL-Repository, auf den gepusht werden soll (normalerweise 'main' oder 'master' für User Pages)
publish_branch: main
# Der Ordner, der den Build-Output enthält (aus deinem Unity-Projekt-Repo)
publish_dir: ./build/WebGL/WebGL # game-ci/unity-builder legt WebGL in 'build/WebGL/WebGL' ab
build-android:
needs: create-version
environment: prod
runs-on: ubuntu-22.04
timeout-minutes: 30
steps:
# Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
- name: Clean Docker cache
run: |
docker system prune -a -f --volumes
- name: Free Disk Space
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
android: false
dotnet: true
haskell: true
large-packages: true
swap-storage: true
# Build
- name: Build project
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
ANDROID_KEYSTORE_PASS: ${{ secrets.ANDROID_KEYSTORE_PASS }}
ANDROID_KEYALIAS_NAME: ${{ secrets.ANDROID_KEYALIAS_NAME }}
ANDROID_KEYALIAS_PASS: ${{ secrets.ANDROID_KEYALIAS_PASS }}
with:
androidVersionCode: 3
targetPlatform: Android
versioning: Custom
version: ${{ needs.create-version.outputs.new_version }} # Use the new version from the previous job
# Output
- uses: actions/upload-artifact@v4
with:
name: Android_Build
path: build/Android/Android.apk
create-github-release:
needs: [create-version, build-web, build-android] # Depends on all preceding jobs
runs-on: ubuntu-latest
permissions:
contents: write # Necessary for creating a release and its tag
steps:
- name: Checkout code (for release context, optional but good practice)
uses: actions/checkout@v4
# We don't need fetch-depth: 0 here unless generating changelog or similar
# Fetching the specific commit might be good for release context
- name: Download Android Build Artifact
uses: actions/download-artifact@v4
with:
name: Android_Build # Must match the name used in build-android's upload-artifact step
path: ./android-build/ # Local directory where the artifact will be downloaded
- name: Wait for file handle to release
run: sleep 5s
# Debugging step: Check contents of the directory after download
- name: Debug - List Downloaded Contents
run: |
echo "Contents of ./android-build/ after download:"
ls -la ./android-build/
- name: Get Version for Release
run: |
RELEASE_VERSION="${{ needs.create-version.outputs.new_version }}"
echo "Release version: $RELEASE_VERSION"
echo "RELEASE_VERSION=$RELEASE_VERSION" >> "$GITHUB_ENV" # Make available as env var
- name: Create Git Tag (for the release)
run: |
TAG_NAME="v${{ env.RELEASE_VERSION }}"
echo "Creating Git tag locally: $TAG_NAME"
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag "$TAG_NAME" -m "Release $TAG_NAME"
git push origin "$TAG_NAME"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use the automatically provided GitHub token
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.RELEASE_VERSION }} # Use the same tag name as created above
name: Release ${{ env.RELEASE_VERSION }}
body: |
## Release Notes - v${{ env.RELEASE_VERSION }}
${{ github.event.inputs.version_info }}
**Web Build:** [Play Here](https://radulf321.github.io)
**Android Download:** [Download APK Here](https://github.com/${{ github.repository }}/releases/download/${{ env.RELEASE_VERSION }}/Android.apk)
draft: false
prerelease: false
files: ./android-build/Android.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Automatically provided token for release creation