Skip to content

Commit

Permalink
cicd: automated changelog and release
Browse files Browse the repository at this point in the history
Signed-off-by: ldelossa <ldelossa@redhat.com>
  • Loading branch information
ldelossa authored and ldelossa committed Sep 11, 2020
1 parent 578c44c commit 31f7b03
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 2 deletions.
60 changes: 60 additions & 0 deletions .chglog/CHANGELOG.tpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{ if .Versions -}}
<a name="unreleased"></a>
## [Unreleased]

{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- [{{.Hash.Short}}]({{ $.Info.RepositoryURL }}/commit/{{ .Hash.Long }}): {{ .Subject }}
{{ if .Refs -}}{{ range .Refs }} -{{if .Action}}{{ .Action }} {{ end }} [#{{ .Ref }}]({{ $.Info.RepositoryURL }}/issues/{{ .Ref }}){{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}

{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- [{{.Hash.Short}}]({{ $.Info.RepositoryURL }}/commit/{{ .Hash.Long }}): {{ .Subject }}
{{ if .Refs -}}{{ range .Refs }} - {{if .Action}}{{ .Action }}{{ end }} [#{{ .Ref }}]({{ $.Info.RepositoryURL }}/issues/{{ .Ref }}){{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts
{{ range .RevertCommits -}}
- {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .MergeCommits -}}
### Pull Requests
{{ range .MergeCommits -}}
- {{ .Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}

{{- if .Versions }}
[Unreleased]: {{ .Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
29 changes: 29 additions & 0 deletions .chglog/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/go-jira/go-jira
options:
commits:
sort_by: Scope
commit_groups:
group_by: Scope
header:
pattern: '^(.*):\s*(.*)$'
pattern_maps:
- Scope
- Subject
issues:
prefix:
- "#"

refs:
actions:
- Closes
- Fixes
- PullRequest

notes:
keywords:
- BREAKING CHANGE
- NOTE
40 changes: 40 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
name: Prepare Release

on:
workflow_dispatch:
inputs:
branch:
description: 'the branch to prepare the release against'
required: true
deault: 'master'
tag:
description: 'the tag to be released'
required: true

jobs:
prepare:
name: Prepare Release
runs-on: 'ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ github.event.inputs.branch }}
- name: Changelog
shell: bash
run: |
curl -o /tmp/git-chglog -L https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64
chmod u+x /tmp/git-chglog
echo "creating change log for tag: ${{ github.event.inputs.tag }}"
/tmp/git-chglog --next-tag "${{ github.event.inputs.tag }}" -o CHANGELOG.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3.1.2
with:
title: "${{ github.event.inputs.tag }} Changelog Bump"
body: "This is an automated changelog commit."
commit-message: "chore: ${{ github.event.inputs.tag }} changelog bump"
branch: "ready-${{ github.event.inputs.tag }}"
signoff: "gh-actions"

97 changes: 97 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
name: Release

on:
push:
tags:
- v1.*

jobs:
release:
name: Release
runs-on: 'ubuntu-latest'
steps:
- name: Setup
run: |
tag=`basename ${{ github.ref }}`
cat <<.
::set-env name=VERSION::${tag}
.
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: ChangeLog
shell: bash
run: |
curl -o git-chglog -L https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64
chmod u+x git-chglog
tag=`basename ${{ github.ref }}`
echo "creating change log for tag: $tag"
chglog="$(./git-chglog ${tag})"
chglog="${chglog//'%'/'%25'}"
chglog="${chglog//$'\n'/'%0A'}"
chglog="${chglog//$'\r'/'%0D'}"
cat <<.
::set-env name=CHANGELOG::${chglog}
.
- name: Create Release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ env.VERSION}} Release
body: |
${{ env.CHANGELOG }}
prerelease: ${{ contains(env.VERSION, 'alpha') || contains(env.VERSION, 'beta') || contains(env.VERSION, 'rc') }}
# perform production release of artifacts
- name: Build Artifacts
run: |
VERSION=${{ env.VERSION }} make all
- name: "Publish Darwin AMD64"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/github.com/go-jira/jira-drawin-amd64
asset_name: jira-drawin-amd64
asset_content_type: application/octet-stream
- name: "Publish Linux 386"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/github.com/go-jira/jira-linux-386
asset_name: jira-linux-386
asset_content_type: application/octet-stream
- name: "Publish Linux AMD64"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/github.com/go-jira/jira-linux-amd64
asset_name: jira-linux-amd64
asset_content_type: application/octet-stream
- name: "Publish Windows 386"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/github.com/go-jira/jira-windows-386.exe
asset_name: jira-windows-386.exe
asset_content_type: application/octet-stream
- name: "Publish Windows AMD64"
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/github.com/go-jira/jira-windows-amd64.exe
asset_name: jira-windows-amd64.exe
asset_content_type: application/octet-stream

File renamed without changes.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GOBIN ?= $(CWD)

CURVER ?= $(patsubst v%,%,$(shell [ -d .git ] && git describe --abbrev=0 --tags || grep ^\#\# CHANGELOG.md | awk '{print $$2; exit}'))
LDFLAGS:= -w
VERSION ?= development

build:
$(GO) build -gcflags="-e" -v -ldflags "$(LDFLAGS) -s" -o '$(BIN)' cmd/jira/main.go
Expand All @@ -42,7 +43,7 @@ all:
GO111MODULE=off $(GO) get -u github.com/mitchellh/gox
rm -rf dist
mkdir -p dist
gox -ldflags="-w -s" -output="dist/github.com/go-jira/jira-{{.OS}}-{{.Arch}}" -osarch="darwin/amd64 linux/386 linux/amd64 windows/386 windows/amd64" ./cmd/jira
gox -ldflags="-w -s" -ldflags="-X 'github.com/go-jira/jira.VERSION=$(VERSION)'" -output="dist/github.com/go-jira/jira-{{.OS}}-{{.Arch}}" -osarch="darwin/amd64 linux/386 linux/amd64 windows/386 windows/amd64" ./cmd/jira

install:
${MAKE} GOBIN=$$HOME/bin build
Expand Down
3 changes: 2 additions & 1 deletion jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"github.com/coryb/oreo"
)

const VERSION = "1.0.26"
// replace by ldflags
var VERSION = "development"

type Jira struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
Expand Down

0 comments on commit 31f7b03

Please sign in to comment.