netgescon-day0/scripts/ops/netgescon-release-build.sh

65 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Build release metadata from git for controlled upgrades.
# Usage:
# scripts/ops/netgescon-release-build.sh v1.3.0
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <version-tag>"
echo "Example: $0 v1.3.0"
exit 1
fi
VERSION_TAG="$1"
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
RELEASE_DIR="$REPO_ROOT/releases"
META_DIR="$RELEASE_DIR/$VERSION_TAG"
mkdir -p "$META_DIR"
pushd "$REPO_ROOT" >/dev/null
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "Error: not a git repository: $REPO_ROOT"
exit 1
fi
if ! git rev-parse "$VERSION_TAG" >/dev/null 2>&1; then
echo "Error: git tag/commit '$VERSION_TAG' not found"
exit 1
fi
COMMIT_SHA="$(git rev-parse "$VERSION_TAG")"
BUILD_TIME_UTC="$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
# Save release notes from the previous tag to this tag when possible.
PREV_TAG="$(git tag --sort=-version:refname | grep -vx "$VERSION_TAG" | head -n1 || true)"
if [[ -n "$PREV_TAG" ]]; then
git --no-pager log --pretty=format:'- %h %s (%an)' "$PREV_TAG..$VERSION_TAG" > "$META_DIR/CHANGELOG_FRAGMENT.md"
else
git --no-pager log --pretty=format:'- %h %s (%an)' "$VERSION_TAG" > "$META_DIR/CHANGELOG_FRAGMENT.md"
fi
cat > "$META_DIR/release-manifest.json" <<EOF
{
"version": "$VERSION_TAG",
"commit": "$COMMIT_SHA",
"built_at_utc": "$BUILD_TIME_UTC",
"php_required": "^8.2",
"laravel_migrate_required": true,
"post_deploy_commands": [
"php artisan migrate --force",
"php artisan optimize:clear",
"php artisan optimize"
]
}
EOF
# Checksum for integrity checks in deployment pipeline.
sha256sum "$META_DIR/release-manifest.json" > "$META_DIR/release-manifest.sha256"
popd >/dev/null
echo "Release metadata generated: $META_DIR"