Skip to content

Commit 338f9d3

Browse files
authored
Add goreleaser to release automatically CLI tool (#15)
* Add goreleaser to release automatically md2confl * Update release workflow name * Add build info by using idflags * Add lint ignore block
1 parent 5db56e3 commit 338f9d3

4 files changed

Lines changed: 119 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Release CLI Tool
2+
3+
on:
4+
push:
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.16
24+
25+
- name: Run GoReleaser
26+
uses: goreleaser/goreleaser-action@v2
27+
with:
28+
distribution: goreleaser
29+
version: latest
30+
args: release --rm-dist
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@
2323
release/
2424
vendor/
2525
_vendor-*
26+
dist/

.goreleaser.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
before:
2+
hooks:
3+
- go mod tidy
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
goos:
8+
- linux
9+
- windows
10+
- darwin
11+
ldflags:
12+
- -s -w -X github.com/kentaro-m/md2confl/cmd.version={{.Version}} -X github.com/kentaro-m/md2confl/cmd.commit={{.Commit}} -X github.com/kentaro-m/md2confl/cmd.date={{.Date}} -X github.com/kentaro-m/md2confl/cmd.builtBy=goreleaser
13+
archives:
14+
- replacements:
15+
darwin: Darwin
16+
linux: Linux
17+
windows: Windows
18+
386: i386
19+
amd64: x86_64
20+
checksum:
21+
name_template: 'checksums.txt'
22+
snapshot:
23+
name_template: "{{ .Tag }}-next"
24+
changelog:
25+
sort: asc
26+
filters:
27+
exclude:
28+
- '^docs:'
29+
- '^test:'
30+
brews:
31+
-
32+
name: md2confl
33+
34+
# NOTE: make sure the url_template, the token and given repo (github or gitlab) owner and name are from the
35+
# same kind. We will probably unify this in the next major version like it is done with scoop.
36+
37+
# GitHub/GitLab repository to push the formula to
38+
# Gitea is not supported yet, but the support coming
39+
tap:
40+
owner: kentaro-m
41+
name: homebrew-md2confl
42+
43+
# Template for the url which is determined by the given Token (github or gitlab)
44+
url_template: "http://github.com/kentaro-m/md2confl/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
45+
46+
# Git author used to commit to the repository.
47+
# Defaults are shown.
48+
commit_author:
49+
name: goreleaserbot
50+
email: goreleaser@carlosbecker.com
51+
52+
# Folder inside the repository to put the formula.
53+
# Default is the root folder.
54+
folder: Formula
55+
56+
# Your app's homepage.
57+
# Default is empty.
58+
homepage: "https://github.com/kentaro-m/md2confl"
59+
60+
# Template of your app's description.
61+
# Default is empty.
62+
description: "md2confl is a CLI tool to convert the markdown text to confluence wiki format."
63+
64+
# SPDX identifier of your app's license.
65+
# Default is empty.
66+
license: "MIT"
67+
68+
# So you can `brew test` your formula.
69+
# Default is empty.
70+
test: |
71+
system "#{bin}/md2confl --version"
72+
73+
# Custom install script for brew.
74+
# Default is 'bin.install "program"'.
75+
install: |
76+
bin.install "md2confl"

cmd/root.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ import (
1313
"golang.org/x/term"
1414
)
1515

16-
// Current version number
17-
const (
18-
VERSION = "0.2.0"
16+
//nolint // these variables are set in build step
17+
var (
18+
version = "dev"
19+
commit = "none"
20+
date = "unknown"
21+
builtBy = "unknown"
1922
)
2023

2124
var (
22-
version bool
25+
isShowVersion bool
2326
)
2427

2528
var rootCmd = &cobra.Command{
@@ -34,8 +37,8 @@ var rootCmd = &cobra.Command{
3437
// Run executes md2confl command
3538
func Run(cmd *cobra.Command, args []string) error {
3639

37-
if version {
38-
fmt.Fprintf(os.Stdout, "v%v\n", VERSION)
40+
if isShowVersion {
41+
fmt.Fprintf(os.Stdout, "v%v\n", version)
3942
return nil
4043
}
4144

@@ -78,7 +81,7 @@ func output(input []byte) {
7881

7982
func init() {
8083
cobra.EnableCommandSorting = false
81-
rootCmd.Flags().BoolVarP(&version, "version", "v", false, "Output the version number")
84+
rootCmd.Flags().BoolVarP(&isShowVersion, "version", "v", false, "Output the version number")
8285
}
8386

8487
// Execute runs the root Cmd

0 commit comments

Comments
 (0)