From d4b548c44a70a466ba2ea583e473efe8a04ef032 Mon Sep 17 00:00:00 2001 From: phm07 <22707808+phm07@users.noreply.github.com> Date: Thu, 15 Jan 2026 17:05:02 +0100 Subject: [PATCH] feat: build .deb and .rpm release files --- .gitignore | 2 ++ .goreleaser.yml | 70 ++++++++++++++++++++++++++++++++++-------- go.mod | 2 +- go.sum | 3 +- scripts/completions.sh | 7 +++++ scripts/manpages.go | 41 +++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 14 deletions(-) create mode 100755 scripts/completions.sh create mode 100644 scripts/manpages.go diff --git a/.gitignore b/.gitignore index d96ff5264..6ee2a7a15 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ /hcloud /dist /bats +/completions +/manpages /cmd/hcloud/hcloud hcloud_cli.p12 coverage.txt diff --git a/.goreleaser.yml b/.goreleaser.yml index 226c3f4d7..0c4ebf05d 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -2,6 +2,8 @@ version: 2 before: hooks: - go mod tidy + - ./scripts/completions.sh + - go run scripts/manpages.go builds: - <<: &build_defaults @@ -17,13 +19,26 @@ builds: env: - CGO_ENABLED=0 - id: hcloud-build - goos: [freebsd, windows, linux] + id: hcloud-build-linux-main + goos: [linux] + goarch: [amd64, arm64] + + - <<: *build_defaults + id: hcloud-build-linux-other + goos: [ linux ] + goarch: [ arm, "386" ] + goarm: [ "6", "7" ] + + - <<: *build_defaults + id: hcloud-build-freebsd + goos: [ freebsd ] goarch: [amd64, arm, arm64, "386"] goarm: ["6", "7"] - ignore: - - goos: windows - goarch: arm + + - <<: *build_defaults + id: hcloud-build-windows + goos: [ windows ] + goarch: [ amd64, arm64, "386" ] - <<: *build_defaults id: hcloud-build-darwin @@ -37,9 +52,46 @@ builds: - cmd: bash -c 'quill sign-and-notarize "{{ .Path }}" --dry-run={{ .IsSnapshot }} --ad-hoc={{ .IsSnapshot }} || touch sign-and-notarize.error' output: true +nfpms: + - id: default + file_name_template: "{{ .ConventionalFileName }}" + package_name: hcloud-cli + ids: [hcloud-build-linux-main] + provides: [hcloud] + vendor: Hetzner Cloud GmbH + homepage: https://github.com/hetznercloud/cli + maintainer: Hetzner Cloud GmbH + formats: + - deb + - rpm + description: A command-line interface for Hetzner Cloud + license: MIT + + contents: + - src: ./completions/hcloud.bash + dst: /usr/share/bash-completion/completions/hcloud + file_info: + mode: 0644 + - src: ./completions/hcloud.fish + dst: /usr/share/fish/vendor_completions.d/hcloud.fish + file_info: + mode: 0644 + - src: ./completions/hcloud.zsh + dst: /usr/share/zsh/vendor-completions/_hcloud + file_info: + mode: 0644 + - src: ./LICENSE + dst: /usr/share/doc/hcloud/license + file_info: + mode: 0644 + - src: ./manpages/* + dst: /usr/share/man/man1/ + file_info: + mode: 0644 + kos: - id: container-images - build: hcloud-build + build: hcloud-build-linux-main main: ./cmd/hcloud/ repositories: - hetznercloud/cli @@ -71,9 +123,6 @@ signs: - artifacts: all signature: ${artifact}.sig id: hcloud-sign - ids: - - hcloud-build - - hcloud-build-darwin args: - --batch - --local-user=github-bot@hetzner-cloud.de @@ -84,9 +133,6 @@ signs: archives: - id: hcloud-archive - ids: - - hcloud-build - - hcloud-build-darwin name_template: "{{ .Binary }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" format_overrides: diff --git a/go.mod b/go.mod index f568f6380..8f4dafd1a 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ toolchain go1.25.7 require ( github.com/BurntSushi/toml v1.6.0 github.com/cheggaaa/pb/v3 v3.1.7 + github.com/cpuguy83/go-md2man/v2 v2.0.7 github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.18.0 github.com/fatih/structs v1.1.0 @@ -33,7 +34,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bool64/shared v0.1.6 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/go-viper/mapstructure/v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 998df97a6..a3d40d98d 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,9 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cheggaaa/pb/v3 v3.1.7 h1:2FsIW307kt7A/rz/ZI2lvPO+v3wKazzE4K/0LtTWsOI= github.com/cheggaaa/pb/v3 v3.1.7/go.mod h1:/Ji89zfVPeC/u5j8ukD0MBPHt2bzTYp74lQ7KlgFWTQ= -github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/cpuguy83/go-md2man/v2 v2.0.7 h1:zbFlGlXEAKlwXpmvle3d8Oe3YnkKIK4xSRTd3sHPnBo= +github.com/cpuguy83/go-md2man/v2 v2.0.7/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= diff --git a/scripts/completions.sh b/scripts/completions.sh new file mode 100755 index 000000000..92af57207 --- /dev/null +++ b/scripts/completions.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -e +rm -rf completions +mkdir completions +for sh in bash zsh fish; do + go run ./cmd/hcloud completion "$sh" >"completions/hcloud.$sh" +done diff --git a/scripts/manpages.go b/scripts/manpages.go new file mode 100644 index 000000000..42b127374 --- /dev/null +++ b/scripts/manpages.go @@ -0,0 +1,41 @@ +package main + +import ( + "context" + "fmt" + "log" + "os" + // We import md2man here so we can keep it up to date in go.mod + _ "github.com/cpuguy83/go-md2man/v2/md2man" + + "github.com/spf13/cobra/doc" + + "github.com/hetznercloud/cli/internal/cli" + "github.com/hetznercloud/cli/internal/state" + "github.com/hetznercloud/cli/internal/state/config" + "github.com/hetznercloud/cli/internal/version" +) + +const directory = "./manpages" + +func main() { + //nolint:gosec + if err := os.MkdirAll(directory, 0755); err != nil { + log.Fatal(err) + } + + ctx := context.Background() + ctx = context.WithValue(ctx, state.ContextKeyMarkdownTables{}, true) + s, _ := state.New(ctx, config.New()) + rootCommand := cli.NewRootCommand(s) + + err := doc.GenManTree(rootCommand, &doc.GenManHeader{ + Source: version.Version, + Manual: "CLI for Hetzner API", + }, directory) + + if err != nil { + log.Fatal(err) + } + fmt.Println("Man pages generated successfully") +}