Skip to content

Commit

Permalink
introduce goreleaser
Browse files Browse the repository at this point in the history
  • Loading branch information
fho committed Nov 21, 2024
1 parent 30c2670 commit acf877e
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*.swo
*.orig

release/
dist/
71 changes: 71 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json

# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

version: 2

builds:
- main: cmd/directorius/main.go
env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- "-X main.Version={{ .Version }}"
goos:
- linux
goarch:
- amd64
mod_timestamp: '{{ .CommitTimestamp }}'

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 }}
wrap_in_directory: false
files:
# Do not include README.md and LICENCE file in archive
# (https://goreleaser-git-revert-1958-snapshot-auto.goreleaser.vercel.app/customization/archive/#packaging-only-the-binaries):
- none*
builds_info:
group: 0
owner: 0
mode: 0644

checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_SHA256SUMS"
algorithm: sha256
signs:
- artifacts: checksum
args:
- "--batch"
- "--pinentry-mode"
- "loopback"
- "--passphrase-fd"
- "0"
- "--local-user"
- "0xC8B381683DBCEDFE"
- "--output"
- "${signature}"
- "--detach-sign"
- "${artifact}"
stdin: '{{ .Env.GPG_PASSWORD }}'

release:
draft: true
prerelease: auto

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
54 changes: 4 additions & 50 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,8 @@
GIT_COMMIT := $(shell git rev-parse HEAD)
GIT_DIRTY := $(if $(shell git diff-files),-dirty)
BUILDFLAGS := -trimpath

LDFLAGS := "-X main.Version=$(GIT_COMMIT)$(GIT_DIRTY)"
BUILDFLAGS := -trimpath -ldflags=$(LDFLAGS)

TARFLAGS := --mode=go=rX,u+rw,a-s --sort=name --owner=0 --group=0 --numeric-owner

BIN = directorius
RELEASE_ARCHIVE = release/directorius-linux_amd64.tar.xz

SRC = cmd/directorius/main.go

export GO111MODULE=on
export GOFLAGS=-mod=vendor

.PHONY: all
all: release_bin

.PHONY: release_bin
release_bin:
$(info * compiling $(BIN))
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(BUILDFLAGS) -o $(BIN) $(SRC)

.PHONY: release
release: clean dirty_worktree_check release_bin $(RELEASE_ARCHIVE) $(RELEASE_ARCHIVE).sha256
@echo
@echo next steps:
@echo - git tag vVERSION
@echo - git push --tags
@echo - upload $$(ls release/*) files

$(RELEASE_ARCHIVE):
$(info * creating $@)
@mkdir -p release
@tar $(TARFLAGS) -cJf $(RELEASE_ARCHIVE) directorius dist/ README.md

$(RELEASE_ARCHIVE).sha256: $(RELEASE_ARCHIVE)
$(info * creating $@)
@(cd $(dir $(RELEASE_ARCHIVE)) && sha256sum $(notdir $(RELEASE_ARCHIVE) > $@))

.PHONY: clean
clean:
rm -rf $(BIN) release/

.PHONY: dirty_worktree_check
dirty_worktree_check:
@if ! git diff-files --quiet || git ls-files --other --directory --exclude-standard | grep ".*" > /dev/null ; then \
echo "remove untracked files and changed files in repository before creating a release, see 'git status'"; \
exit 1; \
fi
.PHONY: build
build:
CGO_ENABLED=0 go build -trimpath -o directorius cmd/directorius/main.go

.PHONY: gen_mocks
gen_mocks:
Expand Down
48 changes: 0 additions & 48 deletions dist/etc/directorius/config.toml

This file was deleted.

42 changes: 42 additions & 0 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Release

## How to Create a Release

1. Create a git tag for the new release

```sh
git tag v<MY-VERSION>
```

**ADVISE**: Do not push the tag. Instead let it be created by GitHub when
removing the draft status. This allows to eventually recreate + delete the
draft release without having the tags already on the on the git remote.

2. Import our GPG signing private key:
- retrieve the GPG private key password and store it in an environment
variable:

```sh
export GPG_PASSWORD="$(vault read -field=master-priv-key-password secret/gpg-key-platform)"
```

- import the signing key:

```sh
vault read -field=subkey-signing-priv-key secret/gpg-key-platform | \
gpg --batch --pinentry-mode loopback --passphrase "$GPG_PASSWORD" --import
```

3. Set the `GITHUB_TOKEN` environment variable:

```sh
export GITHUB_TOKEN=<MY-TOKEN>
```

4. Run goreleaser

```sh
goreleaser release
```

5. Review the draft release on GitHub.

0 comments on commit acf877e

Please sign in to comment.