Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
check:
name: Check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo build --release
- run: cargo test

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- run: cargo clippy -- -D warnings
- run: cargo fmt --check
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Release

on:
push:
tags: ["v*"]

permissions:
contents: write

jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
- run: cargo build --release --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
run: |
cd target/${{ matrix.target }}/release
tar czf ../../../fledge-plugin-gitleaks-${{ matrix.target }}.tar.gz fledge-gitleaks
- name: Package (Windows)
if: runner.os == 'Windows'
run: |
cd target/${{ matrix.target }}/release
7z a ../../../fledge-plugin-gitleaks-${{ matrix.target }}.zip fledge-gitleaks.exe
- uses: softprops/action-gh-release@v2
with:
files: |
fledge-plugin-gitleaks-*.tar.gz
fledge-plugin-gitleaks-*.zip
17 changes: 14 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ fn run_scan(staged: bool, strict: bool) -> Result<bool> {
let version = require_gitleaks()?;

let cwd = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
let mode = if staged { "staged changes" } else { "working tree" };
let mode = if staged {
"staged changes"
} else {
"working tree"
};
println!("scanning {} in {}", mode, cwd.display());
println!(" using gitleaks {version}");

Expand Down Expand Up @@ -161,7 +165,12 @@ fn print_findings(findings: &[Finding], strict: bool) {
let location = if f.commit.is_empty() {
format!("{}:{}", f.file, f.start_line)
} else {
format!("{}:{} ({})", f.file, f.start_line, &f.commit[..7.min(f.commit.len())])
format!(
"{}:{} ({})",
f.file,
f.start_line,
&f.commit[..7.min(f.commit.len())]
)
};
println!(" - [{}] {}", f.rule_id, location);
println!(" {}", f.description);
Expand Down Expand Up @@ -250,7 +259,9 @@ fn uninstall_hook() -> Result<()> {
#[cfg(unix)]
fn make_executable(path: &Path) -> Result<()> {
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(path).context("reading hook permissions")?.permissions();
let mut perms = fs::metadata(path)
.context("reading hook permissions")?
.permissions();
perms.set_mode(0o755);
fs::set_permissions(path, perms).context("setting hook permissions")?;
Ok(())
Expand Down
Loading