Skip to content

Commit f52fe58

Browse files
committed
Add goreleaser github action
1 parent 8c9ef54 commit f52fe58

File tree

4 files changed

+90
-21
lines changed

4 files changed

+90
-21
lines changed

.github/workflows/go-releaser.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
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@v4
17+
with:
18+
fetch-depth: 0
19+
- name: Set up Go
20+
uses: actions/setup-go@v4
21+
with:
22+
go-version: '1.21'
23+
- name: Run GoReleaser
24+
uses: goreleaser/goreleaser-action@v5
25+
with:
26+
# either 'goreleaser' (default) or 'goreleaser-pro'
27+
distribution: goreleaser
28+
version: latest
29+
args: release --clean
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
- name: Upload assets
33+
uses: actions/upload-artifact@v3
34+
with:
35+
name: gitfs
36+
path: dist/*

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
/dist/

.goreleaser.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines bellow are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
before:
10+
hooks:
11+
# You may remove this if you don't use go modules.
12+
- go mod tidy
13+
# you may remove this if you don't need go generate
14+
- go generate ./...
15+
16+
builds:
17+
- env:
18+
- CGO_ENABLED=0
19+
goos:
20+
- linux
21+
- darwin
22+
main: ./cmd/gitfs
23+
24+
archives:
25+
- format: tar.gz
26+
# this name template makes the OS and Arch compatible with the results of `uname`.
27+
name_template: >-
28+
{{ .ProjectName }}_
29+
{{- title .Os }}_
30+
{{- if eq .Arch "amd64" }}x86_64
31+
{{- else if eq .Arch "386" }}i386
32+
{{- else }}{{ .Arch }}{{ end }}
33+
{{- if .Arm }}v{{ .Arm }}{{ end }}
34+
# use zip for windows archives
35+
format_overrides:
36+
- goos: windows
37+
format: zip
38+
39+
changelog:
40+
sort: asc
41+
filters:
42+
exclude:
43+
- "^docs:"
44+
- "^test:"

cmd/gitfs/version.go

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,27 @@ import (
44
"fmt"
55
"github.com/spf13/cobra"
66
"runtime/debug"
7-
"time"
87
)
98

9+
var version string
10+
1011
var versionCmd = &cobra.Command{
1112
Use: "version",
1213
Short: "Print version information",
1314
Run: func(cmd *cobra.Command, args []string) {
14-
fmt.Println(getVersionString())
15+
cmd.Println(getVersionString())
1516
},
1617
}
1718

1819
func getVersionString() string {
20+
if version != "" {
21+
return fmt.Sprintf("gitfs: v%s", version)
22+
}
23+
1924
info, ok := debug.ReadBuildInfo()
2025
if !ok {
2126
return "gitfs: unknown version"
2227
}
23-
var revision string
24-
var lastCommit time.Time
2528

26-
for _, kv := range info.Settings {
27-
switch kv.Key {
28-
case "vcs.revision":
29-
revision = kv.Value
30-
case "vcs.time":
31-
lastCommit, _ = time.Parse(time.RFC3339, kv.Value)
32-
}
33-
}
34-
if revision == "" {
35-
return fmt.Sprintf("gitfs: version %s", info.Main.Version)
36-
}
37-
return fmt.Sprintf(
38-
"gitfs: version %s, build %s",
39-
revision,
40-
lastCommit,
41-
)
29+
return fmt.Sprintf("gitfs: %s", info.Main.Version)
4230
}

0 commit comments

Comments
 (0)