Skip to content

Commit

Permalink
🧱 create workflow to build binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Sep 27, 2024
1 parent 8088e39 commit aa5a1be
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build and Release Binaries

on:
push:
tags:
- "v*.*.*" # Triggers on version tag pushes like v1.0.0

jobs:
build:
name: Build Binaries
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
platform: linux
arch: x86_64
- os: macos-latest
platform: macos
arch: x86_64
- os: windows-latest
platform: windows
arch: x86_64
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set Up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: "1.17.2"
otp-version: "26"

- name: Install Dependencies
run: mix deps.get

- name: Build Release
env:
MIX_ENV: prod
run: mix release

- name: Prepare Artifact
if: ${{ runner.os != 'Windows' }}
run: |
tar czvf cashubrew-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.ref_name }}.tar.gz -C _build/prod/rel/cashubrew .
- name: Prepare Artifact (Windows)
if: ${{ runner.os == 'Windows' }}
shell: pwsh
run: |
Compress-Archive -Path "_build\prod\rel\cashubrew\*" -DestinationPath "cashubrew-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.ref_name }}.zip"
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: cashubrew-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.ref_name }}
path: |
cashubrew-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.ref_name }}.tar.gz
cashubrew-${{ matrix.platform }}-${{ matrix.arch }}-${{ github.ref_name }}.zip
release:
name: Create Release
runs-on: ubuntu-latest
needs: build
steps:
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
path: ./artifacts

- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v1
with:
files: ./artifacts/*
draft: false
prerelease: false
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79 changes: 79 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

set -e

OS="$(uname -s)"
ARCH="$(uname -m)"

# Normalize OS name
case "$OS" in
Linux*) PLATFORM="linux";;
Darwin*) PLATFORM="macos";;
CYGWIN*|MINGW*|MSYS_NT*) PLATFORM="windows";;
*) echo "Unsupported OS: $OS"; exit 1;;
esac

# Normalize ARCH
case "$ARCH" in
x86_64|amd64) ARCH="x86_64";;
arm64|aarch64) ARCH="arm64";;
*) echo "Unsupported architecture: $ARCH"; exit 1;;
esac

echo "Detected platform: $PLATFORM"
echo "Detected architecture: $ARCH"

# Get the version to install
if [ -n "$1" ]; then
VERSION="$1"
else
# Get latest version
VERSION=$(curl -s https://api.github.com/repos/keep-starknet-strange/cashubrew/releases/latest | grep '"tag_name"' | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
fi

if [ -z "$VERSION" ]; then
echo "Failed to get version to install"
exit 1
fi

echo "Installing version: $VERSION"

# Construct download URL
if [ "$PLATFORM" = "windows" ]; then
EXT="zip"
else
EXT="tar.gz"
fi

BINARY_NAME="cashubrew-${PLATFORM}-${ARCH}-${VERSION}.${EXT}"
DOWNLOAD_URL="https://github.com/keep-starknet-strange/cashubrew/releases/download/${VERSION}/${BINARY_NAME}"

echo "Downloading $DOWNLOAD_URL"

# Download the binary
curl -L -o "$BINARY_NAME" "$DOWNLOAD_URL"

# Extract and install
if [ "$EXT" = "tar.gz" ]; then
tar xzvf "$BINARY_NAME"
elif [ "$EXT" = "zip" ]; then
unzip "$BINARY_NAME"
else
echo "Unknown file extension: $EXT"
exit 1
fi

# Move binary to /usr/local/bin
if [ -d "cashubrew/bin" ]; then
sudo cp cashubrew/bin/cashubrew /usr/local/bin/
elif [ -f "cashubrew.exe" ]; then
sudo cp cashubrew.exe /usr/local/bin/
else
echo "Binary not found after extraction"
exit 1
fi

# Clean up
rm -rf "$BINARY_NAME" cashubrew cashubrew.exe

echo "✅ Cashubrew installed successfully!"

0 comments on commit aa5a1be

Please sign in to comment.