Skip to content

Commit

Permalink
Add build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasschafer committed Nov 18, 2024
1 parent afceb68 commit be6864b
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
118 changes: 118 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Build and Upload Release Binaries

on:
# push:
# tags:
# - "v*"
workflow_dispatch:
pull_request:
branches:
- '**' # TODO: remove

permissions:
contents: write

jobs:
build-and-upload:
name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
use-cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-musl
use-cross: true
- os: macos-13
target: x86_64-apple-darwin
use-cross: false
- os: macos-latest
target: aarch64-apple-darwin
use-cross: false
- os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get latest tag
shell: bash
run: |
git fetch --tags
LATEST_TAG=$(git tag --sort=committerdate | tail -1)
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Handle Rust dependencies caching
uses: Swatinem/rust-cache@v2
with:
key: v1-${{ matrix.target }}

- name: Build binary
uses: clechasseur/rs-cargo@v2
with:
command: build
args: --release --target ${{ matrix.target }}
use-cross: ${{ matrix.use-cross }}

- name: Get binary name from Cargo.toml
shell: bash
run: |
BINARY_NAME=$(grep -m1 '^name' Cargo.toml | cut -d'"' -f2 | cut -d"'" -f2)
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV
- name: Create release archive
shell: bash
run: |
cd target/${{ matrix.target }}/release
if [ "${{ runner.os }}" = "Windows" ]; then
ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.zip"
mv "${{ env.BINARY_NAME }}.exe" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe"
7z a "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}.exe"
else
ARCHIVE="${{ env.BINARY_NAME }}-${{ env.LATEST_TAG }}-${{ matrix.target }}.tar.gz"
mv "${{ env.BINARY_NAME }}" "${{ env.BINARY_NAME }}-${{ matrix.target }}"
tar -czvf "$ARCHIVE" "${{ env.BINARY_NAME }}-${{ matrix.target }}"
fi
# Generate checksums
openssl dgst -r -sha256 -out "$ARCHIVE.sha256" "$ARCHIVE"
openssl dgst -r -sha512 -out "$ARCHIVE.sha512" "$ARCHIVE"
echo "ASSET=$ARCHIVE" >> $GITHUB_ENV
- name: Verify binary
shell: bash
run: |
cd target/${{ matrix.target }}/release
case "${{ matrix.target }}" in
*windows*)
7z x -y "$ASSET"
./${{ env.BINARY_NAME }}-${{ matrix.target }}.exe --version ;;
aarch64*)
echo "Can't test an ARM binary on a AMD64 runner" ;;
*)
tar -xvzf "$ASSET"
./${{ env.BINARY_NAME }}-${{ matrix.target }} --version ;;
esac
- name: Upload to release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.LATEST_TAG }}
files: |
target/${{ matrix.target }}/release/${{ env.ASSET }}
target/${{ matrix.target }}/release/${{ env.ASSET }}.sha256
target/${{ matrix.target }}/release/${{ env.ASSET }}.sha512
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use logging::setup_logging;
use ratatui::{backend::CrosstermBackend, Terminal};
use std::{io, path::PathBuf, str::FromStr};
use tui::Tui;

mod app;
mod event;
mod fields;
Expand All @@ -18,6 +17,7 @@ use crate::{

#[derive(Parser, Debug)]
#[command(about = "Interactive find and replace TUI.")]
#[command(version)]
struct Args {
/// Directory in which to search
#[arg(index = 1)]
Expand Down

0 comments on commit be6864b

Please sign in to comment.