Skip to content

Commit

Permalink
feat: build releases using goreleaser
Browse files Browse the repository at this point in the history
michaeladler committed Sep 2, 2024
1 parent 2258a91 commit d5d3386
Showing 15 changed files with 267 additions and 166 deletions.
4 changes: 4 additions & 0 deletions .ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -eux
cargo build --release
cp -a target/release/notmuch-mailmover dist/notmuch-mailmover_linux_amd64_v1/
36 changes: 22 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- v[0-9]+.*
- "v*"

defaults:
run:
shell: bash
permissions:
contents: write

jobs:
create-release:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-go@v5 # for dummy.go
- uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Install build deps
run: sudo apt-get update -q && sudo apt-get install -y libnotmuch-dev

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
changelog: CHANGELOG.md
branch: "main|v[0-9]+"
draft: true
token: ${{ secrets.GITHUB_TOKEN }}
distribution: goreleaser
version: 'latest'
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
/result
/dist
/share
95 changes: 95 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: 2

project_name: notmuch-mailmover

builds:
- id: notmuch-mailmover
main: dummy.go
goarch:
- amd64
goos:
- linux
binary: notmuch-mailmover
hooks:
post: sh .ci/build.sh

archives:
- id: notmuch-mailmover
builds:
- notmuch-mailmover
name_template: >-
{{ .ProjectName }}_{{ .Version }}_
{{- if eq .Os "darwin" }}macOS
{{- else if eq .Os "linux" }}Linux
{{- else }}{{ .Os }}{{ end }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else }}{{ .Arch }}{{ end }}
format: tar.zst
files:
- LICENSE
- share

nfpms:
- id: notmuch-mailmover
package_name: notmuch-mailmover
builds:
- notmuch-mailmover
formats:
- deb
- rpm
- archlinux
maintainer: Michael Adler <[email protected]>
homepage: https://github.com/michaeladler/notmuch-mailmover
description: move notmuch tagged mails into Maildir folders
dependencies:
- notmuch
section: mail
priority: extra
contents:
# zsh completion
- src: share/_notmuch-mailmover
dst: /usr/share/zsh/site-functions/_notmuch-mailmover
# zsh completion for Debian
- src: /usr/share/zsh/site-functions/_notmuch-mailmover
dst: /usr/share/zsh/vendor-completions/_notmuch-mailmover
type: symlink
packager: deb

# bash completion
- src: share/notmuch-mailmover.bash
dst: /usr/share/bash-completion/completions/notmuch-mailmover

# fish completion
- src: share/notmuch-mailmover.fish
dst: /usr/share/fish/completions/notmuch-mailmover.fish

# man page
- src: share/notmuch-mailmover.1.gz
dst: /usr/share/man/man1/notmuch-mailmover.1.gz

# example config
- src: example/config.yaml
dst: /usr/share/doc/notmuch-mailmover/config.yaml

checksum:
name_template: 'checksums.txt'

release:
draft: true
replace_existing_draft: true

changelog:
sort: asc
groups:
- title: Features
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: "Bug fixes"
regexp: "^.*fix[(\\w)]*:+.*$"
order: 1
- title: Others
order: 999
filters:
exclude:
- "^docs:"
- "^test:"
22 changes: 0 additions & 22 deletions CHANGELOG.md

This file was deleted.

84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -32,12 +32,15 @@ directories = "5.0.1"
shellexpand = "3.0.0"
clap = { version = "4.5.13", features = [ "derive", "cargo" ] }
git-version = "0.3.9"
konst = "0.3"

[build-dependencies]
clap = { version = "4.5.13", features = [ "derive", "cargo" ] }
clap_complete = "4.5.13"
clap_mangen = "0.2.23"
git-version = "0.3.9"
flate2 = "1.0.17"
konst = "0.3"

[dev-dependencies]
regex = "1.10.6"
27 changes: 5 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -60,28 +60,11 @@ Then edit the file as you like, see below for an example.

## Example

Move all mails

* tagged as `trash` to folder `Trash`
* tagged as `sent` to folder `Sent`
* tagged as `archive` to folder `Archive`

`config.yaml`:

