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 b291fec
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 21 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/
46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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
flags:
- -buildvcs=true

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:"
21 changes: 1 addition & 20 deletions cmd/gitfs/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/spf13/cobra"
"runtime/debug"
"time"
)

var versionCmd = &cobra.Command{
Expand All @@ -20,23 +19,5 @@ func getVersionString() string {
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: version %s", info.Main.Version)
}

0 comments on commit b291fec

Please sign in to comment.