Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
thash committed Jan 26, 2025
0 parents commit ae3d067
Show file tree
Hide file tree
Showing 20 changed files with 6,781 additions and 0 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Build binaries and upload them to the GitHub release

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+" # Regex matches w/ version tags like 1.0.3

permissions:
contents: write

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_DEBUG: true

jobs:
create_release_on_github:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
- run: gh release create $VERSION --draft --verify-tag --title $VERSION
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
outputs:
version: ${{ env.VERSION }}

build_release_binaries:
runs-on: ${{ matrix.os }}
needs: ['create_release_on_github']
strategy:
fail-fast: false
matrix:
include:
- { name: linux , target: x86_64-unknown-linux-musl , os: ubuntu-latest, strip: true }
- { name: linux-arm, target: aarch64-unknown-linux-musl, os: ubuntu-latest, strip: false }
- { name: macos , target: x86_64-apple-darwin , os: macos-latest }
- { name: macos-arm, target: aarch64-apple-darwin , os: macos-latest }
- { name: windows , target: x86_64-pc-windows-msvc , os: windows-latest }

steps:
- name: Define envvars for this jobs
shell: bash
run: |
version="${{ needs.create_release_on_github.outputs.version }}"
echo "BINARY_BASENAME=zygen-$version-${{ matrix.target }}" >> $GITHUB_ENV
echo "VERSION=$version" >> $GITHUB_ENV
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

# Install required packages to build OpenSSL from source (cfg(target_os="linux") in Cargo.toml)
- if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get update && sudo apt-get install -y musl-tools

- name: Build release binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: build
args: --release --locked
target: ${{ matrix.target }}

- if: matrix.name != 'windows'
run: ls -lrth && ls -lrth ./target/ && ls -lrth ./target/${{ matrix.target }}/{,*}

- if: startsWith(matrix.os, 'ubuntu')
name: Reduce the binary size by UPX
uses: svenstaro/upx-action@v2
with:
files: target/${{ matrix.target }}/release/zg{,.exe} # for zg (linux, windows) or zg.exe (windows)
args: --best --lzma
strip: ${{ matrix.strip }}

- name: Archive the binary and generate SHA256 hash
shell: bash
run: |
if [ "${{ matrix.name }}" = "windows" ]; then
7z a -tzip ${{ env.BINARY_BASENAME }}.zip ./target/${{ matrix.target}}/release/zg.exe
certutil -hashfile ${{ env.BINARY_BASENAME }}.zip SHA256 > ${{ env.BINARY_BASENAME }}.zip.sha256
echo "ASSET=${{ env.BINARY_BASENAME }}.zip" >> $GITHUB_ENV
echo "ASSET_SUM=${{ env.BINARY_BASENAME }}.zip.sha256" >> $GITHUB_ENV
else
tar -C ./target/${{ matrix.target}}/release/ -cvzf ${{ env.BINARY_BASENAME }}.tar.gz zg
shasum -a 256 ${{ env.BINARY_BASENAME }}.tar.gz > ${{ env.BINARY_BASENAME }}.tar.gz.sha256
echo "ASSET=${{ env.BINARY_BASENAME }}.tar.gz" >> $GITHUB_ENV
echo "ASSET_SUM=${{ env.BINARY_BASENAME }}.tar.gz.sha256" >> $GITHUB_ENV
fi
- if: matrix.name != 'windows'
run: ls -lrth && ls -lrth ./target/ && ls -lrth ./target/${{ matrix.target }}/{,*}

- name: Upload the archived binary to Assets of the GitHub release
run: gh release upload --clobber ${{ env.VERSION }} ${{ env.ASSET }} ${{ env.ASSET_SUM }}
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/rust_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: cargo test, clippy, fmt

on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize, reopened]

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: debug

jobs:
test_and_check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Rust
run: |
rustup set profile minimal
rustup component add rustfmt clippy
rustup show
- name: Run cargo tests
run: cargo test --verbose
- name: Run cargo clippy
run: cargo clippy -- -D warnings
- name: Run cargo fmt
run: cargo fmt --all -- --check
- name: Build
run: cargo build --verbose
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Added by cargo

/target

.DS_Store

# Add during development
*.bin
*.msgpack
*.msgpack2
Loading

0 comments on commit ae3d067

Please sign in to comment.