Skip to content

Commit

Permalink
ci: add release automation
Browse files Browse the repository at this point in the history
  • Loading branch information
werne2j committed Jun 28, 2021
1 parent a68c9a3 commit b91d267
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})

{{ range .CommitGroups -}}
### {{ .Title }}

{{ range .Commits -}}
* {{ .Subject }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}

{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
21 changes: 21 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/IBM/argocd-vault-plugin
options:
commits:
filters:
Type:
- feat
- fix
- perf
- refactor
header:
pattern: "^(\\w*)\\:\\s(.*)$"
pattern_maps:
- Type
- Subject
notes:
keywords:
- BREAKING CHANGE
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

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

- name: Set Tag
id: tag
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Install git-chglog
run: GO111MODULE=off go get github.com/git-chglog/git-chglog/cmd/git-chglog

- name: generate changelog
run: |
$(go env GOPATH)/bin/git-chglog \
-c .chglog/config.yml \
-o RELEASE_CHANGELOG.md \
${{ steps.tag.outputs.tag }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist --release-notes=RELEASE_CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
argocd-vault-plugin
RELEASE_CHANGELOG.md
bin
.DS_Store
.chglog
test
cover.out

# Project workspaces
.idea
.vscode
.vscode
27 changes: 27 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
project_name: "argocd-vault-plugin"

builds:
- binary: "argocd-vault-plugin"
flags: "-trimpath"
ldflags: >-
-s -w
-X "github.com/IBM/argocd-vault-plugin/version.Version={{.Tag}}"
-X "github.com/IBM/argocd-vault-plugin/version.BuildDate={{.Date}}"
-X "github.com/IBM/argocd-vault-plugin/version.CommitSHA={{.Commit}}"
env:
- "CGO_ENABLED=0"
goos:
- darwin
- linux
goarch:
- amd64
- arm64
tags:
- netgo
- static_build

archives:
- format: binary

changelog:
skip: true
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ quality:
build:
go build -o ${BINARY} .

release:
GOOS=darwin GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_darwin_amd64
GOOS=linux GOARCH=amd64 go build -o ./bin/${BINARY}_${VERSION}_linux_amd64

install: build

e2e: install
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewVersionCommand() *cobra.Command {
Use: "version",
Short: "Print argocd-vault-plugin version information",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.Version)
fmt.Fprintf(cmd.OutOrStdout(), "argocd-vault-plugin %s (%s) BuildDate: %s\n", version.Version, version.CommitSHA, version.BuildDate)
},
}

Expand Down
35 changes: 35 additions & 0 deletions cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"bytes"
"io/ioutil"
"strings"
"testing"

"github.com/IBM/argocd-vault-plugin/version"
)

func TestVersion(t *testing.T) {
t.Run("will show version", func(t *testing.T) {
args := []string{}
cmd := NewVersionCommand()

version.Version = "v0.0.1"
version.BuildDate = "1970-01-01T:00:00:00Z"
version.CommitSHA = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

c := bytes.NewBufferString("")
cmd.SetArgs(args)
cmd.SetOut(c)
cmd.Execute()
out, err := ioutil.ReadAll(c) // Read buffer to bytes
if err != nil {
t.Fatal(err)
}

expected := "argocd-vault-plugin v0.0.1 (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA) BuildDate: 1970-01-01T:00:00:00Z"
if !strings.Contains(string(out), expected) {
t.Fatalf("expected to contain: %s but got %s", expected, out)
}
})
}
8 changes: 7 additions & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@ package version

var (
// Version is the argocd-vault-plugin version.
Version = "v1.1.1"
Version string

// BuildDate is the date argocd-vault-plugin was built
BuildDate string

// CommitSHA is the commit argocd-vault-plugin was built from
CommitSHA string
)

0 comments on commit b91d267

Please sign in to comment.