Skip to content

Commit

Permalink
Add goreleaser github action
Browse files Browse the repository at this point in the history
  • Loading branch information
dsxack committed Sep 27, 2023
1 parent 8c9ef54 commit 3f88658
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 20 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/go-releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: 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@v4
with:
go-version: '1.21'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload assets
uses: actions/upload-artifact@v3
with:
name: gitfs
path: dist/*
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
/dist/
44 changes: 44 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines bellow 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

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
main: ./cmd/gitfs

archives:
- format: 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
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
26 changes: 7 additions & 19 deletions cmd/gitfs/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"github.com/spf13/cobra"
"runtime/debug"
"time"
)

var version string

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print version information",
Expand All @@ -16,27 +17,14 @@ var versionCmd = &cobra.Command{
}

func getVersionString() string {
if version != "" {
return fmt.Sprintf("gitfs: v%s", version)
}

info, ok := debug.ReadBuildInfo()
if !ok {
return "gitfs: unknown version"
}
var revision string
var lastCommit time.Time

for _, kv := range info.Settings {
switch kv.Key {
case "vcs.revision":
revision = kv.Value
case "vcs.time":
lastCommit, _ = time.Parse(time.RFC3339, kv.Value)
}
}
if revision == "" {
return fmt.Sprintf("gitfs: version %s", info.Main.Version)
}
return fmt.Sprintf(
"gitfs: version %s, build %s",
revision,
lastCommit,
)
return fmt.Sprintf("gitfs: %s", info.Main.Version)
}

0 comments on commit 3f88658

Please sign in to comment.