Skip to content

Commit

Permalink
Set up .changelog, release-notes (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
danroux authored Dec 6, 2023
1 parent 67380f2 commit 8a27d4b
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .changelog/2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:enhancement
Set up CHANGELOG && .changelog
```

```release-note:enhancement
Set up release-notes generation on CI
```

```release-note:enhancement
Tag docker image on docker GHA
```

```release-note:enhancement
Add Makefile
```
71 changes: 71 additions & 0 deletions .changelog/changelog.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{{- if index .NotesByType "breaking-change" -}}
BREAKING CHANGES:

{{range index .NotesByType "breaking-change" -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.security }}
SECURITY:

{{range .NotesByType.security -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.feature }}
FEATURES:

{{range .NotesByType.feature -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.enhancement }}
ENHANCEMENT:

{{range .NotesByType.enhancement -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.deprecation }}
DEPRECATIONS:

{{range .NotesByType.deprecation -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.bug }}
BUG FIXES:

{{range .NotesByType.bug -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.doc }}
DOCS:

{{range .NotesByType.doc -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.dependency }}
DEPENDENCIES:

{{range .NotesByType.dependency -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}

{{- if .NotesByType.note }}
NOTES:

{{range .NotesByType.note -}}
* {{ template "note" . }}
{{ end -}}
{{- end -}}
3 changes: 3 additions & 0 deletions .changelog/note.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- define "note" -}}
{{.Body}}{{if not (stringHasPrefix .Issue "_")}} [[GH-{{- .Issue -}}](https://github.com/danroux/sk8l-ui/issues/{{- .Issue -}})]{{end}}
{{- end -}}
36 changes: 36 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow checks that there is either a 'pr/no-changelog' label applied to a PR
# or there is a .changelog/<pr number>.txt file associated with a PR for a changelog entry
name: Changelog Entry

on:
pull_request:
types: [opened, synchronize, labeled]
# Runs on PRs to main and all release branches
branches:
- main

jobs:
# checks that a .changelog entry is present for a PR
changelog-check:
# If there a `pr/no-changelog` label we ignore this check
if: "!contains(github.event.pull_request.labels.*.name, 'pr/no-changelog') || github.event.pull_request.user.login == 'dependabot'"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 # by default the checkout action doesn't checkout all branches
- name: Check for changelog entry in diff
run: |
# check if there is a diff in the .changelog directory
changelog_files=$(git --no-pager diff --name-only HEAD "$(git merge-base HEAD "origin/${{ github.event.pull_request.base.ref }}")" -- .changelog/${{ github.event.pull_request.number }}.txt)
# If we do not find a file in .changelog/, we fail the check
if [ -z "$changelog_files" ]; then
# Fail status check when no .changelog entry was found on the PR
echo "Did not find a .changelog entry and the 'pr/no-changelog' label was not applied."
exit 1
else
echo "Found .changelog entry in PR!"
fi
5 changes: 4 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ jobs:
production-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
-
name: Checkout - set env
uses: actions/checkout@v4
run: echo "IMAGE_TAG=$(make version)" >> $GITHUB_ENV
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -31,3 +33,4 @@ jobs:
push: true
tags: |
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:latest
${{ vars.DOCKERHUB_SK8L_UI_IMAGE_NAME }}:${{ env.IMAGE_TAG }}
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release

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

permissions:
contents: write

jobs:
release-notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0
- name: Generate Release Notes
run: sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $(git describe --abbrev=0 --exclude="$(git describe --abbrev=0 --match='v*.*.*' --tags)" --match='v*.*.*' --tags | tr -d v)/q;p" CHANGELOG.md > release-notes.txt
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: release-notes
path: release-notes.txt
retention-days: 1
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://gist.github.com/mpneuried/0594963ad38e68917ef189b4e6a269db

# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.PHONY: help

help: ## This help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

# Bump these on release
VERSION_MAJOR ?= 0
VERSION_MINOR ?= 4
VERSION_PATCH ?= 0

WITHOUT ?= $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)
VERSION ?= v$(WITHOUT)

version:
@echo $(VERSION)

# For changelog generation, default the last release to the last tag on
# any branch, and this release to just be the current branch we're on.
LAST_RELEASE?=$$(git describe --tags $$(git rev-list --tags --max-count=1))
THIS_RELEASE?=$$(git rev-parse --abbrev-ref HEAD)

# expected to be invoked by make changelog LAST_RELEASE=gitref THIS_RELEASE=gitref
changelog:
@echo "Generating changelog for $(THIS_RELEASE) from $(LAST_RELEASE)..."
@echo
@changelog-build -last-release $(LAST_RELEASE) \
-entries-dir .changelog/ \
-changelog-template .changelog/changelog.tmpl \
-note-template .changelog/note.tmpl \
-this-release $(THIS_RELEASE)

changelog-entry:
@changelog-entry -dir .changelog/

.PHONY: version changelog changelog-entry

0 comments on commit 8a27d4b

Please sign in to comment.