Skip to content

Commit 4a2be38

Browse files
committed
Update release workflow and install.sh
1 parent 949b4ff commit 4a2be38

File tree

2 files changed

+78
-77
lines changed

2 files changed

+78
-77
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,30 @@ on:
66

77
jobs:
88
build:
9-
strategy:
10-
matrix:
11-
include:
12-
- os: windows-latest
13-
artifact_name: windows
14-
- os: ubuntu-latest
15-
artifact_name: linux
16-
- os: macos-latest
17-
artifact_name: macos
18-
runs-on: ${{ matrix.os }}
9+
runs-on: ubuntu-latest
1910
steps:
2011
- uses: actions/checkout@v4
21-
- name: Set up Python
22-
uses: actions/setup-python@v5
12+
- name: Set up Go
13+
uses: actions/setup-go@v4
2314
with:
24-
python-version: '3.x'
25-
- name: Install dependencies
26-
run: pip install -r requirements.txt
27-
- name: Build binary
28-
run: pyinstaller --onefile gpt_cmd.py
29-
- name: Upload artifact
15+
go-version: '1.22'
16+
- name: Build binaries
17+
run: |
18+
GOOS=linux GOARCH=386 go build -o bin/gpt_cmd-linux-386
19+
GOOS=linux GOARCH=amd64 go build -o bin/gpt_cmd-linux
20+
GOOS=linux GOARCH=arm go build -o bin/gpt_cmd-linux-arm
21+
GOOS=linux GOARCH=arm64 go build -o bin/gpt_cmd-linux-arm64
22+
23+
GOOS=darwin GOARCH=amd64 go build -o bin/gpt_cmd-macos-amd64
24+
GOOS=darwin GOARCH=arm64 go build -o bin/gpt_cmd-macos-arm64
25+
26+
GOOS=windows GOARCH=386 go build -o bin/gpt_cmd-windows-386.exe
27+
GOOS=windows GOARCH=amd64 go build -o bin/gpt_cmd-windows.exe
28+
- name: Upload artifacts
3029
uses: actions/upload-artifact@v4
3130
with:
32-
name: ${{ matrix.artifact_name }}
33-
path: 'dist/gpt_cmd*'
31+
name: binaries
32+
path: bin/*
3433
retention-days: 1
3534

3635
release:
@@ -42,23 +41,9 @@ jobs:
4241
- uses: actions/checkout@v4
4342
- name: Download artifacts
4443
uses: actions/download-artifact@v4
45-
- name: Rename artifacts
46-
run: |
47-
mkdir -p bin
48-
for os in windows linux macos; do
49-
ext=""
50-
if [ "$os" = "windows" ]; then
51-
ext=".exe"
52-
fi
53-
54-
src="${os}/gpt_cmd${ext}"
55-
dest="bin/gpt_cmd-${os}${ext}"
56-
57-
echo "Moving $src to $dest"
58-
mv "$src" "$dest"
59-
rm -rf "${os}/"
60-
done
44+
with:
45+
name: binaries
6146
- name: Create release
6247
uses: ncipollo/release-action@v1.14.0
6348
with:
64-
artifacts: 'bin/gpt_cmd*'
49+
artifacts: 'bin/*'

install.sh

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,8 @@
22

33
set -e
44

5-
if [[ "$OSTYPE" == "linux"* ]]; then
6-
OS="linux"
7-
elif [[ "$OSTYPE" == "darwin"* ]]; then
8-
OS="macos"
9-
else
10-
OS="unknown"
11-
fi
12-
135
ansi_blue='\033[94m'
6+
ansi_dim='\033[2m'
147
ansi_green='\033[92m'
158
ansi_red='\033[91m'
169
ansi_yellow='\033[93m'
@@ -19,6 +12,9 @@ ansi_reset='\033[0m'
1912
function print_blue() {
2013
printf "${ansi_blue}%b${ansi_reset}" "$1"
2114
}
15+
function print_dim() {
16+
printf "${ansi_dim}%b${ansi_reset}" "$1"
17+
}
2218
function print_green() {
2319
printf "${ansi_green}%b${ansi_reset}" "$1"
2420
}
@@ -38,8 +34,9 @@ function log_warning() {
3834

3935
function fetch_latest_binary() {
4036
local github_repo="$1"
41-
local dir_path="$2"
42-
local binary_name="$3"
37+
local os_name="$2"
38+
local dir_path="$3"
39+
local binary_name="$4"
4340

4441
# detect which fetch tool is available on the machine
4542
local fetch_tool
@@ -69,39 +66,43 @@ function fetch_latest_binary() {
6966
| sed -E 's/.*"tag_name": "(.*)",/\1/' \
7067
| head -1 \
7168
)"
72-
local binary_urls="$( \
69+
# this is just used to validate that there are any binary urls
70+
# resolved for the latest release
71+
# (to determine if the GH call failed or if there's just not a file for this OS)
72+
local latest_binary_urls="$( \
7373
echo "$releases_res" \
7474
| grep "releases/download/$latest_version/gpt_cmd-" \
75+
)"
76+
local os_binary_url="$( \
77+
echo "$releases_res" \
78+
| grep "releases/download/$latest_version/gpt_cmd-${os_name}" \
7579
| sed -E 's/[ \t]+"browser_download_url": "([^"]+)",?/\1/' \
7680
)"
77-
local latest_binary_url=""
78-
for url in $binary_urls; do
79-
os="$(echo "$url" | sed -E 's|.*/gpt_cmd-([^.]*).*|\1|')"
80-
if [ "$os" = "$OS" ]; then
81-
latest_binary_url="$url"
82-
break
83-
fi
84-
done
85-
if [ -z "$latest_binary_url" ]; then
86-
local error_file_name="gpt_cmd_install-error_$(date +"%Y-%m-%d_%H-%M-%S").log"
87-
echo -e "ERROR: unable to find release binary\n" >> "$error_file_name"
88-
echo -e "GitHub releases response body:\n$releases_res" >> "$error_file_name"
81+
if [ -z "$os_binary_url" ]; then
82+
echo ""
83+
if [ -n "$latest_binary_urls" ]; then
84+
log_error "no binary found for OS '${os_name}' on latest release"
85+
else
86+
local error_file_name="gpt_cmd_install-error_$(date +"%Y-%m-%d_%H-%M-%S").log"
87+
echo -e "ERROR: unable to find release binary\n" >> "$error_file_name"
88+
echo -e "GitHub releases response body:\n$releases_res" >> "$error_file_name"
8989

