-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: enhancement changelog made (#109)
Co-authored-by: David MICHENEAU <david.micheneau@orange.com>
- Loading branch information
1 parent
1d340ce
commit fe1102a
Showing
6 changed files
with
346 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{{- if .NotesByType.deprecation -}} | ||
### :warning: **Deprecations** | ||
|
||
{{range .NotesByType.deprecation -}} | ||
* {{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if index .NotesByType "breaking-change" -}} | ||
### :rotating_light: **Breaking Changes** | ||
|
||
{{range index .NotesByType "breaking-change" -}} | ||
* {{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- $features := combineTypes .NotesByType.feature (index .NotesByType "new-resource" ) (index .NotesByType "new-data-source") -}} | ||
{{- if $features }} | ||
### :rocket: **New Features** | ||
|
||
{{range $features | sort -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- $improvements := combineTypes .NotesByType.improvement .NotesByType.enhancement -}} | ||
{{- if $improvements }} | ||
### :tada: **Improvements** | ||
|
||
{{range $improvements | sort -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.bug }} | ||
### :bug: **Bug Fixes** | ||
|
||
{{range .NotesByType.bug -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.note -}} | ||
### :information_source: **Notes** | ||
|
||
{{range .NotesByType.note -}} | ||
* {{ template "note" .}} | ||
{{ end -}} | ||
{{- end -}} | ||
|
||
{{- if .NotesByType.dependency }} | ||
### :dependabot: **Dependencies** | ||
|
||
{{range .NotesByType.dependency | sort -}} | ||
* {{ template "note" . }} | ||
{{ end -}} | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
set -x | ||
set -o errexit | ||
set -o nounset | ||
|
||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
__parent="$(dirname "$__dir")" | ||
__root="$(dirname "$__parent")" | ||
|
||
CHANGELOG_FILE_NAME="CHANGELOG.md" | ||
CHANGELOG_TMP_FILE_NAME="CHANGELOG.tmp" | ||
TARGET_SHA=$(git rev-parse HEAD) | ||
PREVIOUS_RELEASE_TAG=$(git tag -l | sort -V | grep -E 'v[0-9]+.[0-9]+.[0-9]+$' | tail -n 1) | ||
PREVIOUS_RELEASE_SHA=$(git rev-list -n 1 $PREVIOUS_RELEASE_TAG) | ||
|
||
if [ $TARGET_SHA == $PREVIOUS_RELEASE_SHA ]; then | ||
echo "Nothing to do" | ||
exit 0 | ||
fi | ||
|
||
PREVIOUS_CHANGELOG=$(sed -n -e "/# ${PREVIOUS_RELEASE_TAG#v}/,\$p" $__root/$CHANGELOG_FILE_NAME) | ||
|
||
if [ -z "$PREVIOUS_CHANGELOG" ] | ||
then | ||
echo "Unable to locate previous changelog contents." | ||
exit 1 | ||
fi | ||
|
||
CHANGELOG=$($(go env GOPATH)/bin/changelog-build -this-release $TARGET_SHA \ | ||
-last-release $PREVIOUS_RELEASE_SHA \ | ||
-git-dir $__root \ | ||
-entries-dir .changelog \ | ||
-changelog-template $__dir/changelog.tmpl \ | ||
-note-template $__dir/release-note.tmpl) | ||
if [ -z "$CHANGELOG" ] | ||
then | ||
echo "No changelog generated." | ||
exit 0 | ||
fi | ||
|
||
rm -f $CHANGELOG_TMP_FILE_NAME | ||
|
||
sed -n -e "1{/# /p;}" $__root/$CHANGELOG_FILE_NAME > $CHANGELOG_TMP_FILE_NAME | ||
echo "$CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME | ||
echo >> $CHANGELOG_TMP_FILE_NAME | ||
echo "$PREVIOUS_CHANGELOG" >> $CHANGELOG_TMP_FILE_NAME | ||
|
||
cp $CHANGELOG_TMP_FILE_NAME $CHANGELOG_FILE_NAME | ||
|
||
rm $CHANGELOG_TMP_FILE_NAME | ||
|
||
echo "Successfully generated changelog." | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{- define "note" -}} | ||
{{if eq "new-resource" .Type}}**New Resource:** {{else if eq "new-data-source" .Type}}**New Data Source:** {{ end }}{{.Body}} (GH-{{- .Issue -}}) | ||
{{- end -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
name: TagRelease | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tag: | ||
description: 'Tag version number (Eg: v0.1.0)' | ||
required: true | ||
type: string | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
# * Step 0: Pre-Check | ||
pre-check: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
TAG_NAME: ${{ steps.set-tag.outputs.TAG_NAME }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
- name: Check if tag is valid | ||
run : | | ||
# Check if the tag start with 'v', if not, add it | ||
if [[ ! ${{ github.event.inputs.tag }} =~ ^v.* ]]; then | ||
echo "Error tag format is invalid. The format is vx.x.x" >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
- name: Construct Tag for Pre-Release | ||
id: set-tag | ||
run: | | ||
# Construct the tag name | ||
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT" | ||
# * Step 1: Check if everything is ok | ||
tag-already-exist: | ||
needs: [pre-check] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
- name: Check if tag not already exists | ||
run: | | ||
if git rev-parse ${{ needs.pre-check.outputs.TAG_NAME }} >/dev/null 2>&1; then | ||
echo "Tag ${{ needs.pre-check.outputs.TAG_NAME }} already exists" >> "$GITHUB_OUTPUT" | ||
exit 1 | ||
fi | ||
golangci-lint: | ||
needs: [pre-check] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
ref: ${{ github.ref }} | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
- run: go mod download | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v4 | ||
with: | ||
version: latest | ||
# TODO: Add testsunit / coverage | ||
# testsunit: | ||
# needs: [pre-check] | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v4 | ||
# with: | ||
# token: ${{ secrets.CHANGELOG_PAT }} | ||
# ref: ${{ github.ref }} | ||
# - uses: actions/setup-go@v5 | ||
# with: | ||
# go-version-file: 'go.mod' | ||
# - run: go mod download | ||
# - name: Run Go unit tests | ||
# env: | ||
# TEST_CLOUDAVENUE_ORG: ${{ secrets.CLOUDAVENUE_ORG }} | ||
# TEST_CLOUDAVENUE_USERNAME: ${{ secrets.CLOUDAVENUE_USER }} | ||
# TEST_CLOUDAVENUE_PASSWORD: ${{ secrets.CLOUDAVENUE_PASSWORD }} | ||
# TEST_CLOUDAVENUE_VDC: ${{ secrets.CLOUDAVENUE_VDC }} | ||
# run: | | ||
# go test $(go list ./... | grep -v /internal/testsacc/) | ||
|
||
# * Step 2: Create a new tag | ||
tag: | ||
needs: [golangci-lint, pre-check, tag-already-exist] #testsunit] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
- uses: rickstaa/action-create-tag@v1 | ||
id: "tag_create" | ||
with: | ||
tag: ${{ needs.pre-check.outputs.TAG_NAME }} | ||
tag_exists_error: true | ||
message: "Release ${{ needs.pre-check.outputs.TAG_NAME }}" | ||
|
||
release-notes: | ||
runs-on: ubuntu-latest | ||
needs: [tag, pre-check] | ||
steps: | ||
- uses: actions/checkout@v4 # v3.5.3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ needs.pre-check.outputs.TAG_NAME }} | ||
- name: Generate Release Notes | ||
run: | | ||
echo "" > release-notes.txt | ||
export PREV_TAG=$(git tag --list 'v*' --sort=-version:refname | grep -E "v[0-9]+\.[0-9]+\.[0-9]+$" | head -n 2 | tail -n 1) | ||
export PREV_VERSION=${PREV_TAG//v} | ||
sed -n -e "1{/# /d;}" -e "2{/^$/d;}" -e "/# $PREV_VERSION/q;p" CHANGELOG.md >> release-notes.txt | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: release-notes | ||
path: release-notes.txt | ||
retention-days: 1 | ||
release-app: | ||
runs-on: ubuntu-latest | ||
needs: [release-notes, golangci-lint, pre-check] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ needs.pre-check.outputs.TAG_NAME }} | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
- id: release-notes-download | ||
name: Release Notes Download | ||
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4 | ||
with: | ||
name: release-notes | ||
path: /tmp | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v5 | ||
if: success() | ||
with: | ||
distribution: goreleaser | ||
version: latest | ||
args: release --clean -f .goreleaser.yaml --release-notes=${{ steps.release-notes-download.outputs.download-path }}/release-notes.txt | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
changelog-newversion: | ||
needs: [release-app, pre-check] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 # v3.5.3 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
fetch-depth: 0 | ||
ref: main | ||
- name: Update Changelog Header | ||
run: | | ||
CHANGELOG_FILE_NAME="CHANGELOG.md" | ||
PREVIOUS_RELEASE_TAG=${{ github.ref_name }} | ||
# Add Release Date | ||
RELEASE_DATE=`date +%B' '%e', '%Y` | ||
sed -i -e "1 s/.*Unreleased.*/## ${PREVIOUS_RELEASE_TAG#v} ($RELEASE_DATE)/" $CHANGELOG_FILE_NAME | ||
# Prepend next release line | ||
echo Previous release is: $PREVIOUS_RELEASE_TAG | ||
NEW_RELEASE_LINE=$(echo $PREVIOUS_RELEASE_TAG | awk -F. '{ | ||
$1 = substr($1,2) | ||
$2 += 1 | ||
printf("%s.%01d.0\n\n", $1, $2); | ||
}') | ||
echo New minor version is: v$NEW_RELEASE_LINE | ||
echo -e "## $NEW_RELEASE_LINE (Unreleased)\n$(cat $CHANGELOG_FILE_NAME)" > $CHANGELOG_FILE_NAME | ||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: "chore: Update CHANGELOG.md after ${{ github.ref_name }}" | ||
commit_options: '--no-verify --signoff' | ||
file_pattern: CHANGELOG.md | ||
commit_user_name: github-actions[bot] | ||
commit_user_email: github-actions[bot]@users.noreply.github.com | ||
commit_author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: PR Close | ||
on: | ||
pull_request: | ||
types: [closed] | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.head_ref }}-changelog | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
GenerateChangelog: | ||
if: github.event.pull_request.merged || github.event_name == 'workflow_dispatch' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
token: ${{ secrets.CHANGELOG_PAT }} | ||
fetch-depth: 0 | ||
submodules: false | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
# * CHANGELOG | ||
- run: go install github.com/hashicorp/go-changelog/cmd/changelog-build@latest | ||
- run: bash .github/changelog/generate-changelog.sh | ||
- uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: "chore: Update CHANGELOG.md" | ||
commit_options: '--no-verify --signoff' | ||
push_options: '--force' | ||
file_pattern: CHANGELOG.md | ||
commit_user_name: github-actions[bot] | ||
commit_user_email: github-actions[bot]@users.noreply.github.com | ||
commit_author: Changelog Bot <github-actions[bot]@users.noreply.github.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters