Files
Sudo-Ivan 2554311338
Some checks failed
ci / build-frontend (push) Successful in 52s
ci / test (push) Successful in 1m42s
ci / build-backend (amd64, linux) (push) Successful in 1m11s
ci / build-backend (arm64, linux) (push) Successful in 1m9s
release / build-assets (push) Successful in 37s
release / release (push) Failing after 20s
Refactor platform pair extraction and manifest list creation in scripts.sh
- Updated the platform pair extraction to use a variable for better readability.
- Simplified the manifest list creation by storing tags and digests in variables before passing them to the docker command, enhancing clarity and maintainability.
2025-12-13 13:11:50 -06:00

195 lines
4.2 KiB
Bash
Executable File

#!/bin/sh
# Exit on first failure.
set -e
test_go() {
echo "testing"
# make some files for embed
mkdir -p ./frontend/build
touch ./frontend/build/index.html
go test ./...
}
extract_version_from_tag() {
tag="$1"
if [ -z "$tag" ]; then
echo "Error: Tag is required"
exit 1
fi
version="$tag"
version=${version#v}
echo "$version"
}
build_frontend() {
echo "building frontend"
mkdir -p ./build
root=$(pwd)
if [ -n "$FUSION_VERSION" ]; then
version="$FUSION_VERSION"
else
# Try to get version relative to the last git tag.
if git describe --tags --abbrev=0 >/dev/null 2>&1; then
version=$(git describe --tags --abbrev=0)
else
# If repo has no tags, just use the latest commit hash.
version=$(git rev-parse --short HEAD)
fi
fi
echo "Using fusion version string: ${version}"
cd ./frontend
# Use frozen lockfile for CI builds, skip if lockfile doesn't exist
if [ -f "pnpm-lock.yaml" ] && [ "${CI:-}" = "true" ]; then
pnpm i --frozen-lockfile
else
pnpm i
fi
VITE_FUSION_VERSION="$version" pnpm run build
cd $root
}
build_backend() {
target_os=${1:-$(go env GOOS)}
target_arch=${2:-$(go env GOARCH)}
echo "building backend for OS: ${target_os}, Arch: ${target_arch}"
CGO_ENABLED=0 GOOS=${target_os} GOARCH=${target_arch} go build \
-ldflags '-extldflags "-static"' \
-o ./build/fusion \
./cmd/server/*
}
build() {
test_go
# Check if frontend is already built (for CI optimization)
if [ ! -f "./frontend/build/index.html" ] || [ "${FORCE_REBUILD:-}" = "true" ]; then
build_frontend
else
echo "Frontend already built, skipping..."
fi
build_backend
}
prepare_gitea_config() {
gitea_url="$1"
if [ -z "$gitea_url" ]; then
echo "Error: Gitea URL is required"
exit 1
fi
echo "" >> .goreleaser.yaml
echo "gitea_urls:" >> .goreleaser.yaml
echo " api: ${gitea_url}/api/v1" >> .goreleaser.yaml
echo " download: ${gitea_url}" >> .goreleaser.yaml
}
prepare_registry_vars() {
repo="$1"
server_url="$2"
if [ -z "$repo" ] || [ -z "$server_url" ]; then
echo "Error: Repository and server URL are required"
exit 1
fi
repo=$(echo "$repo" | tr '[:upper:]' '[:lower:]')
reg="$server_url"
reg=${reg#https://}
reg=${reg#http://}
echo "REPOSITORY=$repo" >> $GITHUB_ENV
echo "REGISTRY_HOST=$reg" >> $GITHUB_ENV
}
extract_platform_pair() {
platform="$1"
if [ -z "$platform" ]; then
echo "Error: Platform is required"
exit 1
fi
platform_pair=$(echo "$platform" | tr '/' '-')
echo "PLATFORM_PAIR=${platform_pair}" >> $GITHUB_ENV
}
export_digest() {
digest="$1"
if [ -z "$digest" ]; then
echo "Error: Digest is required"
exit 1
fi
mkdir -p /tmp/digests
touch "/tmp/digests/${digest#sha256:}"
}
create_manifest_list() {
registry_host="$1"
repository="$2"
metadata_json="$3"
if [ -z "$registry_host" ] || [ -z "$repository" ] || [ -z "$metadata_json" ]; then
echo "Error: Registry host, repository, and metadata JSON are required"
exit 1
fi
tags=$(echo "$metadata_json" | jq -cr '.tags | map("-t " + .) | join(" ")')
digests=$(printf "${registry_host}/${repository}@sha256:%s " *)
docker buildx imagetools create $tags $digests
}
inspect_image() {
registry_host="$1"
repository="$2"
version="$3"
if [ -z "$registry_host" ] || [ -z "$repository" ] || [ -z "$version" ]; then
echo "Error: Registry host, repository, and version are required"
exit 1
fi
docker buildx imagetools inspect "${registry_host}/${repository}:${version}"
}
dev() {
go run \
-ldflags '-extldflags "-static"' \
./cmd/server
}
case $1 in
"test")
test_go
;;
"dev")
dev
;;
"build-frontend")
build_frontend
;;
"build-backend")
# Pass along additional arguments ($2, $3) to the function
build_backend "$2" "$3"
;;
"build")
build
;;
"prepare-gitea-config")
prepare_gitea_config "$2"
;;
"prepare-registry-vars")
prepare_registry_vars "$2" "$3"
;;
"extract-platform-pair")
extract_platform_pair "$2"
;;
"export-digest")
export_digest "$2"
;;
"create-manifest-list")
create_manifest_list "$2" "$3" "$4"
;;
"inspect-image")
inspect_image "$2" "$3" "$4"
;;
"extract-version-from-tag")
extract_version_from_tag "$2"
;;
esac