Skip to content

Commit

Permalink
add release and install
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiago Medina Rolong committed Dec 14, 2024
1 parent 9632119 commit f0b6765
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 57 deletions.
75 changes: 21 additions & 54 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,40 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- 'v*'
- v[0-9]+.*

jobs:
create-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}

build-release:
upload-assets:
needs: create-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: program-linux-x86_64.tar.gz
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
artifact_name: program-linux-aarch64.tar.gz
- os: macos-latest
target: x86_64-apple-darwin
artifact_name: program-darwin-x86_64.tar.gz
- os: macos-latest
target: aarch64-apple-darwin
artifact_name: program-darwin-aarch64.tar.gz

- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: Install Rust
uses: actions-rs/toolchain@v1
- uses: actions/checkout@v4
- uses: taiki-e/upload-rust-binary-action@v1
with:
toolchain: stable
bin: xurl
target: ${{ matrix.target }}
override: true

- name: Build
uses: actions-rs/cargo@v1
with:
command: build
args: --release --target ${{ matrix.target }}

- name: Package
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../${{ matrix.artifact_name }} your-program
cd ../../..
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ./${{ matrix.artifact_name }}
asset_name: ${{ matrix.artifact_name }}
asset_content_type: application/gzip
tar: unix
zip: windows
token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# xurl - A curl-like CLI Tool for X (Twitter) API
# xurl - A curl-like CLI Tool for the X API
`xurl` is a command-line tool that simplifies making authenticated requests to the X (formerly Twitter) API. It handles OAuth 2.0 authentication automatically and provides a curl-like interface for API interactions.

## Features
Expand All @@ -11,8 +11,9 @@
- Custom header support

## Installation


```bash
curl -fsSL https://raw.githubusercontent.com/santiagomed/xurl/main/install.sh | sudo bash
```

## Configuration
Before using xurl, you need to set up the following environment variables:
Expand Down
106 changes: 106 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/bin/bash

# Exit immediately if any command fails
set -e

# Default installation directory
INSTALL_DIR="/usr/local/bin"
GITHUB_REPO="santiagomed/xurl"
PROGRAM_NAME="xurl"

# Print colorful messages
print_message() {
echo -e "\033[1;34m>> $1\033[0m"
}

print_error() {
echo -e "\033[1;31mError: $1\033[0m"
exit 1
}

# Check if running with sudo
check_permissions() {
if [ "$EUID" -ne 0 ]; then
print_error "Please run with sudo privileges"
fi
}

# Detect system architecture
detect_architecture() {
local arch=$(uname -m)
case $arch in
x86_64)
echo "x86_64"
;;
aarch64|arm64)
echo "aarch64"
;;
*)
print_error "Unsupported architecture: $arch"
;;
esac
}

# Detect operating system
detect_os() {
local os=$(uname -s)
case $os in
Linux)
echo "linux"
;;
Darwin)
echo "darwin"
;;
*)
print_error "Unsupported operating system: $os"
;;
esac
}

# Download the latest release
download_release() {
local os=$1
local arch=$2

# Construct binary name
local binary_name="${PROGRAM_NAME}-${os}-${arch}.tar.gz"
local download_url="https://github.com/${GITHUB_REPO}/releases/latest/download/${binary_name}"

print_message "Downloading latest release for ${os}-${arch}..."

# Create temporary directory
local temp_dir=$(mktemp -d)
trap 'rm -rf -- "$temp_dir"' EXIT

# Download and extract
if ! curl -L "$download_url" -o "${temp_dir}/${binary_name}"; then
print_error "Failed to download release"
fi

tar xzf "${temp_dir}/${binary_name}" -C "$temp_dir"

# Install binary
print_message "Installing to ${INSTALL_DIR}..."
mv "${temp_dir}/${PROGRAM_NAME}" "${INSTALL_DIR}/"
chmod +x "${INSTALL_DIR}/${PROGRAM_NAME}"
}

# Main installation process
main() {
print_message "Starting installation..."

# Check if running with necessary permissions
check_permissions

# Detect system details
local os=$(detect_os)
local arch=$(detect_architecture)

# Download and install
download_release "$os" "$arch"

print_message "Installation complete! You can now run '${PROGRAM_NAME}' from anywhere."
}

# Run main function
main

0 comments on commit f0b6765

Please sign in to comment.