Skip to content

Commit a75e08a

Browse files
committed
feat: configure releases and versioning
1 parent 33a9514 commit a75e08a

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed

.github/workflows/release.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
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+
20+
- name: Install Nix
21+
uses: cachix/install-nix-action@v30
22+
with:
23+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
24+
25+
- name: Run GoReleaser
26+
run: nix develop --command goreleaser release --clean
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.goreleaser.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 below 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+
version: 2
10+
11+
before:
12+
hooks:
13+
- go mod tidy
14+
15+
builds:
16+
- env:
17+
- CGO_ENABLED=0
18+
goos:
19+
- linux
20+
- darwin
21+
goarch:
22+
- amd64
23+
- arm64
24+
binary: nix-auth
25+
ldflags:
26+
- -s -w -X github.com/numtide/nix-auth/internal/version.Version={{.Version}} -X github.com/numtide/nix-auth/internal/version.Commit={{.Commit}} -X github.com/numtide/nix-auth/internal/version.Date={{.Date}}
27+
28+
archives:
29+
- # this name template makes the OS and Arch compatible with the results of `uname`.
30+
name_template: >-
31+
{{ .ProjectName }}_
32+
{{- title .Os }}_
33+
{{- if eq .Arch "amd64" }}x86_64
34+
{{- else if eq .Arch "386" }}i386
35+
{{- else }}{{ .Arch }}{{ end }}
36+
{{- if .Arm }}v{{ .Arm }}{{ end }}
37+
38+
changelog:
39+
sort: asc
40+
filters:
41+
exclude:
42+
- "^docs:"
43+
- "^test:"
44+
- "^chore:"
45+
- "^ci:"
46+
- "^Merge"
47+
48+
checksum:
49+
name_template: 'checksums.txt'
50+
51+
snapshot:
52+
version_template: "{{ incpatch .Version }}-next"
53+
54+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json

cmd/version.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/numtide/nix-auth/internal/version"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var versionCmd = &cobra.Command{
11+
Use: "version",
12+
Short: "Display version information",
13+
Run: func(_ *cobra.Command, _ []string) {
14+
fmt.Println(version.Full())
15+
},
16+
}
17+
18+
func init() {
19+
rootCmd.AddCommand(versionCmd)
20+
}

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
go-tools
3939
golangci-lint
4040
gopls
41+
goreleaser
4142
];
4243
};
4344
});

internal/version/version.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Package version provides version information for nix-auth.
2+
package version
3+
4+
import "fmt"
5+
6+
var (
7+
// Version is the main version number that is being run at the moment.
8+
Version = "dev"
9+
10+
// Commit is the git commit that was compiled. This will be filled in by the compiler.
11+
Commit = "none"
12+
13+
// Date is the build date in RFC3339 format.
14+
Date = "unknown"
15+
)
16+
17+
// String returns the complete version string.
18+
func String() string {
19+
if Version == "dev" {
20+
return fmt.Sprintf("%s (commit: %s, built at: %s)", Version, Commit, Date)
21+
}
22+
23+
return Version
24+
}
25+
26+
// Full returns the full version information.
27+
func Full() string {
28+
return fmt.Sprintf("nix-auth %s\ncommit: %s\nbuilt at: %s", Version, Commit, Date)
29+
}

0 commit comments

Comments
 (0)