Skip to content

Commit e5a6b2e

Browse files
committed
goreleaser and workflow
1 parent eb99bec commit e5a6b2e

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

.github/workflows/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
push:
6+
tags:
7+
- 'v*.*.*'
8+
9+
jobs:
10+
goreleaser:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Set up Go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: 1.14
19+
- name: Run GoReleaser
20+
uses: goreleaser/goreleaser-action@v2
21+
with:
22+
version: latest
23+
args: release --rm-dist
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
env:
2+
- CGO_ENABLED=0
3+
- GOFLAGS=-mod=vendor
4+
- GO111MODULE=auto
5+
6+
before:
7+
hooks:
8+
- go mod download
9+
- go mod vendor
10+
11+
builds:
12+
- id: binary
13+
goos:
14+
- linux
15+
- darwin
16+
- windows
17+
goarch:
18+
- amd64
19+
ldflags:
20+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} -X main.builtBy=GoReleaser
21+
22+
archives:
23+
- builds:
24+
- binary
25+
replacements:
26+
darwin: Darwin
27+
linux: Linux
28+
windows: Windows
29+
386: x86
30+
amd64: x86_64
31+
format_overrides:
32+
- goos: windows
33+
format: zip
34+
files: ["LICENSE"]
35+
36+
checksum:
37+
name_template: 'checksums.txt'
38+
algorithm: sha256
39+
40+
snapshot:
41+
name_template: "{{ .Tag }}-next"
42+
43+
changelog:
44+
sort: asc
45+
filters:
46+
exclude:
47+
- '^docs:'
48+
- '^test:'

main.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
package main
22

33
import (
4+
"fmt"
45
"github.com/briandowns/spinner"
56
"github.com/spf13/cobra"
7+
"runtime"
68
"time"
79
)
810

911
var Spinner = spinner.New(spinner.CharSets[43], 100*time.Millisecond)
1012
var Log = NewLogger()
1113

14+
var (
15+
version = "dev"
16+
commit = "none"
17+
date = "unknown"
18+
builtBy = "unknown"
19+
)
20+
1221
func main() {
1322

1423
var file string
1524
var path string
1625
var share bool
26+
var info = fmt.Sprintf(
27+
"code-playground %s (%s, %s, %s) on %s (%s)",
28+
version,
29+
builtBy,
30+
date,
31+
commit,
32+
runtime.GOOS,
33+
runtime.GOARCH,
34+
)
1735

1836
var evaluate = func(playground IPlayground) {
1937

@@ -74,12 +92,21 @@ func main() {
7492
},
7593
}
7694

95+
var versionCmd = &cobra.Command{
96+
Use: "version",
97+
Short: "Print the version number of Gaos",
98+
Run: func(cmd *cobra.Command, args []string) {
99+
100+
fmt.Println(info)
101+
},
102+
}
103+
77104
goCmd.Flags().BoolVarP(&share, "share", "s", false, "share playground")
78105
goCmd.Flags().StringVarP(&path, "import", "i", "", "import playground")
79106
rustCmd.Flags().BoolVarP(&share, "share", "s", false, "share playground")
80107
rustCmd.Flags().StringVarP(&path, "import", "i", "", "import playground")
81108

82-
cmd.AddCommand(goCmd, rustCmd)
109+
cmd.AddCommand(goCmd, rustCmd, versionCmd)
83110

84111
_ = cmd.Execute()
85112
}

0 commit comments

Comments
 (0)