This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from StrongMonkey/tweak-ci
Chore: add cross compile script and CI
- Loading branch information
Showing
6 changed files
with
130 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
GO_VERSION: "1.22.x" | ||
|
||
jobs: | ||
test-suite: | ||
timeout-minutes: 30 | ||
name: Full Test Suite | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
# Setup | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go environment | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: "${{ env.GO_VERSION }}" | ||
- name: Setup CI Tools | ||
run: make ci-setup | ||
- name: Build | ||
run: make build | ||
# Tests | ||
- name: Run Go Tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
REPO="gptscript-ai/knowledge" | ||
INSTALL_DIR="/usr/local/bin" | ||
|
||
# Function to determine the OS and architecture | ||
get_os_arch() { | ||
OS=$(uname -s | tr '[:upper:]' '[:lower:]') | ||
ARCH=$(uname -m) | ||
|
||
case $ARCH in | ||
x86_64) | ||
ARCH="amd64" | ||
;; | ||
aarch64) | ||
ARCH="arm64" | ||
;; | ||
arm64) | ||
ARCH="arm64" | ||
;; | ||
*) | ||
echo "Unsupported architecture: $ARCH" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
echo "${OS}-${ARCH}" | ||
} | ||
|
||
# Function to download the latest release | ||
download_latest_release() { | ||
OS_ARCH=$1 | ||
LATEST_RELEASE_URL="https://api.github.com/repos/$REPO/releases/latest" | ||
|
||
DOWNLOAD_URL=$(curl -s $LATEST_RELEASE_URL | grep "browser_download_url.*$OS_ARCH" | cut -d '"' -f 4) | ||
|
||
if [[ -z "$DOWNLOAD_URL" ]]; then | ||
echo "No binary found for $OS_ARCH" | ||
exit 1 | ||
fi | ||
|
||
TEMP_DIR=$(mktemp -d) | ||
TEMP_FILE="$TEMP_DIR/knowledge" | ||
|
||
echo "Downloading $DOWNLOAD_URL..." | ||
curl -sL "$DOWNLOAD_URL" -o "$TEMP_FILE" | ||
|
||
chmod +x $TEMP_FILE | ||
|
||
mv $TEMP_FILE "$INSTALL_DIR/knowledge" | ||
|
||
rm -rf "$TEMP_DIR" | ||
|
||
echo "Installed knowledge to $INSTALL_DIR/knowledge" | ||
} | ||
|
||
# Ensure the script is run as root | ||
if [[ $EUID -ne 0 ]]; then | ||
echo "This script must be run as root. Please run with sudo." | ||
exit 1 | ||
fi | ||
|
||
OS_ARCH=$(get_os_arch) | ||
download_latest_release "$OS_ARCH" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
GO_TAGS="netgo" | ||
LD_FLAGS="-s -w -X github.com/gptscript-ai/knowledge/version.Version=${GIT_TAG}" | ||
|
||
if [ "$(go env GOOS)" = "linux" ]; then | ||
CGO_ENABLED=1 GOARCH=amd64 go build -o dist/knowledge-linux-amd64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}\" -extldflags \"-static\" " . | ||
else | ||
CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc GOOS=windows GOARCH=amd64 go build -o dist/knowledge-windows-amd64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}" . | ||
CGO_ENABLED=1 GOARCH=amd64 go build -o dist/knowledge-darwin-amd64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}" . | ||
CGO_ENABLED=1 GOARCH=arm64 go build -o dist/knowledge-darwin-arm64 -tags "${GO_TAGS}" -ldflags "${LD_FLAGS}" . | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters