ship: v0.1 Foundation milestone complete (#1)
This commit was merged in pull request #1.
This commit is contained in:
Executable
+137
@@ -0,0 +1,137 @@
|
||||
#!/bin/bash
|
||||
# release.sh - Build a release artifact and create a Gitea release via `tea`
|
||||
#
|
||||
# Usage:
|
||||
# scripts/release.sh [VERSION]
|
||||
#
|
||||
# If VERSION is not given, it is read from the latest git tag (e.g. v0.1.5).
|
||||
# Falls back to "dev" if no tag is found.
|
||||
#
|
||||
# Steps:
|
||||
# 1. Validate toolchain (git, go, tar, tea)
|
||||
# 2. Determine version
|
||||
# 3. Build orca binary with version injection via -ldflags
|
||||
# 4. Package as tarball: orca-${VERSION}-${OS}-${ARCH}.tar.gz
|
||||
# 5. Generate release notes from `---ci---` blocks since last tag
|
||||
# 6. Invoke `tea releases create` to publish to Gitea
|
||||
#
|
||||
# Requires:
|
||||
# - GITEA_TOKEN environment variable
|
||||
# - `tea` CLI on PATH (https://gitea.com/gitea/tea)
|
||||
#
|
||||
# Idempotent: tea releases create will fail if the release already exists;
|
||||
# the script surfaces that error rather than silently swallowing it.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
cd "$REPO_ROOT"
|
||||
|
||||
# Source .env for GITEA_TOKEN if present
|
||||
for env_file in "$REPO_ROOT/.env" "$PWD/.env" "./.env"; do
|
||||
if [ -f "$env_file" ]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
. "$env_file"
|
||||
set +a
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# --- helpers --------------------------------------------------------------
|
||||
|
||||
err() { echo "release: error: $*" >&2; exit 1; }
|
||||
info() { echo "release: $*"; }
|
||||
|
||||
require_tool() {
|
||||
command -v "$1" >/dev/null 2>&1 || err "required tool not found: $1"
|
||||
}
|
||||
|
||||
# --- preflight ------------------------------------------------------------
|
||||
|
||||
require_tool git
|
||||
require_tool go
|
||||
require_tool tar
|
||||
|
||||
if [ -z "${GITEA_TOKEN:-}" ]; then
|
||||
err "GITEA_TOKEN is not set. Export it or put it in .env"
|
||||
fi
|
||||
|
||||
if ! command -v tea >/dev/null 2>&1; then
|
||||
err "tea CLI not found on PATH. Install from https://gitea.com/gitea/tea"
|
||||
fi
|
||||
|
||||
# --- version detection ----------------------------------------------------
|
||||
|
||||
VERSION="${1:-}"
|
||||
if [ -z "$VERSION" ]; then
|
||||
VERSION="$(git describe --tags --abbrev=0 2>/dev/null || echo dev)"
|
||||
fi
|
||||
# Strip leading 'v' for the tarball name (we keep it in the release tag itself)
|
||||
VERSION_NUMBER="${VERSION#v}"
|
||||
|
||||
info "version: $VERSION"
|
||||
info "building..."
|
||||
|
||||
# --- build with version injection ----------------------------------------
|
||||
|
||||
GIT_COMMIT="$(git rev-parse --short HEAD)"
|
||||
BUILD_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
||||
LDFLAGS="-s -w -X git.cloudinit.dev/coreci/orca/internal/cli.version=$VERSION -X git.cloudinit.dev/coreci/orca/internal/cli.gitCommit=$GIT_COMMIT -X git.cloudinit.dev/coreci/orca/internal/cli.buildTime=$BUILD_TIME"
|
||||
|
||||
mkdir -p bin
|
||||
go build -trimpath -ldflags="$LDFLAGS" -o bin/orca ./cmd/orca
|
||||
info "built: bin/orca"
|
||||
|
||||
# --- tarball --------------------------------------------------------------
|
||||
|
||||
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
|
||||
ARCH="$(uname -m)"
|
||||
case "$ARCH" in
|
||||
x86_64) ARCH=amd64 ;;
|
||||
aarch64) ARCH=arm64 ;;
|
||||
armv7l) ARCH=armv7 ;;
|
||||
esac
|
||||
|
||||
TARBALL="orca-${VERSION}-${OS}-${ARCH}.tar.gz"
|
||||
tar -czf "$TARBALL" -C bin orca
|
||||
info "packaged: $TARBALL ($(du -h "$TARBALL" | cut -f1))"
|
||||
|
||||
# --- release notes from ---ci--- blocks ----------------------------------
|
||||
|
||||
NOTES_FILE="$(mktemp)"
|
||||
trap 'rm -f "$NOTES_FILE"' EXIT
|
||||
|
||||
{
|
||||
echo "# Release $VERSION"
|
||||
echo ""
|
||||
echo "_Built: $BUILD_TIME from $GIT_COMMIT_"
|
||||
echo ""
|
||||
|
||||
PREV_TAG="$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")"
|
||||
if [ -n "$PREV_TAG" ]; then
|
||||
RANGE="$PREV_TAG..HEAD"
|
||||
else
|
||||
RANGE="HEAD"
|
||||
fi
|
||||
|
||||
echo "## Changes since $PREV_TAG"
|
||||
echo ""
|
||||
# Extract messages of ---ci--- tagged commits in the range
|
||||
git log --pretty=format:'- %s' "$RANGE" 2>/dev/null | head -100 || true
|
||||
echo ""
|
||||
} > "$NOTES_FILE"
|
||||
|
||||
info "release notes: $NOTES_FILE"
|
||||
cat "$NOTES_FILE"
|
||||
|
||||
# --- publish to gitea -----------------------------------------------------
|
||||
|
||||
info "creating gitea release..."
|
||||
tea releases create "$VERSION" \
|
||||
--title "Orca $VERSION" \
|
||||
--note-file "$NOTES_FILE" \
|
||||
--asset "$TARBALL"
|
||||
|
||||
info "✓ release $VERSION published"
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
# trigger_coreci.sh - Trigger CoreCI pipeline for the pushed branch
|
||||
# Invoked by .githooks/pre-push
|
||||
# Gracefully degrades if CoreCI API is unreachable (Gitea webhook is secondary path).
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
# Source .env if present (provides GITEA_TOKEN)
|
||||
# Look in repo root, then cwd, then script dir
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
for env_file in "$REPO_ROOT/.env" "$PWD/.env" "./.env"; do
|
||||
if [ -f "$env_file" ]; then
|
||||
set -a
|
||||
# shellcheck disable=SC1090
|
||||
. "$env_file"
|
||||
set +a
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
CORECI_URL="${CORECI_URL:-https://git.cloudinit.dev/coreci/coreci}"
|
||||
GITEA_TOKEN="${GITEA_TOKEN:-}"
|
||||
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
echo " (skip: GITEA_TOKEN not set)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while read local_ref local_sha remote_ref remote_sha; do
|
||||
branch="${remote_ref#refs/heads/}"
|
||||
if [ -z "$branch" ] || [ "$branch" = "HEAD" ]; then
|
||||
continue
|
||||
fi
|
||||
echo "→ Triggering CoreCI for branch: $branch (${local_sha:0:7})"
|
||||
payload=$(printf '{"repo":"coreci/orca","branch":"%s","ref":"%s"}' "$branch" "$local_sha")
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsS -X POST "${CORECI_URL}/api/pipeline/run" \
|
||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$payload" >/dev/null 2>&1 \
|
||||
&& echo " ✓ CoreCI triggered" \
|
||||
|| echo " (CoreCI trigger failed; pipeline may run via webhook)"
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user