```yaml
maildir: ~/mail
# if omitted (or null), it will use the same as notmuch would, see notmuch-config(1)
notmuch_config: ~/.config/notmuch/notmuchrc
# only rename if you use mbsync
rename: true
rules:
- folder: Trash
query: tag:trash
- folder: Sent
query: tag:sent and not tag:trash
- folder: Archive
query: tag:archive and not tag:sent and not tag:trash
```
The provided [config.yaml](./example/config.yaml) does the following:

* move mails tagged as `trash` to folder `Trash`
* move mails tagged as `sent` to folder `Sent`
* move mails tagged as `archive` to folder `Archive`

**Note**: Queries **must not overlap** (hence the `and not tag:trash` clause in the second query).
This is to avoid moving files more than once and checked by notmuch-mailmover *before* any files are moved.
16 changes: 8 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::{
fs::{create_dir_all, File},
path::Path,
};

use clap::CommandFactory;
use clap_complete::{generate_to, Shell};
use clap_mangen::Man;
use flate2::write::GzEncoder;
use flate2::Compression;
use std::fs::{create_dir_all, File};
use std::path::Path;

include!("src/lib/cli.rs");

@@ -16,9 +15,10 @@ fn main() {
create_dir_all(out).unwrap();
let cmd = &mut Cli::command();

Man::new(cmd.clone())
.render(&mut File::create(out.join("notmuch-mailmover.1")).unwrap())
.unwrap();
let f = File::create(out.join("notmuch-mailmover.1.gz")).unwrap();
let mut encoder = GzEncoder::new(f, Compression::default());

Man::new(cmd.clone()).render(&mut encoder).unwrap();

for shell in Shell::value_variants() {
generate_to(*shell, cmd, "notmuch-mailmover", out).unwrap();
91 changes: 0 additions & 91 deletions cliff.toml

This file was deleted.

3 changes: 3 additions & 0 deletions dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

func main() {}
17 changes: 17 additions & 0 deletions example/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
maildir: ~/mail
# if omitted (or null), it will use the same as notmuch would, see notmuch-config(1)
notmuch_config: ~/.config/notmuch/notmuchrc
# only rename if you use mbsync
rename: true
rules:
# move mails tagged as `trash` to folder `Trash`
- folder: Trash
query: tag:trash

# move mails tagged as `sent` to folder `Sent`
- folder: Sent
query: tag:sent and not tag:trash

# move mails tagged as `archive` to folder `Archive`
- folder: Archive
query: tag:archive and not tag:sent and not tag:trash
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@
buildInputs = with pkgs; [ notmuch ];

postInstall = ''
installManPage share/notmuch-mailmover.1
installManPage share/notmuch-mailmover.1.gz
installShellCompletion --cmd notmuch-mailmover \
--bash share/notmuch-mailmover.bash \
--fish share/notmuch-mailmover.fish \
5 changes: 4 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -3,5 +3,8 @@
with pkgs;

mkShell {
buildInputs = [ notmuch ];
buildInputs = [
notmuch
nodePackages.markdown-link-check
];
}
26 changes: 19 additions & 7 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
use core::str;
use std::path::PathBuf;

use clap::{crate_authors, Parser, ValueEnum};

use git_version::git_version;

pub const VERSION: &str = git_version!(
cargo_prefix = "",
prefix = "",
// Note that on the CLI, the v* needs to be in single quotes
// When passed here though there seems to be some magic quoting that happens.
args = ["--always", "--dirty=-dirty", "--match=v*", "--tags"]
pub const VERSION: &[u8] = remove_leading_v(
git_version!(
cargo_prefix = "",
prefix = "",
// Note that on the CLI, the v* needs to be in single quotes
// When passed here though there seems to be some magic quoting that happens.
args = ["--always", "--dirty=-dirty", "--match=v*", "--tags"]
)
.as_bytes(),
);

const fn remove_leading_v(bytes: &[u8]) -> &[u8] {
if !bytes.is_empty() && bytes[0] == b'v' {
konst::slice::slice_from(bytes, 1)
} else {
bytes
}
}

#[derive(Parser)]
#[clap(
name = "notmuch-mailmover",
version = VERSION,
version = str::from_utf8( VERSION).unwrap(),
author = crate_authors!(),
)]
pub struct Cli {

0 comments on commit d5d3386

Please sign in to comment.