Files
Heimdall/scripts/ci/package.sh
T

69 lines
3.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
sha=$(git rev-parse HEAD)
ref=${BUILD_REF:-}
if [[ "$ref" == refs/tags/* ]]; then
version=${ref#refs/tags/}
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][0-9A-Za-z.-]+)?$ ]] || {
echo 'Release tags must be MAJOR.MINOR.PATCH with an optional prerelease suffix.' >&2; exit 2;
}
else
version="0.0.0-ci.${sha:0:12}"
fi
mkdir -p artifacts/packages
component=Agent
rid=portable
out="artifacts/publish/$component-$rid"
dotnet publish "src/Heimdall.Agent" -c Release --self-contained false \
-p:RestoreLockedMode=true -p:Version="$version" -p:SourceRevisionId="$sha" -p:ContinuousIntegrationBuild=true -o "$out"
mkdir -p "$out/models"
cp models/yolov8n.onnx "$out/models/"
epoch=$(git show -s --format=%ct HEAD)
tar --sort=name --mtime="@$epoch" --owner=0 --group=0 --numeric-owner -cf - -C "$out" . | gzip -1 -n > "artifacts/packages/heimdall-agent-$rid-$version.tar.gz"
python3 - "$version" "$ref" <<'PY'
import os,sys,zipfile
from datetime import datetime,timezone
from pathlib import Path
version, ref = sys.argv[1:]
epoch = int(__import__('subprocess').check_output(['git','show','-s','--format=%ct','HEAD'],text=True))
stamp = datetime.fromtimestamp(max(epoch, 315532800), timezone.utc).timetuple()[:6]
tag = version
source_base = f"https://sources.tordais.cc/arnaud.dartois/Heimdall/raw/tag/{tag}"
files = [Path('install/install-server.sh'), Path('install/install-server.ps1')]
files += sorted(Path('install').glob('*.sh'))
files += sorted(Path('install').glob('*.ps1'))
files += sorted(Path('install').glob('*.py'))
files += sorted(Path('docker').glob('docker-compose*.yml'))
files += sorted(Path('docker/scripts').glob('*')) if Path('docker/scripts').exists() else []
archive = Path(f'artifacts/packages/heimdall-installers-{version}.zip')
with zipfile.ZipFile(archive, 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as bundle:
for path in sorted(set(files)):
if not path.is_file():
continue
data = path.read_bytes()
if path.name in {'install-server.sh', 'install-server.ps1'} or path.name.startswith('docker-compose'):
text = data.decode('utf-8')
text = text.replace('https://sources.tordais.cc/arnaud.dartois/Heimdall/raw/branch/main', source_base)
text = text.replace('eltruncho/heimdall:latest', f'eltruncho/heimdall:{version}')
text = text.replace('PACKAGE_RELEASE_VERSION="unversioned"', f'PACKAGE_RELEASE_VERSION="{version}"')
text = text.replace("PackageReleaseVersion = 'unversioned'", f"PackageReleaseVersion = '{version}'")
data = text.encode('utf-8')
entry = zipfile.ZipInfo(path.as_posix(), stamp)
entry.compress_type = zipfile.ZIP_DEFLATED
entry.external_attr = (0o100755 if path.suffix in {'.sh', '.py'} else 0o100644) << 16
bundle.writestr(entry, data)
PY
python3 - "$sha" "$version" "$ref" <<'PY'
import json,os,sys
from pathlib import Path
Path('artifacts/packages/provenance.json').write_text(json.dumps({
'commit':sys.argv[1], 'version':sys.argv[2], 'ref':sys.argv[3],
'repository':os.environ.get('BUILD_REPOSITORY'), 'run_id':os.environ.get('BUILD_RUN_ID'),
'targets':['Agent native updater'], 'rids':['portable-framework-dependent'],
'runtime':'framework-dependent .NET 10', 'mobile_native':False}, indent=2)+'\n')
PY
(cd artifacts/packages && sha256sum *.tar.gz heimdall-installers-*.zip provenance.json > SHA256SUMS)
installer_bundle="artifacts/packages/heimdall-installers-$version.zip"
(cd artifacts/packages && sha256sum "$(basename "$installer_bundle")" > "$(basename "$installer_bundle").sha256")
printf '%s' "$version" > artifacts/version