Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 269 additions & 0 deletions .github/workflows/publish-unity-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
name: Unity Build, Release, and Publish Package

on:
release:
types: [published]
repository_dispatch:
types: [trigger_docker_publish]
workflow_dispatch:
inputs:
version:
description: 'Version (for manual dispatch)'
required: false
default: ''
push:
tags:
- 'v*.*.*'

env:
DOCKER_NAMESPACE: chrisjcc
DOCKER_REPOSITORY: replicantdrivesim


jobs:
build-plugin:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install pybind11
run: pip install pybind11

- name: Compile C++ code
working-directory: Assets/Plugins/TrafficSimulation
run: |
# Create build directory and compile
mkdir build && cd build
cmake ..
#cmake .. -Dpybind11_DIR=$(python -m pybind11 --cmakedir)
make

- name: Upload Plugin Artifact
uses: actions/upload-artifact@v4
with:
name: TrafficSimulation-Plugin
path: Assets/Plugins/TrafficSimulation/build
include-hidden-files: true


build-unity:
needs: build-plugin
runs-on: macos-latest
outputs:
VERSION: ${{ steps.get_version.outputs.VERSION }}
steps:
- name: Checkout Git repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # This is important to fetch all history for all tags and branches
lfs: true

- name: Cache Library files from previous builds
uses: actions/cache@v3
with:
path: Library
key: Library-UnityDriveSimulation-StandaloneOSX
restore-keys: |
Library-UnityDriveSimulation-
Library-

- name: Determine version
id: get_version
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
elif [[ ${{ github.event_name }} == 'workflow_dispatch' ]]; then
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=$(date +"%Y%m%d-%H%M%S") # Fallback to timestamp if no version is provided
fi
elif [[ ${{ github.ref }} == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ ${{ github.event_name }} == 'pull_request' ]]; then
VERSION="pr-${{ github.event.pull_request.number }}"
else
VERSION=$(git rev-parse --short HEAD) # Use short commit hash for other cases
fi
echo "Using version: $VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Get short SHA
id: slug
run: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT

- name: Download Plugin Artifact
uses: actions/download-artifact@v4
with:
name: TrafficSimulation-Plugin
path: Assets/Plugins/TrafficSimulation/build

- name: Build Unity Project for macOS
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
# Build a macOS standalone (Intel 64-bit).
targetPlatform: StandaloneOSX
# Use "auto" (default) to get from your ProjectSettings/ProjectVersion.txt
unityVersion: auto
versioning: Semantic
# Enables caching the Unity Hub and Editor installation for MacOS runners (default: false).
# This can significantly reduce project build times if you have enough available cache on Github Actions.
cacheUnityInstallationOnMac: true
buildName: libReplicantDriveSim
#buildName: libReplicantDriveSim-${{ steps.slug.outputs.sha8 }}
buildsPath: Builds
# Format: EditorNamespace.BuilderClassName.StaticBuildMethod
buildMethod: UnityBuilderAction.BuildScript.PerformMacOSBuild
projectPath: .
customParameters: -buildTarget OSXArm64 -logFile "./Logs/unity_build.log" -development -debugCode
androidExportType: "none"
androidSymbolType: "none"

#- name: Create metadata file
# run: |
# echo "Version: ${{ steps.get_version.outputs.VERSION }}" > metadata.txt
# echo "Commit SHA: ${{ github.sha }}" >> metadata.txt
# echo "Short SHA: ${{ steps.slug.outputs.sha8 }}" >> metadata.txt

- name: Package Builds with metadata
run: |
zip -r macos-unity-build-${{ steps.get_version.outputs.VERSION }}.zip ./Builds
zip -r plugin-build-${{ steps.get_version.outputs.VERSION }}.zip ./Assets/Plugins/TrafficSimulation/build
#zip -r macos-unity-build-${{ steps.get_version.outputs.VERSION }}.zip ./Builds metadata.txt
#zip -r plugin-build-${{ steps.get_version.outputs.VERSION }}.zip ./Assets/Plugins/TrafficSimulation/build metadata.txt
#zip -r macos-unity-build-${{ steps.get_version.outputs.VERSION }}-${{ steps.slug.outputs.sha8 }}.zip ./Builds metadata.txt
#zip -r plugin-build-${{ steps.get_version.outputs.VERSION }}-${{ steps.slug.outputs.sha8 }}.zip ./Assets/Plugins/TrafficSimulation/build metadata.txt

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.get_version.outputs.VERSION }}
release_name: Release v${{ steps.get_version.outputs.VERSION }}
body: |
Release v${{ steps.get_version.outputs.VERSION }}
Commit: ${{ github.sha }}
Short SHA: ${{ steps.slug.outputs.sha8 }}
${{ steps.tag.outputs.message }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./macos-unity-build-${{ steps.get_version.outputs.VERSION }}.zip
asset_name: macos-unity-build-${{ steps.get_version.outputs.VERSION }}.zip
asset_content_type: application/zip

- name: Upload Plugin Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./plugin-build-${{ steps.get_version.outputs.VERSION }}.zip
asset_name: plugin-build-${{ steps.get_version.outputs.VERSION }}.zip
asset_content_type: application/zip

- name: Upload Unity Build Artifact
uses: actions/upload-artifact@v4
with:
name: macOS-Unity-Build-${{ steps.get_version.outputs.VERSION }}
# Upload the entire Builds and Logs directories
path: |
./Builds
./Logs


build-and-push-image:
needs: [build-unity]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download Unity Build Artifact
uses: actions/download-artifact@v4
with:
name: macOS-Unity-Build-${{ needs.build-unity.outputs.VERSION }}
path: ./Builds

- name: Set up Docker
uses: docker-practice/actions-setup-docker@master

#- name: Install and start Docker
# run: |
# brew install docker
# brew install colima
# #colima start
# sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock

- name: Verify Docker installation
run: |
docker --version
docker info

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Lowercase the repo name
run: |
echo "REPO_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_REPOSITORY }}
tags: |
type=raw,value=${{ needs.build-unity.outputs.VERSION }}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image to the GitHub Container and DockerHub Registry
id: docker_build
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: true
with:
context: .
push: true
# Support single multi-architecture Docker image
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
#tags: |
# ghcr.io/${{ env.REPO_LOWER }}:${{ needs.build-unity.outputs.VERSION }}
# ghcr.io/${{ env.REPO_LOWER }}:latest
# ${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_REPOSITORY }}:${{ steps.get_version.outputs.VERSION }}
# ${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_REPOSITORY }}:latest
labels: ${{ steps.meta.outputs.labels }}
no-cache: true # Set to true disable caching
Loading