Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ echo "Building windows/amd64..."
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath -ldflags "${BUILD_FLAGS}" -o "$BUILD_DIR/${BINARY_NAME}-${VERSION}-windows-amd64.exe" main.go
echo "Building windows/386..."
CGO_ENABLED=0 GOOS=windows GOARCH=386 go build -trimpath -ldflags "${BUILD_FLAGS}" -o "$BUILD_DIR/${BINARY_NAME}-${VERSION}-windows-386.exe" main.go
echo "Building windows/arm64..."
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -trimpath -ldflags "${BUILD_FLAGS}" -o "$BUILD_DIR/${BINARY_NAME}-${VERSION}-windows-arm64.exe" main.go

# Verify all binaries were created
echo "Verifying binaries..."
MISSING_BINARIES=()

for binary in "${BINARY_NAME}-${VERSION}-darwin-amd64" "${BINARY_NAME}-${VERSION}-darwin-arm64" \
"${BINARY_NAME}-${VERSION}-linux-amd64" "${BINARY_NAME}-${VERSION}-linux-arm64" "${BINARY_NAME}-${VERSION}-linux-386" \
"${BINARY_NAME}-${VERSION}-windows-amd64.exe" "${BINARY_NAME}-${VERSION}-windows-386.exe"; do
"${BINARY_NAME}-${VERSION}-windows-amd64.exe" "${BINARY_NAME}-${VERSION}-windows-386.exe" "${BINARY_NAME}-${VERSION}-windows-arm64.exe"; do
if [[ ! -f "$BUILD_DIR/$binary" ]]; then
MISSING_BINARIES+=("$binary")
fi
Expand Down Expand Up @@ -83,12 +85,22 @@ echo "Creating windows archives..."
if command -v zip >/dev/null 2>&1; then
(cd "$BUILD_DIR" && zip "${PACKAGE_NAME}-${VERSION}-windows-amd64.zip" "${BINARY_NAME}-${VERSION}-windows-amd64.exe")
(cd "$BUILD_DIR" && zip "${PACKAGE_NAME}-${VERSION}-windows-386.zip" "${BINARY_NAME}-${VERSION}-windows-386.exe")
(cd "$BUILD_DIR" && zip "${PACKAGE_NAME}-${VERSION}-windows-arm64.zip" "${BINARY_NAME}-${VERSION}-windows-arm64.exe")
else
echo "Warning: zip command not found, skipping Windows archives"
echo "Warning: zip command not found, falling back to tar.gz for Windows"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the zip-missing branch, the script assumes tar is available but doesn’t verify it. Since the script also doesn’t use set -e, a missing tar would result in failed archive creation while the script still reaches the final “Build complete” message. Consider adding a command -v tar check (and exiting non-zero if unavailable) before attempting the Windows tar.gz fallback so failures are explicit.

Suggested change
echo "Warning: zip command not found, falling back to tar.gz for Windows"
echo "Warning: zip command not found, falling back to tar.gz for Windows"
if ! command -v tar >/dev/null 2>&1; then
echo "Error: tar command not found, cannot create Windows fallback archives" >&2
exit 1
fi

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The fallback branch uses tar without verifying it exists via command -v, while zip gets that check. In practice tar is a POSIX standard utility and will always be present on systems that can run this script, so this is a consistency nit rather than a real risk.

tar czf "$BUILD_DIR/${PACKAGE_NAME}-${VERSION}-windows-amd64.tar.gz" -C "$BUILD_DIR" "${BINARY_NAME}-${VERSION}-windows-amd64.exe"
tar czf "$BUILD_DIR/${PACKAGE_NAME}-${VERSION}-windows-386.tar.gz" -C "$BUILD_DIR" "${BINARY_NAME}-${VERSION}-windows-386.exe"
tar czf "$BUILD_DIR/${PACKAGE_NAME}-${VERSION}-windows-arm64.tar.gz" -C "$BUILD_DIR" "${BINARY_NAME}-${VERSION}-windows-arm64.exe"
fi

# Generate checksums
echo "Generating checksums..."
(cd "$BUILD_DIR" && shasum -a 256 * > "${PACKAGE_NAME}-${VERSION}-checksums.txt")
if command -v shasum >/dev/null 2>&1; then
(cd "$BUILD_DIR" && shasum -a 256 * > "${PACKAGE_NAME}-${VERSION}-checksums.txt")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Fix: The * glob checksums everything in dist/ — raw binaries (which aren't released, only archives are uploaded) and potentially a stale checksums file from a previous run. Should target only release archives:

shasum -a 256 *.tar.gz *.zip > "${PACKAGE_NAME}-${VERSION}-checksums.txt"

(Same applies to the sha256sum branch below.)

Note: this is a pre-existing issue on main, but since this code block is already being modified, it's the right time to fix it.

elif command -v sha256sum >/dev/null 2>&1; then
(cd "$BUILD_DIR" && sha256sum * > "${PACKAGE_NAME}-${VERSION}-checksums.txt")
Comment on lines +99 to +101
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checksum generation uses *, which will include the raw binaries in dist/ (and possibly an old *-checksums.txt from a previous run). However, the release workflow only uploads archives (dist/*.tar.gz, dist/*.zip), so the generated checksums won’t correspond 1:1 with the released artifacts. Consider generating checksums from an explicit artifact glob/list (e.g., only *.tar.gz and *.zip, excluding the checksum file itself) to keep checksums accurate and reproducible across reruns.

Suggested change
(cd "$BUILD_DIR" && shasum -a 256 * > "${PACKAGE_NAME}-${VERSION}-checksums.txt")
elif command -v sha256sum >/dev/null 2>&1; then
(cd "$BUILD_DIR" && sha256sum * > "${PACKAGE_NAME}-${VERSION}-checksums.txt")
(
cd "$BUILD_DIR" || exit 1
artifacts=()
for pattern in "${PACKAGE_NAME}-${VERSION}-"*.tar.gz "${PACKAGE_NAME}-${VERSION}-"*.zip; do
[ -e "$pattern" ] || continue
artifacts+=("$pattern")
done
if [ ${#artifacts[@]} -gt 0 ]; then
shasum -a 256 "${artifacts[@]}" > "${PACKAGE_NAME}-${VERSION}-checksums.txt"
else
echo "Warning: No release archives found, skipping checksums"
fi
)
elif command -v sha256sum >/dev/null 2>&1; then
(
cd "$BUILD_DIR" || exit 1
artifacts=()
for pattern in "${PACKAGE_NAME}-${VERSION}-"*.tar.gz "${PACKAGE_NAME}-${VERSION}-"*.zip; do
[ -e "$pattern" ] || continue
artifacts+=("$pattern")
done
if [ ${#artifacts[@]} -gt 0 ]; then
sha256sum "${artifacts[@]}" > "${PACKAGE_NAME}-${VERSION}-checksums.txt"
else
echo "Warning: No release archives found, skipping checksums"
fi
)

Copilot uses AI. Check for mistakes.
else
echo "Warning: Neither shasum nor sha256sum found, skipping checksums"
fi

echo "Build complete! Artifacts are in the $BUILD_DIR directory"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must Fix: Missing newline at end of file. The PR removes the trailing newline — \ No newline at end of file appears in the diff. POSIX requires a trailing newline for well-formed text files, and many tools will warn about this.