ci: Add Git configuration for tests #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Test | |
on: | |
push: | |
branches: [ "**" ] | |
tags: [ "v*" ] | |
pull_request: | |
branches: [ "**" ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
CARGO_TERM_COLOR: always | |
RUST_BACKTRACE: 1 | |
CARGO_NET_RETRY: 2 | |
permissions: | |
contents: read | |
jobs: | |
build-and-test: | |
name: Build and Test ${{ matrix.target }} | |
runs-on: ${{ matrix.os }} | |
timeout-minutes: 30 | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
# macOS builds | |
- os: macos-latest | |
target: x86_64-apple-darwin | |
binary_name: essex | |
use_cross: false | |
- os: macos-latest | |
target: aarch64-apple-darwin | |
binary_name: essex | |
use_cross: false | |
# Linux builds | |
- os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
binary_name: essex | |
use_cross: false | |
- os: ubuntu-latest | |
target: aarch64-unknown-linux-gnu | |
binary_name: essex | |
use_cross: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Cache Rust dependencies | |
uses: actions/cache@v4 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-${{ matrix.target }}- | |
- name: Install cross (if needed) | |
if: matrix.use_cross | |
run: cargo install cross | |
- name: Build binary | |
run: | | |
if [ "${{ matrix.use_cross }}" = "true" ]; then | |
cross build --release --target ${{ matrix.target }} | |
else | |
cargo build --release --target ${{ matrix.target }} | |
fi | |
- name: Configure Git | |
run: | | |
git config --global user.email "ci@example.com" | |
git config --global user.name "CI User" | |
- name: Run tests | |
run: | | |
if [ "${{ matrix.use_cross }}" = "true" ]; then | |
cross test --target ${{ matrix.target }} -- --nocapture | |
else | |
cargo test --target ${{ matrix.target }} -- --nocapture | |
fi | |
- name: Package binary | |
shell: bash | |
run: | | |
cd target/${{ matrix.target }}/release | |
if [ "${{ matrix.os }}" = "windows-latest" ]; then | |
zip ../../../essex-${{ matrix.target }}.zip ${{ matrix.binary_name }}.exe | |
else | |
tar czf ../../../essex-${{ matrix.target }}.tar.gz ${{ matrix.binary_name }} | |
fi | |
cd - | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: essex-${{ matrix.target }} | |
path: essex-${{ matrix.target }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }} | |
retention-days: 5 | |
release: | |
name: Create Release | |
needs: build-and-test | |
if: startsWith(github.ref, 'refs/tags/') | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: dist | |
merge-multiple: true | |
- name: List artifacts | |
run: ls -la dist/ | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2.1.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
files: dist/* | |
generate_release_notes: true | |
draft: false | |
prerelease: false |