From 7f8c0ac831c8cdeb61eb6d19efb2d1cfb38bb9bb Mon Sep 17 00:00:00 2001 From: Zhiqiang ZHOU Date: Sat, 24 May 2025 19:40:59 -0700 Subject: [PATCH 1/2] chore: setup goreleaser and minor fix --- .gitignore | 2 ++ .goreleaser.yaml | 56 ++++++++++++++++++++++++++++++++++++++++++++++ pkg/cloudflared.go | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 .goreleaser.yaml diff --git a/.gitignore b/.gitignore index 81fc6fc..f87ba11 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ go.work.sum .env out +# Added by goreleaser init: +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..2e9bfa9 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,56 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 2 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + goarch: + - amd64 + - arm64 + main: ./cmd/shell-now + +archives: + - formats: [tar.gz] + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + formats: [zip] + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" + +release: + footer: >- + + --- + + Released by [GoReleaser](https://github.com/goreleaser/goreleaser). diff --git a/pkg/cloudflared.go b/pkg/cloudflared.go index a093ce2..4cc04d0 100644 --- a/pkg/cloudflared.go +++ b/pkg/cloudflared.go @@ -58,10 +58,10 @@ func startCloudflared( } else { var err error cloudflaredStderr, err = cmd.StderrPipe() - defer cloudflaredStderr.Close() if err != nil { return fmt.Errorf("get stderr pipe from cloudflared: %w", err) } + defer cloudflaredStderr.Close() } go func() { From 2b8e11169439d6b0f6d40b169ff0a7b8c971027e Mon Sep 17 00:00:00 2001 From: Zhiqiang ZHOU Date: Sun, 25 May 2025 12:26:41 -0700 Subject: [PATCH 2/2] ci: setup go releaser github actions --- .github/workflows/release.yml | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7c9d4d3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +# .github/workflows/release.yml +name: goreleaser + +on: + pull_request: + push: + # run only against tags + tags: + - "*" + +permissions: + contents: write + packages: write + # issues: write + # id-token: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: stable + # More assembly might be required: Docker logins, GPG, etc. + # It all depends on your needs. + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v6 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + # 'latest', 'nightly', or a semver + version: "~> v2" + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution + # GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}