From f2c7e502cb4feedaddb7414c6f0ef38a2b08f29d Mon Sep 17 00:00:00 2001 From: kpym Date: Sun, 11 Oct 2020 12:02:14 +0200 Subject: [PATCH] use goreleaser and new help --- .github/workflows/release.yml | 47 ++++++++++++++++------------------- .gitignore | 1 + .goreleaser.yml | 37 +++++++++++++++++++++++++++ main.go | 10 ++++++++ 4 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bf98f19..7b051b3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,37 +1,34 @@ # workflow name -name: release +name: goreleaser + + + # on events on: - release: - types: - - created + push: + tags: + - '*' -# jobs jobs: - # generate build cross-platform build files - generate: - name: Generate cross-platform builds + goreleaser: runs-on: ubuntu-latest steps: - # step 1: checkout repository code - - name: Checkout the repository + - + name: Checkout uses: actions/checkout@v2 - - # step 2: generate build files - - name: Generate build files - uses: thatisuday/go-build-action@v1 with: - platforms: "linux/amd64, darwin/amd64, windows/amd64" - package: "" - name: "urlencode" - compress: "true" - dest: "dist" - - # step 3: upload build-artifacts - - name: Upload build-artifacts - uses: skx/github-action-publish-binaries@master + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.15 + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: "./dist/*.tar.gz" diff --git a/.gitignore b/.gitignore index 1feae78..0ac6e46 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.exe +dist diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..c7fc13a --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,37 @@ +# This is an example goreleaser.yaml file with some sane defaults. +# Make sure to check the documentation at http://goreleaser.com +before: + hooks: + # You may remove this if you don't use go modules. + - go mod download + # you may remove this if you don't need go generate + - go generate ./... +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - -s -w -X main.version={{.Version}} +archives: + - replacements: + darwin: MacOS + linux: Linux + windows: Windows + 386: 32bit + amd64: 64bit + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ .Tag }}" +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' diff --git a/main.go b/main.go index 082438f..b0298bc 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,15 @@ package main import ( "flag" + "fmt" "io/ioutil" "net/url" "os" "strings" ) +var version string = "--" + func restoreSpaces(s string) string { return strings.ReplaceAll(strings.ReplaceAll(s, "%20", " "), "+", " ") } @@ -18,6 +21,13 @@ func main() { keepSpaces := flag.Bool("keep-spaces", false, "keep spaces as they are") usePathEscape := flag.Bool("path-escape", false, "use PathEscape in place of QueryEscape") trimSpaces := flag.Bool("trim", false, "trim (from both sides) spaces and new lines") + // Help message + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "urlencode (version: %s, executable: %s)\n\n", version, os.Args[0]) + fmt.Fprintf(os.Stderr, "This program is a thin wrapper around the standard go url escape functions.\nAvailable flgs:\n\n") + flag.PrintDefaults() + fmt.Fprintf(os.Stderr, "\n") + } // parse flags flag.Parse()