Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Release

on:
push:
tags:
- 'v*' # This workflow runs on tags like v1.0, v1.2.3

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# This is needed for GoReleaser to determine the changelog.
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
# The Go version from your go.mod file.
go-version: '1.24'

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
# We use the GoReleaser distribution itself.
distribution: goreleaser
version: latest
args: release --clean
env:
# This token is provided by GitHub Actions to allow creating releases.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# This is the configuration for GoReleaser
project_name: gitx

builds:
- # Each build is an object with its own configuration.
id: gitx
# The main package for your application.
main: ./cmd/gitx/
# The name of the binary file.
binary: gitx
env:
# CGO_ENABLED=0 is used to build a statically linked binary.
- CGO_ENABLED=0
# Platforms to build for.
goos:
- linux
- darwin # macOS
goarch:
- amd64 # For Intel/AMD processors
- arm64 # For Apple Silicon and other ARM processors

# Configuration for the archives (e.g., .tar.gz files).
archives:
- format: tar.gz
# This template creates archives like "gitx_1.0.0_linux_amd64.tar.gz"
name_template: >-
{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}
# Files to include in the archive along with the binary.
files:
- LICENSE
- README.md
91 changes: 91 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/sh
#
# This script downloads and installs the latest binary release of gitx.
# It detects the user's OS and architecture to download the correct binary.
#
# Usage:
# curl -sSL https://raw.githubusercontent.com/gitxtui/gitx/master/install.sh | bash

set -e

# The GitHub repository in the format "owner/repo".
REPO="gitxtui/gitx"
INSTALL_DIR="/usr/local/bin"

# Get the operating system.
get_os() {
case "$(uname -s)" in
Linux*) OS='linux';;
Darwin*) OS='darwin';;
*)
echo "Unsupported operating system: $(uname -s)"
exit 1
;;
esac
echo "$OS"
}

# Get the architecture.
get_arch() {
case "$(uname -m)" in
x86_64|amd64) ARCH='amd64';;
aarch64|arm64) ARCH='arm64';;
*)
echo "Unsupported architecture: $(uname -m)"
exit 1
;;
esac
echo "$ARCH"
}

# Get the latest release tag from the GitHub API.
get_latest_release() {
curl --silent "https://api.github.com/repos/$REPO/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}

main() {
OS=$(get_os)
ARCH=$(get_arch)
VERSION=$(get_latest_release)

if [ -z "$VERSION" ]; then
echo "Error: Could not find the latest release version for $REPO."
exit 1
fi

# Construct the archive filename and download URL.
VERSION_NUM=$(echo "$VERSION" | sed 's/v//')
FILENAME="gitx_${VERSION_NUM}_${OS}_${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/${VERSION}/${FILENAME}"

# Download and extract the binary.
echo "Downloading gitx ${VERSION} for ${OS}/${ARCH}..."
TEMP_DIR=$(mktemp -d)
# Download to a temporary directory.
curl -sSL -o "$TEMP_DIR/$FILENAME" "$DOWNLOAD_URL"

echo "Installing gitx to ${INSTALL_DIR}..."
# Extract the archive.
tar -xzf "$TEMP_DIR/$FILENAME" -C "$TEMP_DIR"

# Move the binary to the installation directory.
# Use sudo if the directory is not writable by the current user.
if [ -w "$INSTALL_DIR" ]; then
mv "$TEMP_DIR/gitx" "${INSTALL_DIR}/gitx"
else
echo "Root permission is required to install gitx to ${INSTALL_DIR}"
sudo mv "$TEMP_DIR/gitx" "${INSTALL_DIR}/gitx"
fi

# Clean up the temporary directory.
rm -rf "$TEMP_DIR"

echo ""
echo "gitx has been installed successfully!"
echo "Run 'gitx' to get started."
}

# Run the main function.
main
Loading