Files
av3-animation-as-crab/vpm/package.sh
T
doloro a1b81b8eb7
ci / build (push) Canceled after 0s
flake: emit Unity bundle zip; add Gitea Actions CI/release; publish VPM index
- flake.nix: install the libaac cdylib alongside aac-dump and zip it with
  the C# Unity packages as the default package
- .gitea/workflows: build+package on push/PR, publish release on v* tags
- vpm: commit the repository index and packaging script, with VPM_INDEX and
  VPM_INDEX_URL overrides for generating a local listing
2026-09-19 16:07:43 +01:00

82 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds the VPM release zip for dev.doloro.animator-as-crab and (re)generates vpm/index.json,
# the repository listing that VCC and ALCOM read.
#
# Needs `zip` and `jq`: run it inside `nix develop`.
#
# Environment overrides (all optional):
# VPM_HOST default https://git.scug.io
# VPM_PROJECT default doloro/av3-animation-as-crab
# VPM_RELEASE_BASE default <host>/<project>/-/releases/download/v<version>
# VPM_INDEX default <root>/vpm/index.json
# VPM_INDEX_URL default <host>/<project>/-/raw/main/vpm/index.json
# VPM_REPO_NAME default "Doloro VPM Packages"
# VPM_REPO_ID default dev.doloro.vpm
set -euo pipefail
root=$(cd "$(dirname "$0")/.." && pwd)
pkg="$root/csharp/dev.doloro.animator-as-crab"
vpm="$root/vpm"
host=${VPM_HOST:-https://git.scug.io}
project=${VPM_PROJECT:-doloro/av3-animation-as-crab}
repo_name=${VPM_REPO_NAME:-Doloro VPM Packages}
repo_id=${VPM_REPO_ID:-dev.doloro.vpm}
index_url=${VPM_INDEX_URL:-$host/$project/-/raw/main/vpm/index.json}
release_base=${VPM_RELEASE_BASE:-}
id=$(jq -r .name "$pkg/package.json")
version=$(jq -r .version "$pkg/package.json")
zip_name="$id-$version.zip"
: "${release_base:=$host/$project/-/releases/download/v$version}"
zip_url="$release_base/$zip_name"
stage=$(mktemp -d)
trap 'rm -rf "$stage"' EXIT
cp -r "$pkg/." "$stage/"
rm -f "$stage/.gitignore"
# The native library is not optional: DllImport("libaac") fails without it, and a VPM package is
# unpacked into Packages/, so it cannot rely on the user's Assets/Plugins. Ship it in the package.
# Only Linux is built here; drop a libaac.dll / libaac.dylib into vpm/native/ for other hosts.
shopt -s nullglob
native=("$vpm"/native/* "$root"/result/lib/*)
shopt -u nullglob
if [ ${#native[@]} -eq 0 ]; then
echo "warning: no native library found; the package will not load libaac" >&2
fi
for lib in "${native[@]}"; do
cp "$lib" "$stage/V1/Editor/"
echo "bundled $(basename "$lib")"
done
mkdir -p "$vpm/dist"
rm -f "$vpm/dist/$zip_name"
(cd "$stage" && zip -r -X -q "$vpm/dist/$zip_name" .)
sha=$(sha256sum "$vpm/dist/$zip_name" | cut -d' ' -f1)
entry=$(jq -n \
--arg id "$id" --arg version "$version" --arg zip_url "$zip_url" --arg sha "$sha" \
--slurpfile manifest "$pkg/package.json" \
'{name: $id, displayName: $manifest[0].displayName, version: $version, unity: $manifest[0].unity,
description: $manifest[0].description, url: $zip_url, zipSHA256: $sha,
dependencies: ($manifest[0].dependencies // {}), vpmDependencies: {}, author: $manifest[0].author}')
index=${VPM_INDEX:-$vpm/index.json}
old='{}'
[ -f "$index" ] && old=$(cat "$index")
echo "$old" | jq \
--arg repo_name "$repo_name" --arg repo_id "$repo_id" --arg index_url "$index_url" \
--arg id "$id" --arg version "$version" --argjson entry "$entry" \
'.name = $repo_name | .id = $repo_id | .url = $index_url | .author = $entry.author
| .packages = (.packages // {})
| .packages[$id] = (.packages[$id] // {versions: {}})
| .packages[$id].versions[$version] = $entry' > "$index"
jq -e . "$index" > /dev/null
echo "wrote $vpm/dist/$zip_name"
echo "sha256 $sha"
echo "updated $index -> $zip_url"