Skip to content

Commit

Permalink
Merge branch 'deb' (fix #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Apr 5, 2024
2 parents dfe0547 + 87b29ea commit 092e8ea
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 10 deletions.
37 changes: 35 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
files: ${{ steps.info.outputs.zip }}
if: ${{ github.event_name != 'workflow_dispatch' }}
- name: Upload release artifact for dry-run
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.info.outputs.asset_dir }}
path: ${{ steps.info.outputs.asset_dir }}
Expand Down Expand Up @@ -141,11 +141,44 @@ jobs:
files: ${{ steps.info.outputs.zip }}
if: ${{ github.event_name != 'workflow_dispatch' }}
- name: Upload release artifact for dry-run
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.info.outputs.asset_dir }}
path: ${{ steps.info.outputs.asset_dir }}
if: ${{ github.event_name == 'workflow_dispatch' }}
debian:
name: Upload Debian package
runs-on: ubuntu-latest
steps:
- name: Collect build information
id: info
# $GITHUB_REF will have a value like "refs/tags/0.3.1". Extract "0.3.1" from it
run: |
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "version=v0.0.0" >> "$GITHUB_OUTPUT"
else
echo "version=${GITHUB_REF##refs/tags/}" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cargo-deb
- run: cargo build --release
- run: target/release/hgrep --generate-completion-script bash > target/release/hgrep.bash
- run: target/release/hgrep --generate-man-page > target/release/hgrep.1
- run: cargo deb
- uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.info.outputs.version }}
draft: false
prerelease: false
files: target/debian/hgrep_*.deb
if: ${{ github.event_name != 'workflow_dispatch' }}
- name: Upload release artifact for dry-run
uses: actions/upload-artifact@v4
with:
name: hgrep_${{ steps.info.outputs.version }}_amd64.deb
path: target/debian/hgrep_*.deb
if: ${{ github.event_name == 'workflow_dispatch' }}
homebrew:
name: Update Homebrew formula
needs: [upload]
Expand Down
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ git add testdata/snapshots
These snapshot tests were added because `clap`'s major changes caused some regressions. `clap`'s major version bump caused API
breaking changes frequently and it was hard to follow them without tests.

## How to generate `.deb` file

[cargo-deb][] needs to be installed. The `.deb` package metadata is described in `[package.metadata.deb]` section in
[Cargo.toml](./Cargo.toml).

The `.deb` file contains a manual file for `man` and a Bash completion file. You need to generate them in advance.

```sh
cargo build --release
# Create a manual file
target/release/hgrep --generate-man-page > target/release/hgrep.1
# Create a Bash completion file
target/release/hgrep --generate-completion-script bash > target/release/hgrep.bash
# Generate `.deb` file at `target/debian/`
cargo deb
# Try to install the package
sudo dpkg -i target/debian/hgrep_*.deb
```

These build steps should be done on Linux. I haven't tried cross compilation.

The release CI workflow automatically builds `.deb` file and uploads it to [the GitHub releases page][releases] so usually you
don't need to build it manually.

## Make a new release

Let's say we're releasing v1.2.3.
Expand Down Expand Up @@ -102,6 +126,7 @@ Syntax set and theme set are managed in [./assets](./assets) directory. See [the
[clippy]: https://github.com/rust-lang/rust-clippy
[rustfmt]: https://github.com/rust-lang/rustfmt
[repo]: https://github.com/rhysd/hgrep
[cargo-deb]: https://github.com/kornelski/cargo-deb
[release-ci]: ./.github/workflows/release.yml
[releases]: https://github.com/rhysd/hgrep/releases
[changelog-from-release]: https://github.com/rhysd/changelog-from-release
Expand Down
10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,13 @@ insta = "1.38.0"
lazy_static = "1.4"
pretty_assertions = "1"
regex = "1.10.4"

[package.metadata.deb]
copyright = "Copyright (c) 2021 rhysd"
license-file = ["LICENSE.txt", "0"]
assets = [
["target/release/hgrep", "usr/bin/", "755"],
["README.md", "usr/share/doc/hgrep/README", "644"],
["target/release/hgrep.1", "usr/share/man/man1/hgrep.1", "644"],
["target/release/hgrep.bash", "usr/share/bash-completion/completions/hgrep", "644"],
]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ cd /usr/pkgsrc/textproc/hgrep
make install
```

### Via [APT][apt] package manager on Debian or Ubuntu

Visit [the releases page][releases] and download `.deb` package file. It can be installed via `dpkg` command:

```sh
sudo dpkg -i hgrep_v0.3.5_amd64.deb
```

The manual (for `man` command) and Bash completion is automatically installed. If you're using some other shell, setup the shell
completion by yourself. See ['Generate completion scripts' section](#gen-completion-scripts) for more details.

### Via [cargo][] package manager

```sh
Expand Down Expand Up @@ -354,6 +365,8 @@ $Env:HGREP_DEFAULT_OPTS = "--glob '!C:\Program Files'"

See `--help` for the full list of available options in your environment.


<a name="gen-completion-scripts"></a>
### Generate completion scripts

Shell completion script for `hgrep` command is available. `--generate-completion-script` option generates completion script and
Expand Down Expand Up @@ -493,6 +506,7 @@ hgrep is distributed under [the MIT license](./LICENSE.txt).
[nushell]: https://www.nushell.sh/
[homebrew]: https://brew.sh/
[macports]: https://www.macports.org/
[apt]: https://www.debian.org/doc/manuals/debian-faq/pkgtools.html
[new-issue]: https://github.com/rhysd/hgrep/issues/new
[syntect]: https://github.com/trishume/syntect
[bat-vs-syntect]: #bat-printer-vs-syntect-printer
Expand Down
11 changes: 3 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ impl Args {
let env = match env::var(OPTS_ENV_VAR) {
Ok(var) => {
let Some(mut opts) = shlex::split(&var) else {
anyhow::bail!("String in `{}` environment variable cannot be parsed as a shell command: {:?}", OPTS_ENV_VAR, var);
anyhow::bail!("String in `{OPTS_ENV_VAR}` environment variable cannot be parsed as a shell command: {var:?}");
};
opts.reverse();
opts
}
Err(env::VarError::NotPresent) => vec![],
Err(env::VarError::NotUnicode(invalid)) => {
anyhow::bail!(
"String in `{}` environment variable is not a valid UTF-8 sequence: {:?}",
OPTS_ENV_VAR,
invalid,
);
anyhow::bail!("String in `{OPTS_ENV_VAR}` environment variable is not a valid UTF-8 sequence: {invalid:?}");
}
};

Expand Down Expand Up @@ -1080,8 +1076,7 @@ mod tests {
let mut settings = insta::Settings::clone_current();
settings.set_snapshot_path(SNAPSHOT_DIR);
settings.bind(|| {
let cmd = command();
let mat = cmd.try_get_matches_from($args).unwrap();
let mat = command().try_get_matches_from($args).unwrap();
let err = build_ripgrep_config(3, 6, &mat).unwrap_err();
let mut msg = format!("{err}");
for err in err.chain().skip(1) {
Expand Down

0 comments on commit 092e8ea

Please sign in to comment.