Skip to content

Commit 6e8d7ab

Browse files
authored
add .goreleaser.yml install.sh and release.yml (#12)
1 parent add45d6 commit 6e8d7ab

File tree

3 files changed

+156
-0
lines changed

3 files changed

+156
-0
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*' # This workflow runs on tags like v1.0, v1.2.3
7+
8+
jobs:
9+
goreleaser:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
with:
15+
# This is needed for GoReleaser to determine the changelog.
16+
fetch-depth: 0
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
# The Go version from your go.mod file.
22+
go-version: '1.24'
23+
24+
- name: Run GoReleaser
25+
uses: goreleaser/goreleaser-action@v5
26+
with:
27+
# We use the GoReleaser distribution itself.
28+
distribution: goreleaser
29+
version: latest
30+
args: release --clean
31+
env:
32+
# This token is provided by GitHub Actions to allow creating releases.
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
2+
# This is the configuration for GoReleaser
3+
project_name: gitx
4+
5+
builds:
6+
- # Each build is an object with its own configuration.
7+
id: gitx
8+
# The main package for your application.
9+
main: ./cmd/gitx/
10+
# The name of the binary file.
11+
binary: gitx
12+
env:
13+
# CGO_ENABLED=0 is used to build a statically linked binary.
14+
- CGO_ENABLED=0
15+
# Platforms to build for.
16+
goos:
17+
- linux
18+
- darwin # macOS
19+
goarch:
20+
- amd64 # For Intel/AMD processors
21+
- arm64 # For Apple Silicon and other ARM processors
22+
23+
# Configuration for the archives (e.g., .tar.gz files).
24+
archives:
25+
- format: tar.gz
26+
# This template creates archives like "gitx_1.0.0_linux_amd64.tar.gz"
27+
name_template: >-
28+
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
29+
# Files to include in the archive along with the binary.
30+
files:
31+
- LICENSE
32+
- README.md

install.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/sh
2+
#
3+
# This script downloads and installs the latest binary release of gitx.
4+
# It detects the user's OS and architecture to download the correct binary.
5+
#
6+
# Usage:
7+
# curl -sSL https://raw.githubusercontent.com/gitxtui/gitx/master/install.sh | bash
8+
9+
set -e
10+
11+
# The GitHub repository in the format "owner/repo".
12+
REPO="gitxtui/gitx"
13+
INSTALL_DIR="/usr/local/bin"
14+
15+
# Get the operating system.
16+
get_os() {
17+
case "$(uname -s)" in
18+
Linux*) OS='linux';;
19+
Darwin*) OS='darwin';;
20+
*)
21+
echo "Unsupported operating system: $(uname -s)"
22+
exit 1
23+
;;
24+
esac
25+
echo "$OS"
26+
}
27+
28+
# Get the architecture.
29+
get_arch() {
30+
case "$(uname -m)" in
31+
x86_64|amd64) ARCH='amd64';;
32+
aarch64|arm64) ARCH='arm64';;
33+
*)
34+
echo "Unsupported architecture: $(uname -m)"
35+
exit 1
36+
;;
37+
esac
38+
echo "$ARCH"
39+
}
40+
41+
# Get the latest release tag from the GitHub API.
42+
get_latest_release() {
43+
curl --silent "https://api.github.com/repos/$REPO/releases/latest" |
44+
grep '"tag_name":' |
45+
sed -E 's/.*"([^"]+)".*/\1/'
46+
}
47+
48+
main() {
49+
OS=$(get_os)
50+
ARCH=$(get_arch)
51+
VERSION=$(get_latest_release)
52+
53+
if [ -z "$VERSION" ]; then
54+
echo "Error: Could not find the latest release version for $REPO."
55+
exit 1
56+
fi
57+
58+
# Construct the archive filename and download URL.
59+
VERSION_NUM=$(echo "$VERSION" | sed 's/v//')
60+
FILENAME="gitx_${VERSION_NUM}_${OS}_${ARCH}.tar.gz"
61+
DOWNLOAD_URL="https://github.com/$REPO/releases/download/${VERSION}/${FILENAME}"
62+
63+
# Download and extract the binary.
64+
echo "Downloading gitx ${VERSION} for ${OS}/${ARCH}..."
65+
TEMP_DIR=$(mktemp -d)
66+
# Download to a temporary directory.
67+
curl -sSL -o "$TEMP_DIR/$FILENAME" "$DOWNLOAD_URL"
68+
69+
echo "Installing gitx to ${INSTALL_DIR}..."
70+
# Extract the archive.
71+
tar -xzf "$TEMP_DIR/$FILENAME" -C "$TEMP_DIR"
72+
73+
# Move the binary to the installation directory.
74+
# Use sudo if the directory is not writable by the current user.
75+
if [ -w "$INSTALL_DIR" ]; then
76+
mv "$TEMP_DIR/gitx" "${INSTALL_DIR}/gitx"
77+
else
78+
echo "Root permission is required to install gitx to ${INSTALL_DIR}"
79+
sudo mv "$TEMP_DIR/gitx" "${INSTALL_DIR}/gitx"
80+
fi
81+
82+
# Clean up the temporary directory.
83+
rm -rf "$TEMP_DIR"
84+
85+
echo ""
86+
echo "gitx has been installed successfully!"
87+
echo "Run 'gitx' to get started."
88+
}
89+
90+
# Run the main function.
91+
main

0 commit comments

Comments
 (0)