From 2399df3c20e390a81d2bf5ec001e6411c5a2d581 Mon Sep 17 00:00:00 2001 From: Henry Hale <92443116+henryhale@users.noreply.github.com> Date: Mon, 6 Jan 2025 03:45:33 +0300 Subject: [PATCH] build: zip binaries on release --- .github/workflows/release.yml | 2 +- scripts/build.sh | 6 +++++- scripts/install.sh | 24 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31489a8..49cf227 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: with: generate_release_notes: true files: | - depgraph-* + depgraph-*.zip checksum.sha.txt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/build.sh b/scripts/build.sh index 3a78283..b15666b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -16,9 +16,13 @@ cibuild () { GOARCH="$2" EXT="" + BINARY_NAME="depgraph-$GOOS-$GOARCH$EXT" + if [ "$GOOS" = "windows" ]; then EXT=".exe"; fi - go build -ldflags "-X main.version=$VERSION" -o "depgraph-$GOOS-$GOARCH$EXT" depgraph.go + go build -ldflags "-X main.version=$VERSION" -o "$BINARY_NAME" depgraph.go + + zip -m $BINARY_NAME{.zip,} } if [ "$CI" = "ci" ]; then diff --git a/scripts/install.sh b/scripts/install.sh index 49a3758..27b8f70 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -5,9 +5,14 @@ echo "depgraph: installing executable..." # detect os and architecture echo "depgraph: detecting system architecture..." -OS=$(uname | tr '[:upper:]' '[:lower:]') +OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) +if [ "$OS" != "linux" -1 "$OS" != "darwin"]; then + echo "depgraph: error: unsupported operating system" + exit 1 +fi + if [ "$ARCH" = "x86_64" ]; then ARCH="amd64" elif [ "$ARCH" = "aarch64" ]; then @@ -20,7 +25,7 @@ else fi # download binary -BIN_URL="https://github.com/henryhale/depgraph/releases/latest/download/depgraph-${OS}-${ARCH}" +BIN_URL="https://github.com/henryhale/depgraph/releases/latest/download/depgraph-${OS}-${ARCH}.zip" DEST_DIR="/usr/local/bin" @@ -29,11 +34,18 @@ if [ "$OS" == "linux" ] && [ -n "$PREFIX" ]; then DEST_DIR="$PREFIX/bin" fi -# fetch +BINARY_PATH="$DEST_DIR/depgraph" + +# fetch binary echo "depgraph: downloading binary..." +curl -L "$BIN_URL" -o "$BINARY_PATH.zip" +unzip -o "$BINARY_PATH.zip" + +echo "depgraph: making binary executable..." +chmod +x "$BINARY_PATH" -curl -L "$BIN_URL" -o "$DEST_DIR/depgraph" -chmod +x "$DEST_DIR/depgraph" +# clean up +rm -f "$BINARY_PATH.zip" -echo "depgraph: successfully installed at $DEST_DIR/depgraph" +echo "depgraph: successfully installed at $BINARY_PATH" echo -e "\ntry it now:\n\t$ depgraph -h"