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
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Release

on:
push:
tags:
- "v*"

permissions:
contents: write

jobs:
goreleaser:
name: GoReleaser
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version-file: go.mod
cache: true

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5daf1e915a5f0af01ddbcd89a43b8061ff4f1a89 # v7
with:
distribution: goreleaser
# goreleaser/goreleaser@v2.16.0
# tag: 4d54523455df2818f4b10e3f0174168acc5c809e
# commit: d76fb400136f96af3aaa7202776257885c9a6097
version: v2.16.0
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
version: 2

project_name: git-wtclean

before:
hooks:
- go mod tidy

builds:
- id: git-wtclean
main: ./cmd/git-wtclean
binary: git-wtclean
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/rokuosan/git-wtclean/internal/wtclean.Version={{ .Version }}
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64

archives:
- id: git-wtclean
ids:
- git-wtclean
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
formats:
- tar.gz
format_overrides:
- goos: windows
formats:
- zip

checksum:
name_template: checksums.txt

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
10 changes: 10 additions & 0 deletions internal/wtclean/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ type Options struct {
Prune bool
Verbose bool
Help bool
Version bool
}

var Version = "dev"

type Runner interface {
Output(ctx context.Context, name string, args ...string) ([]byte, error)
}
Expand Down Expand Up @@ -53,6 +56,10 @@ func (a *App) Run(ctx context.Context, args []string) int {
Usage(a.stdout)
return 0
}
if opts.Version {
writef(a.stdout, "git-wtclean %s\n", Version)
return 0
}

summary, err := a.run(ctx, opts)
if err != nil {
Expand Down Expand Up @@ -205,6 +212,8 @@ func ParseArgs(args []string) (Options, error) {
opts.Prune = true
case "-v", "--verbose":
opts.Verbose = true
case "--version":
opts.Version = true
case "-h", "--help":
opts.Help = true
default:
Expand All @@ -227,6 +236,7 @@ Options:
-D Force remove worktrees with `+"`git worktree remove --force`"+`
--prune Run `+"`git worktree prune`"+` for each ghq repository
-v, --verbose Print each repository while pruning
--version Show version
-h Show this help

Note:
Expand Down
16 changes: 16 additions & 0 deletions internal/wtclean/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ func TestRunRejectsMultipleDeleteOptions(t *testing.T) {
}
}

func TestRunVersionPrintsVersion(t *testing.T) {
app, runner, stdout, stderr := newTestApp()

code := app.Run(context.Background(), []string{"--version"})

if code != 0 {
t.Fatalf("exit code = %d, stderr = %s", code, stderr.String())
}
if stdout.String() != "git-wtclean dev\n" {
t.Fatalf("stdout = %q, want %q", stdout.String(), "git-wtclean dev\n")
}
if len(runner.calls) != 0 {
t.Fatalf("calls = %#v, want none", runner.calls)
}
}

func newTestApp() (*App, *fakeRunner, *bytes.Buffer, *bytes.Buffer) {
runner := &fakeRunner{}
var stdout bytes.Buffer
Expand Down
1 change: 1 addition & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[tools]
go = "1.26.4"
golangci-lint = "2.12.2"
goreleaser = "latest"
shellcheck = "latest"

[tasks.format]
Expand Down