Skip to content

Commit

Permalink
Add release action (#4)
Browse files Browse the repository at this point in the history
* Add release action

* Rename action(Test -> Release)

* check GITHUB_REF

* move Version vars, version to command package

* add goreleaser.yml

* Set command.Version when goreleaser build

* fix indent .goreleaser.yml

* escape ldflags option

* Change ldflags option

* Use version variable by GoReleaser

* Fix pass version variable

* Add cross compile option to goreleaser configuration

* Packaging only binary

* Tidyup Makefile and run target
  • Loading branch information
corrupt952 authored Nov 6, 2021
1 parent 39610c4 commit 174b6bf
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 22 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release

on:
push:
tags:
- '*'

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 changes: 13 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
builds:
- ldflags: -s -w -X "tmuxist/command.Version={{.Version}}"
goos:
- linux
- darwin
goarch:
- amd64

# Packging only binary
# FYI: https://goreleaser.com/customization/archive/#packaging-only-the-binaries
archives:
- files:
- none*
22 changes: 8 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
VERSION ?= 0.0.7
LDFLAGS ?= "-X github.com/corrupt952/tmuxist/version.Version=$(VERSION)"
LDFLAGS ?= -ldflags "-s -w -X 'tmuxist/command.Version=$(VERSION)'"

all: build
ARGS = $(filter-out $@,$(MAKECMDGOALS))
%:
@:

build: clean
gox -ldflags=$(LDFLAGS) -output="pkg/{{.OS}}_{{.Arch}}/{{.Dir}}" -osarch="darwin/amd64 linux/amd64"
all: run

run:
go run $(LDFLAGS) . $(ARGS)

fmt:
go fmt ./...
Expand All @@ -17,13 +21,3 @@ lint:

clean:
@rm -rf pkg/*

###
# for CI
package: build
cd pkg \
&& find * -type d | xargs -I{} tar -zcvf tmuxist_$(VERSION)_{}.tar.gz {}/tmuxist \
&& find * -type d | xargs -I{} rm -rf {}

release:
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} pkg
6 changes: 4 additions & 2 deletions command/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"fmt"

"github.com/google/subcommands"
)

"tmuxist/version"
var (
Version string
)

// VersionCommand represents a version command.
Expand All @@ -34,6 +36,6 @@ func (*VersionCommand) SetFlags(f *flag.FlagSet) {

// Execute executes print version and returns an ExitStatus.
func (*VersionCommand) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
fmt.Print(version.Version)
fmt.Println(Version)
return subcommands.ExitSuccess
}
6 changes: 0 additions & 6 deletions version/version.go

This file was deleted.

0 comments on commit 174b6bf

Please sign in to comment.