Skip to content

Commit f59c8f4

Browse files
authored
Improve developer experience: clippy, formatting, error handling (#11)
1 parent 298097e commit f59c8f4

15 files changed

Lines changed: 330 additions & 304 deletions

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
concurrency:
9+
group: ci-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
name: Lint
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: dtolnay/rust-toolchain@stable
20+
with:
21+
components: rustfmt, clippy
22+
23+
- uses: Swatinem/rust-cache@v2
24+
25+
- name: cargo fmt --check
26+
run: cargo fmt --check
27+
28+
- name: cargo clippy
29+
run: cargo clippy --tests -- -D warnings
30+
31+
test:
32+
name: Test
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- uses: dtolnay/rust-toolchain@stable
38+
39+
- uses: Swatinem/rust-cache@v2
40+
41+
- name: cargo test
42+
run: cargo test

.github/workflows/release.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ concurrency:
1010

1111
jobs:
1212
build-release:
13-
name: build-release ${{ matrix.os }} ${{ matrix.rust }} ${{ matrix.target }}
13+
name: build-release ${{ matrix.build }}
1414
runs-on: ${{ matrix.os }}
15-
timeout-minutes: 5
15+
timeout-minutes: 30
1616
strategy:
1717
matrix:
1818
include:
1919
- build: linux
20-
os: ubuntu-20.04
20+
os: ubuntu-22.04
2121
rust: stable
2222
target: x86_64-unknown-linux-musl
2323
- build: macos
2424
os: macos-latest
2525
rust: stable
26-
target: x86_64-apple-darwin
26+
target: x86_64-apple-darwin # cross-compiled on the arm64 runner
2727
- build: macos-arm64
2828
os: macos-latest
2929
rust: stable
30-
target: aarch64-apple-darwin
30+
target: aarch64-apple-darwin # native on the arm64 runner
3131
env:
3232
RUST_BACKTRACE: full
3333
TARGET_DIR: ./target
3434
steps:
3535
- name: Checkout repository
36-
uses: actions/checkout@v2
36+
uses: actions/checkout@v4
3737

3838
- name: Determine version changes
3939
id: version_check
@@ -56,18 +56,16 @@ jobs:
5656
fi
5757
5858
- name: Install packages (Ubuntu)
59-
if: steps.version_check.outputs.version_changed == 'true' && matrix.os == 'ubuntu-20.04'
59+
if: steps.version_check.outputs.version_changed == 'true' && matrix.os == 'ubuntu-22.04'
6060
run: |
6161
sudo apt-get update
6262
sudo apt-get install -y musl-tools
6363
6464
- name: Install Rust
6565
if: steps.version_check.outputs.version_changed == 'true'
66-
uses: actions-rs/toolchain@v1
66+
uses: dtolnay/rust-toolchain@master
6767
with:
6868
toolchain: ${{ matrix.rust }}
69-
profile: minimal
70-
override: true
7169

7270
- name: Build and Package
7371
if: steps.version_check.outputs.version_changed == 'true'

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: local
3+
hooks:
4+
- id: cargo-fmt
5+
name: cargo fmt
6+
entry: cargo fmt --
7+
language: system
8+
types: [rust]
9+
pass_filenames: false
10+
11+
- id: cargo-clippy
12+
name: cargo clippy
13+
entry: cargo clippy --tests -- -D warnings
14+
language: system
15+
types: [rust]
16+
pass_filenames: false
17+

.rustfmt.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
edition = "2021"
2+
max_width = 100
3+
use_small_heuristics = "Default"

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
name = "flopha"
33
version = "0.1.1"
44
edition = "2021"
5-
rust-version = "1.60.0"
5+
rust-version = "1.74.0"
66

77
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
88

99
[dependencies]
10-
git2 = "0.14"
11-
clap = { version = "3.1.18", features = ["derive"] }
12-
openssl = { version = "0.10", features = ["vendored"] } # to fix build error
10+
git2 = { version = "0.19", features = ["vendored-libgit2"] }
11+
clap = { version = "4", features = ["derive"] }
12+
openssl = { version = "0.10", features = ["vendored"] } # statically linked for portable binaries (musl, macOS)
1313
regex = "1.5"
14+
thiserror = "1"
15+
log = "0.4"
16+
env_logger = "0.11"
1417

1518
[dev-dependencies]
1619
url = "2.0"

src/cli.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ use crate::versioning::Increment;
55
#[derive(Parser)]
66
#[clap(author, version, about, long_about = None)]
77
pub struct Cli {
8-
#[clap(short = 'v', long = "version", action)]
8+
#[clap(short = 'V', long = "version", action)]
99
pub version: bool,
1010

11+
#[clap(
12+
short = 'v',
13+
long,
14+
action,
15+
global = true,
16+
help = "Enable verbose output"
17+
)]
18+
pub verbose: bool,
19+
1120
#[clap(subcommand)]
1221
pub command: Option<Commands>,
1322
}
@@ -36,13 +45,6 @@ pub struct NextVersionArgs {
3645
short = 'i'
3746
)]
3847
pub increment: Increment,
39-
#[clap(
40-
help = "Enable verbose output for detailed information",
41-
long,
42-
short = 'v',
43-
action
44-
)]
45-
pub verbose: bool,
4648
#[clap(
4749
help = "Specify a custom pattern for version matching and generation. \
4850
Use {major}, {minor}, and {patch} as placeholders. \
@@ -75,13 +77,6 @@ pub struct LastVersionArgs {
7577
short = 'p'
7678
)]
7779
pub pattern: Option<String>,
78-
#[clap(
79-
help = "Enable verbose output for detailed information",
80-
long,
81-
short = 'v',
82-
action
83-
)]
84-
pub verbose: bool,
8580
#[clap(
8681
help = "Specify the source for versioning: tag (default) or branch",
8782
long,

src/error.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use thiserror::Error;
2+
3+
#[derive(Debug, Error)]
4+
pub enum FlophaError {
5+
#[error("git error: {0}")]
6+
Git(#[from] git2::Error),
7+
#[error("failed to open repository at '{path}'")]
8+
RepoNotFound {
9+
path: String,
10+
#[source]
11+
source: git2::Error,
12+
},
13+
#[error("remote '{name}' not found")]
14+
RemoteNotFound {
15+
name: String,
16+
#[source]
17+
source: git2::Error,
18+
},
19+
#[error("version component '{{{0}}}' not present in pattern")]
20+
MissingVersionComponent(String),
21+
}

0 commit comments

Comments
 (0)