Skip to content

Commit

Permalink
Feature/pipeline releases (#11)
Browse files Browse the repository at this point in the history
* Introduced releases via pipeline
  * This is based on a new version of simple-go-pipeline
* `setup.sh` script which finds OS -> arch and finds release -> installs
* Updated `clai v/version` command to also print version set with ld flags
  • Loading branch information
baalimago authored Jun 4, 2024
1 parent f0d3866 commit efb9a2a
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 3 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Simple Go Pipeline - relesae

on:
push:
tags:
- "v*.*.*"

jobs:
call-workflow:
uses: baalimago/simple-go-pipeline/.github/workflows/release.yml@v0.2.5
with:
go-version: '1.22'
project-name: clai
branch: main
version-var: "github.com/baalimago/clai/internal.BUILD_VERSION"

4 changes: 2 additions & 2 deletions .github/workflows/go.yml → .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Simple Go Pipeline
name: Simple Go Pipeline - validate

on:
push:
Expand All @@ -8,6 +8,6 @@ on:

jobs:
call-workflow:
uses: baalimago/simple-go-pipeline/.github/workflows/go.yml@main
uses: baalimago/simple-go-pipeline/.github/workflows/validate.yml@main
with:
go-version: '1.22'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Most text and photo based models within the respective vendors are supported, se
go install github.com/baalimago/clai@latest
```

You may also use the setup script:
```bash
curl -fsSL https://raw.githubusercontent.com/baalimago/clai/main/setup.sh | sh
```

Either look at `clai help` or the [examples](./EXAMPLES.md) for how to use `clai`.

## Honorable mentions
Expand Down
10 changes: 9 additions & 1 deletion internal/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,15 @@ func Setup(usage string) (models.Querier, error) {
if !ok {
return nil, errors.New("failed to read build info")
}
fmt.Printf("version: %v, go version: %v, checksum: %v\n", bi.Main.Version, bi.GoVersion, bi.Main.Sum)
version := bi.Main.Version
checksum := bi.Main.Sum
if version == "" || version == "(devel)" {
version = BUILD_VERSION
}
if checksum == "" {
checksum = BUILD_CHECKSUM
}
fmt.Printf("version: %v, go version: %v, checksum: %v\n", version, bi.GoVersion, checksum)
os.Exit(0)
case SETUP:
err := setup.Run()
Expand Down
7 changes: 7 additions & 0 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package internal

// Set with buildflag if built in pipeline and not using go install
var (
BUILD_VERSION = ""
BUILD_CHECKSUM = ""
)
87 changes: 87 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/sh

# Function to get the latest release download URL for the specified OS and architecture
get_latest_release_url() {
repo="baalimago/clai"
os="$1"
arch="$2"

# Fetch the latest release data from GitHub API
release_data=$(curl -s "https://api.github.com/repos/$repo/releases/latest")

# Extract the asset URL for the specified OS and architecture
download_url=$(echo "$release_data" | grep "browser_download_url" | grep "$os" | grep "$arch" | cut -d '"' -f 4)

echo "$download_url"
}

# Detect the OS
case "$(uname)" in
Linux*)
os="linux"
;;
Darwin*)
os="darwin"
;;
*)
echo "Unsupported OS: $(uname)"
exit 1
;;
esac

# Detect the architecture
arch=$(uname -m)
case "$arch" in
x86_64)
arch="amd64"
;;
armv7*)
arch="arm"
;;
aarch64|arm64)
arch="arm64"
;;
i?86)
arch="386"
;;
*)
echo "Unsupported architecture: $arch"
exit 1
;;
esac

printf "detected os: '%s', arch: '%s'\n" "$os" "$arch"

# Get the download URL for the latest release
printf "finding asset url..."
download_url=$(get_latest_release_url "$os" "$arch")
printf "OK!\n"

# Download the binary
tmp_file=$(mktemp)

printf "downloading binary..."
if ! curl -s -L -o "$tmp_file" "$download_url"; then
echo
echo "Failed to download the binary."
exit 1
fi
printf "OK!\n"

printf "setting file executable file permissions..."
# Make the binary executable

if ! chmod +x "$tmp_file"; then
echo
echo "Failed to make the binary executable. Try running the script with sudo."
exit 1
fi
printf "OK!\n"

# Move the binary to /usr/local/bin and handle permission errors
if ! mv "$tmp_file" /usr/local/bin/clai; then
echo "Failed to move the binary to /usr/local/bin/clai, see error above. Try running the script with sudo, or run 'mv $tmp_file <desired-position>'."
exit 1
fi

echo "clai installed successfully in /usr/local/bin, try it out with 'clai h'"

0 comments on commit efb9a2a

Please sign in to comment.