Skip to content

Commit

Permalink
feat: init goreleaser and github actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhop committed Sep 22, 2021
1 parent 4f01255 commit 527810f
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 18 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: goreleaser

on:
push:
tags:
- 'v*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Go Lint
run: |
go mod tidy
go test -v ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46 changes: 46 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
ldflags:
- -X github.com/tjhop/clip/cmd.builddate={{ .CommitDate }}
- -X github.com/tjhop/clip/cmd.version={{ .Version }}
- -X github.com/tjhop/clip/cmd.commit={{ .Commit }}
binary: clip
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
nfpms:
- package_name: 'clip'
homepage: 'https://github.com/tjhop/clip'
maintainer: 'TJ Hoplock <t.hoplock@gmail.com>'
description: 'Cross Platform CLI clipboard and templating tool'
formats:
- apk
- deb
- rpm
bindir: /usr/bin
contents:
- src: ./README.md
dst: /usr/share/doc/tjhop/clip/README.md
changelog:
sort: asc
filters:
exclude:
- '^Merge pull request'
- '^ci(?:\(\w+\))?\!?:'
- '^docs(?:\(\w+\))?\!?:'
- '^test(?:\(\w+\))?\!?:'
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,30 @@ tjhop
```

## Building
Builds are using `go1.12.1` with [gox](https://github.com/mitchellh/gox):

```shell
~/go/src/github.com/tjhop/clip -> COMMIT=$(git rev-parse --short HEAD | tr -d "[ \r\n\']");
TAG=$(git describe --always --tags --abbrev=0 | tr -d "[v\r\n]");
echo "commit: $COMMIT"; echo "tag: $TAG";
gox -ldflags="-X github.com/tjhop/clip/cmd.builddate=$(date +%Y-%m-%d)
-X github.com/tjhop/clip/cmd.version=$TAG
-X github.com/tjhop/clip/cmd.commit=$COMMIT" \
-osarch "linux/amd64" -output="$GOBIN/{{ .OS }}/{{ .Arch }}/clip" \
-osarch "darwin/amd64" -output="$GOBIN/{{ .OS }}/{{ .Arch }}/clip"
```

Release archive creation:
```shell
~/go/src/github.com/tjhop/clip -> tar vzcf "clip-$(git describe --always --tags --abbrev=0 | tr -d '[v\r\n]').darwin-amd64.tar.gz" -C $GOBIN/darwin/amd64/ -s /\./clip/g .
~/go/src/github.com/tjhop/clip -> tar vzcf "clip-$(git describe --always --tags --abbrev=0 | tr -d '[v\r\n]').linux-amd64.tar.gz" -C $GOBIN/linux/amd64/ -s /\./clip/g .
```
### Binaries
Binaries are built by [goreleaser and github actions](https://goreleaser.com/ci/actions/). Please see [Releases](#Releases) for more information on building binaries for release.

For testing purposes, binaries can be built manually, as well:
```shell
COMMIT=$(git rev-parse --short HEAD);
TAG=$(git describe --always --tags --abbrev=0 | tr -d "[v\r\n]");
go build -o clip -ldflags="-X github.com/tjhop/clip/cmd.builddate=$(date --iso-8601=seconds)
-X github.com/tjhop/clip/cmd.version=$TAG
-X github.com/tjhop/clip/cmd.commit=$COMMIT"
```

### Releases
Releases are handled by [goreleaser and github actions](https://goreleaser.com/ci/actions/).

In order to cut a release, a new semver tag must be pushed to the repo:
Note: It's highly recommended to install [SVU](https://github.com/caarlos0/svu) to help with tag creation.
```shell
git checkout master
git fetch --tags origin master
git tag $(svu next)
git push --tags upstream master
```
## TODO
- [ ] allow editing Clip config directly through `clip` commands like template files?
Expand Down

0 comments on commit 527810f

Please sign in to comment.