Skip to content
This repository has been archived by the owner on Aug 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from kachick/goreleaser
Browse files Browse the repository at this point in the history
Integrate goreleaser
  • Loading branch information
kachick committed Jun 19, 2023
2 parents cead825 + 570c169 commit 754791a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 9 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
if: startsWith(github.ref, 'refs/tags/')
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ go.work

# Binary
nix-headbump

dist/
45 changes: 45 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
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
- windows
- darwin

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
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(prepared bash)

> task
task: [build] go build -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
task: [build] ..."
task: [test] go test
task: [lint] dprint check
task: [lint] go vet
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ When I want to bump it, I always visit the nixpkgs repository and copy and paste
## Usage

```console
> go install -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
> go install -ldflags "-X main.commit=$(git rev-parse --short HEAD) -X main.date=$(date --iso-8601)"
> cd repository-that-using-nix
> ${GOPATH:-"$HOME/go"}/bin/nix-headbump && git commit -m 'Bump nixpkgs to latest' *.nix
[main 213d1bf] Bump nixpkgs to latest
Expand Down
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ tasks:
- task: build
install:
cmds:
- go install -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
- go install -ldflags "-X main.commit=$(git rev-parse HEAD) -X main.date=$(date --iso-8601)"
build:
cmds:
- go build -ldflags "-X main.revision=$(git rev-parse --short HEAD)"
- goreleaser build --snapshot --single-target --clean
test:
cmds:
- go test
Expand All @@ -34,3 +34,4 @@ tasks:
- go version
- dprint --version
- actionlint --version
goreleaser --version
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pkgs.mkShell {
pkgs.dprint
pkgs.actionlint
pkgs.go-task
pkgs.goreleaser
];
}
1 change: 1 addition & 0 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"singleQuote": true
},
"includes": ["**/*.{json,md,yml}"],
"excludes": ["dist"],
"plugins": [
"https://plugins.dprint.dev/json-0.17.1.wasm",
"https://plugins.dprint.dev/markdown-0.15.2.wasm",
Expand Down
13 changes: 8 additions & 5 deletions nix-headbump.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import (
"regexp"
)

const version string = "0.1.0"
var (
version = "dev"
commit = "none"
date = "unknown"

var re = regexp.MustCompile(`(?s)(import\s+\(fetchTarball\s+"https://github.com/NixOS/nixpkgs/archive/)([^"]+?)(\.tar\.gz"\))`)

var revision string
re = regexp.MustCompile(`(?s)(import\s+\(fetchTarball\s+"https://github.com/NixOS/nixpkgs/archive/)([^"]+?)(\.tar\.gz"\))`)
)

func main() {
versionFlag := flag.Bool("version", false, "print the version of this program")
Expand All @@ -25,7 +27,8 @@ func main() {
flag.Parse()

if *versionFlag {
fmt.Printf("%s\n", version+"("+revision+")")
revision := commit[:7]
fmt.Printf("%s\n", "nix-headbump"+" "+version+" "+"("+revision+") # "+date)
return
}

Expand Down

0 comments on commit 754791a

Please sign in to comment.