summaryrefslogtreecommitdiff
path: root/scripts/m6c-package.sh
blob: 89ae6a47bfa8a5c6c7fbb1449ce0f584515cbc76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd)"
PROJECT="$REPO_ROOT/src/LivingVillage.Desktop/LivingVillage.Desktop.fsproj"
STAMP="${M6C_TIMESTAMP:-$(date -u +%Y%m%dT%H%M%SZ)}"
PACKAGE_ROOT="$REPO_ROOT/artifacts/m6c-release/$STAMP"
APP_DIR="$PACKAGE_ROOT/app"
PUBLISH_LOG="$PACKAGE_ROOT/publish.log"

if [[ -e "$PACKAGE_ROOT" ]]; then
    printf 'Refusing to overwrite existing package directory: %s\n' "$PACKAGE_ROOT" >&2
    exit 2
fi

if ! command -v dotnet >/dev/null 2>&1; then
    printf 'dotnet SDK is required to build the Linux package.\n' >&2
    exit 127
fi

mkdir -p "$APP_DIR"

publish_args=(
    "$PROJECT"
    --configuration Release
    --runtime linux-x64
    --output "$APP_DIR"
    --nologo
    -p:DebugType=None
    -p:DebugSymbols=false
)

runtime_mode="self-contained"
self_contained_exit=0
if dotnet publish "${publish_args[@]}" --self-contained true >"$PUBLISH_LOG" 2>&1; then
    :
else
    self_contained_exit=$?
    runtime_mode="framework-dependent"
    rm -rf "$APP_DIR"
    mkdir -p "$APP_DIR"
    if ! dotnet publish "${publish_args[@]}" --self-contained false >>"$PUBLISH_LOG" 2>&1; then
        printf 'Both self-contained and framework-dependent publish failed. See %s\n' "$PUBLISH_LOG" >&2
        exit 1
    fi
fi

for asset in Assets/cjk-glyph-atlas.png Assets/cjk-glyphs.txt; do
    if [[ ! -s "$APP_DIR/$asset" ]]; then
        printf 'Required CJK asset is missing from the Linux package: %s\n' "$APP_DIR/$asset" >&2
        exit 1
    fi
done

mapfile -t cjk_manifest_lines < "$APP_DIR/Assets/cjk-glyphs.txt"
if [[ "${#cjk_manifest_lines[@]}" -ne 188 ]]; then
    printf 'Packaged CJK manifest contains %s lines; expected 188: %s\n' "${#cjk_manifest_lines[@]}" "$APP_DIR/Assets/cjk-glyphs.txt" >&2
    exit 1
fi
for cjk_manifest_line in "${cjk_manifest_lines[@]}"; do
    if [[ ${#cjk_manifest_line} -ne 1 ]]; then
        printf 'Packaged CJK manifest contains a line that is not one character: %s\n' "$APP_DIR/Assets/cjk-glyphs.txt" >&2
        exit 1
    fi
done

cp "$SCRIPT_DIR/m6c-run.sh" "$PACKAGE_ROOT/run-living-village.sh"
chmod +x "$PACKAGE_ROOT/run-living-village.sh"
cp "$REPO_ROOT/README.md" "$PACKAGE_ROOT/README.md"
cp "$REPO_ROOT/docs/release-notes-m6c.md" "$PACKAGE_ROOT/RELEASE-NOTES-M6C.md"
cp "$REPO_ROOT/docs/assets-and-licenses.md" "$PACKAGE_ROOT/ASSETS-AND-LICENSES.md"

source_commit="unknown"
if git -C "$REPO_ROOT" rev-parse HEAD >/dev/null 2>&1; then
    source_commit="$(git -C "$REPO_ROOT" rev-parse HEAD)"
fi

{
    printf 'package=M6c Linux x64\n'
    printf 'created_utc=%s\n' "$STAMP"
    printf 'source_commit=%s\n' "$source_commit"
    printf 'runtime_mode=%s\n' "$runtime_mode"
    printf 'rid=linux-x64\n'
    printf 'entrypoint=run-living-village.sh\n'
    printf 'native_desktopgl_dependencies=system-provided\n'
    if [[ "$runtime_mode" == "framework-dependent" ]]; then
        printf 'self_contained_publish_exit=%s\n' "$self_contained_exit"
        printf 'framework_dependent_requirement=.NET 8 runtime\n'
    fi
} > "$PACKAGE_ROOT/PACKAGE-INFO.txt"

printf 'M6C_PACKAGE_DIR=%s\n' "$PACKAGE_ROOT"
printf 'M6C_RUNTIME_MODE=%s\n' "$runtime_mode"