Skip to content

fix: replace create-unitypackage action with manual build script #2

fix: replace create-unitypackage action with manual build script

fix: replace create-unitypackage action with manual build script #2

Workflow file for this run

name: Build and Release .unitypackage
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get version from tag
id: version
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
- name: Prepare Unity asset structure
run: |
# The repo root IS the PatcherHub folder content.
# .unitypackage requires files to be under their Unity asset path.
ASSET_PATH="Assets/!Pawlygon/PatcherHub"
mkdir -p "unity-project/${ASSET_PATH}"
# Copy all package files into the Unity asset path structure
# Exclude git/github metadata and workflow files
rsync -av \
--exclude='.git' \
--exclude='.github' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='LICENSE.md' \
--exclude='LICENSE.md.meta' \
./ "unity-project/${ASSET_PATH}/"
- name: Build .unitypackage
run: |
set -e
PROJECT_DIR="unity-project"
ASSET_PATH="Assets/!Pawlygon/PatcherHub"
PKG_NAME="PawlygonPatcherHub-${{ steps.version.outputs.VERSION }}.unitypackage"
STAGING_DIR="package-staging"
mkdir -p "${STAGING_DIR}"
# Find all non-.meta files (actual assets)
cd "${PROJECT_DIR}"
find "${ASSET_PATH}" -type f ! -name '*.meta' | sort > ../asset-files.txt
cd ..
echo "=== Building .unitypackage ==="
while IFS= read -r asset_path; do
meta_path="${asset_path}.meta"
meta_full="${PROJECT_DIR}/${meta_path}"
# Skip if no .meta file exists
if [ ! -f "${meta_full}" ]; then
echo "WARN: No .meta for ${asset_path}, skipping"
continue
fi
# Extract GUID from .meta file
guid=$(grep -oP '^guid:\s*\K[0-9a-f]+' "${meta_full}" || true)
if [ -z "${guid}" ]; then
echo "WARN: No GUID in ${meta_full}, skipping"
continue
fi
# Create entry directory
entry_dir="${STAGING_DIR}/${guid}"
mkdir -p "${entry_dir}"
# pathname - the Unity asset path
echo "${asset_path}" > "${entry_dir}/pathname"
# asset - the actual file content
cp "${PROJECT_DIR}/${asset_path}" "${entry_dir}/asset"
# asset.meta - the .meta file content
cp "${meta_full}" "${entry_dir}/asset.meta"
echo " + ${asset_path} (${guid})"
done < asset-files.txt
# Also include .meta files for folders (they have GUIDs too)
cd "${PROJECT_DIR}"
find "${ASSET_PATH}" -name '*.meta' -type f | sort > ../meta-files.txt
cd ..
while IFS= read -r meta_path; do
# Check if this is a folder .meta (no corresponding file without .meta extension)
asset_path="${meta_path%.meta}"
# If the asset path is a directory, include the folder .meta
if [ -d "${PROJECT_DIR}/${asset_path}" ]; then
meta_full="${PROJECT_DIR}/${meta_path}"
guid=$(grep -oP '^guid:\s*\K[0-9a-f]+' "${meta_full}" || true)
if [ -n "${guid}" ]; then
entry_dir="${STAGING_DIR}/${guid}"
mkdir -p "${entry_dir}"
echo "${asset_path}" > "${entry_dir}/pathname"
cp "${meta_full}" "${entry_dir}/asset.meta"
echo " + [folder] ${asset_path} (${guid})"
fi
fi
done < meta-files.txt
# Create the .unitypackage (gzipped tar)
cd "${STAGING_DIR}"
tar czf "../${PKG_NAME}" ./*
cd ..
FILE_COUNT=$(find "${STAGING_DIR}" -maxdepth 1 -mindepth 1 -type d | wc -l)
FILE_SIZE=$(du -h "${PKG_NAME}" | cut -f1)
echo "=== Package built: ${PKG_NAME} (${FILE_COUNT} entries, ${FILE_SIZE}) ==="
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: PawlygonPatcherHub ${{ github.ref_name }}
draft: false
prerelease: false
generate_release_notes: true
files: PawlygonPatcherHub-${{ steps.version.outputs.VERSION }}.unitypackage