90-
log_error "unable to find release binary; see $error_file_name for more info"
90+
log_error "unable to lookup release binaries; see $error_file_name for more info"
91+
fi
9192
exit 1
9293
fi
9394

9495
# fetch the binary
95-
local file_name="$(basename "$latest_binary_url")"
96+
local file_name="$(basename "$os_binary_url")"
9697
local file_path="$dir_path/$file_name"
9798
case $fetch_tool in
9899
curl)
99-
curl -L -s -S -o "$file_path" "$latest_binary_url";;
100+
curl -L -s -S -o "$file_path" "$os_binary_url";;
100101
wget)
101-
wget -q -O "$file_path" "$latest_binary_url";;
102+
wget -q -O "$file_path" "$os_binary_url";;
102103
esac
103104
if [ ! -e "$file_path" ]; then
104-
log_error "failed to fetch latest release binary ($latest_binary_url)"
105+
log_error "failed to fetch latest release binary ($os_binary_url)"
105106
exit 1
106107
fi
107108

@@ -111,11 +112,12 @@ function fetch_latest_binary() {
111112

112113
function make_binary_executable() {
113114
local file_path="$1"
115+
local os_name="$2"
114116

115117
chmod +x "$file_path"
116118

117119
# try to make MacOS trust the binary file
118-
if [ "$OS" = "macos" ]; then
120+
if [[ "$os_name" == "darwin"* ]]; then
119121
if command -v xattr >/dev/null; then
120122
if xattr -p com.apple.quarantine "$file_path" &>/dev/null; then
121123
xattr -d com.apple.quarantine "$file_path"
@@ -142,33 +144,47 @@ function get_profile_file() {
142144
done
143145
}
144146

145-
function run_install() {
146-
if [ "$OS" = "unknown" ]; then
147-
log_error "OS type '$OSTYPE' not recognized as a supported OS"
148-
exit 1
149-
fi
147+
function get_os_name() {
148+
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
149+
local arch=$(uname -m)
150+
151+
case "$arch" in
152+
x86_64)
153+
arch="amd64" ;;
154+
i686)
155+
arch="386" ;;
156+
aarch64)
157+
arch="arm64" ;;
158+
armv7l)
159+
arch="arm" ;;
160+
esac
161+
162+
echo "${os}-${arch}"
163+
}
150164

165+
function run_install() {
166+
local os_name="$(get_os_name)"
151167
local install_dir="$HOME/.gpt_cmd"
152-
echo "Installing to ${install_dir}"
168+
print_blue "Installing to ${install_dir}\n"
153169

154-
print_blue "Attempting to fetch latest binary..."
170+
print_dim "Attempting to fetch latest binary..."
155171
local repo_name="chrisdothtml/gpt-cmd"
156172
local binary_dir_path="$install_dir/bin"
157173
local binary_name="gpt_cmd"
158174
mkdir -p "$binary_dir_path"
159-
fetch_latest_binary "$repo_name" "$binary_dir_path" "$binary_name"
175+
fetch_latest_binary "$repo_name" "$os_name" "$binary_dir_path" "$binary_name"
160176
echo ""
161177

162-
print_blue "Making binary executable on your system..."
178+
print_dim "Making binary executable on your system..."
163179
local binary_file_path="$binary_dir_path/$binary_name"
164-
make_binary_executable "$binary_file_path"
180+
make_binary_executable "$binary_file_path" "$os_name"
165181
echo ""
166182

167183
local path_update_str="export PATH=\"${binary_dir_path}:\$PATH\""
168184
local profile_file
169185
if ! command -v gpt_cmd >/dev/null; then
170186
profile_file="$(get_profile_file)"
171-
print_blue "Exposing binary to PATH..."
187+
print_dim "Exposing binary to PATH..."
172188
echo -e "\n$path_update_str" >> "$profile_file"
173189
echo ""
174190
fi

0 commit comments

Comments
 (0)