Update CHANGELOG.md #17
Workflow file for this run
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
# Terraform Provider release workflow. | |
name: Release | |
# This GitHub action creates a release when a tag that matches the pattern | |
# "v*" (e.g. v0.1.0) is created. | |
on: | |
push: | |
tags: | |
- 'v[0-9]+.[0-9]+.[0-9]+*' | |
# Releases need permissions to read and write the repository contents. | |
# GitHub considers creating releases and uploading assets as writing contents. | |
permissions: | |
contents: write | |
jobs: | |
goreleaser: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
# Allow goreleaser to access older tag information. | |
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/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 | |
with: | |
go-version-file: 'go.mod' | |
cache: true | |
- name: Import GPG key | |
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0 | |
id: import_gpg | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
- name: Run GoReleaser | |
uses: goreleaser/goreleaser-action@v6 | |
with: | |
distribution: goreleaser-pro | |
version: "~> v2" | |
args: release --clean -f ${{ vars.GORELEASER_CONFIG_PATH }} --release-notes=release-notes.txt | |
env: | |
# GitHub sets the GITHUB_TOKEN secret automatically. | |
DISABLE_CHANGELOG: ${{ vars.DISABLE_CHANGELOG}} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} | |
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }} | |
highest-version-tag: | |
needs: [goreleaser] | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.highest-version-tag.outputs.tag }} | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: Output highest version tag | |
id: highest-version-tag | |
run: | | |
HIGHEST=$(git tag | sort -V | tail -1) | |
echo "tag=$HIGHEST" >> "$GITHUB_OUTPUT" | |
changelog-newversion: | |
needs: [goreleaser, highest-version-tag] | |
# write new changelog header only if release tag is the $HIGHEST i.e. exists on main | |
# and not a backport release branch (e.g. release/3.x). This results in | |
# manually updating the CHANGELOG header if releasing from the non-default branch. | |
# TODO: find a more deterministic way to determine release branch from tag commit | |
if: github.ref_name == needs.highest-version-tag.outputs.tag | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
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/$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 | |
- run: | | |
git config --local user.email [email protected] | |
git config --local user.name changelogbot | |
git add CHANGELOG.md | |
git commit -m "Update CHANGELOG.md after ${{ github.ref_name }}" | |
git push |