From 67294b87ce48756f4ed8fa3689530910155ac699 Mon Sep 17 00:00:00 2001 From: Chris Kuehl Date: Fri, 30 Aug 2024 00:39:00 -0500 Subject: [PATCH] Add goreleaser and CLI publish workflow --- .github/workflows/publish-cli.yaml | 40 ++++++++++++++++++++++++++++++ .goreleaser.yaml | 30 ++++++++++++++++++++++ cli/main.go | 12 ++++----- 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish-cli.yaml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/publish-cli.yaml b/.github/workflows/publish-cli.yaml new file mode 100644 index 0000000..553ad06 --- /dev/null +++ b/.github/workflows/publish-cli.yaml @@ -0,0 +1,40 @@ +name: Publish Release CLI + +on: + push: + tags: + - cli/v* + release: + types: + - published + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + - name: Set VERSION + run: | + TAG="${{ github.event.inputs.version || github.ref_name }}" + # Get rid of the tag since the cli/ prefix confuses goreleaser. + git tag -d $TAG + echo VERSION=${TAG#cli/v} >> $GITHUB_ENV + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + distribution: goreleaser + version: '~> v2' + args: release --clean --snapshot --verbose + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload assets + uses: actions/upload-artifact@v4 + with: + name: release + path: dist/* diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..a1d7239 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,30 @@ +version: 2 +snapshot: + name_template: '{{.Env.VERSION}}' +builds: + - id: cli + main: ./cli + no_unique_dist_dir: true + binary: fput-{{.Os}}-{{.Arch}} +archives: +- format: binary +nfpms: + - id: cli + package_name: fluffy + builds: + - cli + homepage: 'https://github.com/chriskuehl/fluffy' + maintainer: 'Chris Kuehl ' + description: 'command-line tools for uploading to fluffy servers' + license: Apache-2.0 + formats: + - deb + - rpm + - archlinux + contents: + - src: /usr/bin/fput-{{.Os}}-{{.Arch}} + dst: /usr/bin/fpb + type: symlink + - src: /usr/bin/fput-{{.Os}}-{{.Arch}} + dst: /usr/bin/fput + type: symlink diff --git a/cli/main.go b/cli/main.go index 7e060b3..aa83799 100644 --- a/cli/main.go +++ b/cli/main.go @@ -412,19 +412,19 @@ func (v *regexpValue) Type() string { var regex = regexpValue{} // This will be set by the linker for release builds. -var Version string +var version string func init() { buildInfo, ok := debug.ReadBuildInfo() if !ok { panic("could not read build info") } - if Version == "" { - Version = buildInfo.Main.Version + if version == "" { + version = buildInfo.Main.Version } - version := fmt.Sprintf("%s/%s", Version, buildInfo.GoVersion) - fpbCommand.Version = version - fputCommand.Version = version + versionString := fmt.Sprintf("%s/%s", version, buildInfo.GoVersion) + fpbCommand.Version = versionString + fputCommand.Version = versionString settings, err := getSettings() if err != nil {