forked from 0x2E/fusion

It's tripped me up a few times that version string generation happens in the Vite build. When someone forks a repo, they don't have the tags, so when they run ./scripts.sh build, the build will fail with a confusing error about git describe. This adjusts the logic so that we determine the fusion version string in scripts.sh and in the release.yml workflow. It also makes it so that if no version string is available, the frontend defaults to 'unknown-version'. This should also make it easier for distributions that want to package fusion, as they previously had to apply workarounds to avoid issues related to deriving the version from git: https://github.com/NixOS/nixpkgs/pull/353616/files#diff-bf194e560f79450a8df2281184c901a7cab6f5da1e25b3b20ec7767e9482ad1e
74 lines
1.2 KiB
Bash
Executable file
74 lines
1.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 ./...
|
|
}
|
|
|
|
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
|
|
npm i
|
|
VITE_FUSION_VERSION="$version" npm run build
|
|
cd $root
|
|
}
|
|
|
|
build_backend() {
|
|
echo "building backend"
|
|
CGO_ENABLED=0 go build \
|
|
-ldflags '-extldflags "-static"' \
|
|
-o ./build/fusion \
|
|
./cmd/server/*
|
|
}
|
|
|
|
build() {
|
|
test_go
|
|
build_frontend
|
|
build_backend
|
|
}
|
|
|
|
dev() {
|
|
go run \
|
|
-ldflags '-extldflags "-static"' \
|
|
./cmd/server
|
|
}
|
|
|
|
case $1 in
|
|
"test")
|
|
test_go
|
|
;;
|
|
"dev")
|
|
dev
|
|
;;
|
|
"build-frontend")
|
|
build_frontend
|
|
;;
|
|
"build-backend")
|
|
build_backend
|
|
;;
|
|
"build")
|
|
build
|
|
;;
|
|
esac
|