Skip to content

Commit

Permalink
cicd: change log generation and releases
Browse files Browse the repository at this point in the history
this commit adds change log generation and a set of gihub workflows to
support it.

Signed-off-by: ldelossa <ldelossa@redhat.com>
  • Loading branch information
ldelossa committed Sep 11, 2020
1 parent c0a9c0b commit 54ee2d2
Show file tree
Hide file tree
Showing 5 changed files with 248 additions and 62 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/quay/clair
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
125 changes: 118 additions & 7 deletions .github/workflows/cut-release.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
---
name: Release

on:
release:
types:
- published
push:
tags:
- v4.*

name: Upload Release Assets

jobs:
build:
release:
name: Release
runs-on: 'ubuntu-latest'
container: docker.io/library/golang:1.14
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: Build clairctl
run:
GOOS=darwin GOARCH=amd64 -o clairctl-darwin-amd64 ./cmd/clairctl
GOOS=linux GOARCH=amd64 -o clairctl-linux-amd64 ./cmd/clairctl
GOOS=windows GOARCH=amd64 -o clairctl-windows-amd64 ./cmd/clairctl

GOOS=darwin GOARCH=386 -o clairctl-darwin-386 ./cmd/clairctl
GOOS=linux GOARCH=386 -o clairctl-linux-386 ./cmd/clairctl
GOOS=windows GOARCH=386 -o clairctl-windows-386 ./cmd/clairctl

- 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
id: create_release
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: Upload Release Assets
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -42,14 +91,76 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clair.tar.gz
asset_name: clair-${{ env.CLAIR_VERSION }}.tar.gz
asset_content_type: application/gzip

- name: Publish clairctl-darwin-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-darwin-amd64
asset_name: clairctl-darwin-amd64
asset_content_type: application/octet-stream

- name: Publish clairctl-linux-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-linux-amd64
asset_name: clairctl-linux-amd64
asset_content_type: application/octet-stream

- name: Publish clairctl-windows-amd64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-windows-amd64
asset_name: clairctl-windows-amd64
asset_content_type: application/octet-stream

- name: Publish clairctl-darwin-386
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-darwin-386
asset_name: clairctl-darwin-386
asset_content_type: application/octet-stream

- name: Publish clairctl-linux-386
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-linux-386
asset_name: clairctl-linux-386
asset_content_type: application/octet-stream

- name: Publish clairctl-windows-386
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./clairctl-windows-386
asset_name: clairctl-windows-386
asset_content_type: application/octet-stream

- name: Publish Release Container
run: |
docker login -u "${QUAY_USER}" -p '${{ secrets.QUAY_TOKEN }}' quay.io
docker push "${TAG}"
deploy-documentation:
name: Deploy Documentation
runs-on: ubuntu-latest
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ on:
- development-4.0 # Remove this when the branch switch happens.

jobs:
commit-check:
name: Commit Check
runs-on: ubuntu-latest
steps:
- name: commit check
uses: gsactions/commit-message-checker@v1
with:
pattern: |
^(.*):\s*(.*)\n
error: 'Commit must begin with <scope>: <subject>'

tidy:
name: Tidy
runs-on: ubuntu-latest
Expand Down
85 changes: 30 additions & 55 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,39 @@
name: Prepare Release

on:
push:
tags:
- 'v4.*'
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:
create:
name: Create Release
prepare:
name: Prepare Release
runs-on: 'ubuntu-latest'
steps:
- name: Setup
run: |
: "${tag:=${GITHUB_REF#refs/tags/}}"
cat <<.
::set-env name=CLAIR_VERSION::${tag}
.
- name: Create Release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ env.CLAIR_VERSION}} Release
body: |
Coming Soon...
draft: true
prerelease: ${{ contains(env.CLAIR_VERSION, 'alpha') || contains(env.CLAIR_VERSION, 'beta') || contains(env.CLAIR_VERSION, 'rc') }}
stable:
if: endsWith(github.ref, '.0')
name: Create Stable Helpers
runs-on: 'ubuntu-latest'
steps:
- name: Create Branch
uses: actions/github-script@0.9.0
- name: Checkout
uses: actions/checkout@v2
with:
script: |
const tag = context.ref.replace("refs/tags/", "");
github.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/heads/release-' + tag,
sha: context.sha
});
- name: Create Labels
uses: actions/github-script@0.9.0
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 v4.0.0-alpha.2..
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3.1.2
with:
script: |
const tag = context.ref.replace("refs/tags/", "").slice(0, -2);
github.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'NeedsBackport-' + tag,
color: '790604',
description: `This needs to be backported to ${tag}`
});
github.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: 'PossibleBackport-' + tag,
color: '008000',
description: `This may need to be backported to ${tag}`
});
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"

0 comments on commit 54ee2d2

Please sign in to comment.