Skip to content

Remove tarpaulin-report.html from repo and add to gitignore #78

Remove tarpaulin-report.html from repo and add to gitignore

Remove tarpaulin-report.html from repo and add to gitignore #78

Workflow file for this run

name: Build and Test
on:
push:
branches: [ "main" ]
tags: [ "v*" ]
pull_request:
branches: [ "main" ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_NET_RETRY: 2
RUSTFLAGS: "-D warnings -D clippy::redundant-pattern-matching -D clippy::needless-borrows-for-generic-args"
RUST_VERSION: "1.83.0"
permissions:
contents: read
jobs:
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
toolchain: ${{ env.RUST_VERSION }}
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
~/.rustup
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Check formatting
run: cargo fmt --all -- --check
- name: Run clippy
run: |
cargo clippy --all-targets --all-features -- \
-D warnings \
-D clippy::redundant-pattern-matching \
-D clippy::needless-borrows-for-generic-args
- name: Install cargo-deny
run: cargo install --locked cargo-deny
- name: Run cargo-deny
run: cargo deny check
coverage:
name: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-tarpaulin
run: cargo install cargo-tarpaulin
- name: Generate coverage report
run: cargo tarpaulin --out Xml --output-dir coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/cobertura.xml
fail_ci_if_error: true
build-and-test:
name: Build and Test ${{ matrix.target }}
runs-on: ${{ matrix.os }}
timeout-minutes: 30
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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:
target: ${{ matrix.target }}
toolchain: ${{ env.RUST_VERSION }}
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
~/.rustup
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock', '**/Cargo.toml', 'rust-toolchain.toml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target }}-cargo-
- name: Cache cargo bin
uses: actions/cache@v3
with:
path: ~/.cargo/bin
key: ${{ runner.os }}-cargo-bin
- name: Configure Git
run: |
# Set global git config in home directory
git config --global user.email "[email protected]"
git config --global user.name "CI User"
git config --global init.defaultBranch main
# Create a git config template for cross environment
mkdir -p /tmp/git-template
git config -f /tmp/git-template/config user.email "[email protected]"
git config -f /tmp/git-template/config user.name "CI User"
# Set environment variable for tests to use the template
echo "GIT_CONFIG_GLOBAL=/tmp/git-template/config" >> $GITHUB_ENV
- 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: Run tests
env:
RUST_BACKTRACE: 1
run: |
if [ "${{ matrix.use_cross }}" = "true" ]; then
cross test --target ${{ matrix.target }} -- --nocapture
else
cargo test --target ${{ matrix.target }} -- --nocapture
fi
- name: Test install script
if: matrix.os != 'windows-latest' # Skip on Windows as it's not supported
run: |
chmod +x ./test_install.sh
./test_install.sh
- 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 -
# Generate checksum for the archive
if [ "${{ matrix.os }}" = "windows-latest" ]; then
shasum -a 256 essex-${{ matrix.target }}.zip > essex-${{ matrix.target }}.zip.sha256
else
shasum -a 256 essex-${{ matrix.target }}.tar.gz > essex-${{ matrix.target }}.tar.gz.sha256
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: essex-${{ matrix.target }}
path: |
essex-${{ matrix.target }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }}
essex-${{ matrix.target }}.${{ matrix.os == 'windows-latest' && 'zip' || 'tar.gz' }}.sha256
retention-days: 5
create-tag:
name: create-tag
# Only run on main branch when Cargo.toml version changes
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check-version.outputs.version }}
should_tag: ${{ steps.check-version.outputs.should_tag }}
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check version change
id: check-version
run: |
# Get the current version from Cargo.toml
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
# Check if this version is already tagged
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Version v$CURRENT_VERSION is already tagged"
echo "should_tag=false" >> $GITHUB_OUTPUT
else
echo "Version v$CURRENT_VERSION needs to be tagged"
echo "should_tag=true" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
if: steps.check-version.outputs.should_tag == 'true'
run: |
VERSION=${{ steps.check-version.outputs.version }}
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
release:
name: release
needs: [build-and-test, lint, create-tag]
if: needs.create-tag.outputs.should_tag == 'true'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Verify version matches
run: |
# Extract version from Cargo.toml
CARGO_VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
# Extract version from git tag
GIT_VERSION=${GITHUB_REF#refs/tags/v}
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $GIT_VERSION"
if [ "$CARGO_VERSION" != "$GIT_VERSION" ]; then
echo "Error: Version mismatch between Cargo.toml ($CARGO_VERSION) and git tag ($GIT_VERSION)"
exit 1
fi
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Copy download script
run: cp download_cli.sh dist/
- name: List artifacts
run: ls -la dist/
- name: Create GitHub Release
uses: softprops/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: dist/*
generate_release_notes: true
draft: false
prerelease: false