From efa3dc056e7c5e7448c7e5aee15704c6974a2057 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 27 Nov 2024 22:05:34 -0800 Subject: [PATCH 1/2] provider: update changelog via tag workflow instead of release script --- .github/workflows/release.yaml | 58 ++++++++++++++++++++++++- scripts/changelog-update-for-release.sh | 49 +++++++++++++++++++++ scripts/release.sh | 47 -------------------- 3 files changed, 106 insertions(+), 48 deletions(-) create mode 100755 scripts/changelog-update-for-release.sh diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f7c2228e7bb8..c93b0ab96641 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,6 +18,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - id: go-version run: echo "version=$(cat ./.go-version)" >>${GITHUB_OUTPUT} + release-notes: runs-on: custom-linux-xl steps: @@ -36,7 +37,6 @@ jobs: name: 'Terraform Provider Release' needs: [go-version, release-notes] uses: hashicorp/ghaction-terraform-provider-release/.github/workflows/hashicorp.yml@393dac4dd208c749b1622323f9f0e8d26a6f26cc # v4.0.1 - secrets: hc-releases-github-token: '${{ secrets.HASHI_RELEASES_GITHUB_TOKEN }}' hc-releases-host-staging: '${{ secrets.HC_RELEASES_HOST_STAGING }}' @@ -54,3 +54,59 @@ jobs: setup-go-version: '${{ needs.go-version.outputs.version }}' # Product Version (e.g. v1.2.3 or github.ref_name) product-version: '${{ github.ref_name }}' + + get-highest-version-tag: + needs: [terraform-provider-release] + runs-on: macos-latest + outputs: + tag: ${{ steps.highest-version-tag.outputs.tag }} + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + # Allow tag to be fetched when ref is a commit + 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: [terraform-provider-release, get-highest-version-tag] + # update changelog only if release tag is the $HIGHEST i.e. exists on main and not a backport release branch (e.g. release/4.x). + # This requires 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/create-github-app-token@5d869da34e18e7287c1daad50e0b8ea0f506ce69 # v1.11.0 + # id: app-token + # with: + # app-id: ${{ secrets.APP_ID }} + # private-key: ${{ secrets.APP_PEM }} + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + ref: main + token: ${{ steps.app-token.outputs.token }} + - name: Update Changelog # updates date & links, do we want to move updating the links elsewhere to where we automate the changelog? + run: | + bash ./scripts/changelog-update-for-release.sh + - run: | + git config --local user.email changelogbot@hashicorp.com + git config --local user.name changelogbot + git add CHANGELOG.md + git commit -m "Update CHANGELOG.md after ${{ github.ref_name }}" + git push + + upload-tag-before-post-publish: + needs: [terraform-provider-release] + runs-on: ubuntu-latest + steps: + - name: Save Release Tag + run: echo ${{ github.ref_name }} > release-tag.data + - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 + with: + name: release-tag + path: release-tag.data + retention-days: 1 \ No newline at end of file diff --git a/scripts/changelog-update-for-release.sh b/scripts/changelog-update-for-release.sh new file mode 100755 index 000000000000..8c6d80384b5c --- /dev/null +++ b/scripts/changelog-update-for-release.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +if [[ "$(uname)" == "Darwin" ]]; then + echo "(Using BSD sed)" + SED="sed -E" +else + echo "(Using GNU sed)" + SED="sed -r" +fi + +DATE="$(date '+%B %d, %Y')" +PROVIDER_URL="https:\/\/github.com\/hashicorp\/terraform-provider-azurerm\/issues" + +echo "Preparing changelog for release..." + +if [[ ! -f CHANGELOG.md ]]; then + echo "Error: CHANGELOG.md not found." + exit 2 +fi + +# Get the next release +RELEASE="$($SED -n 's/^## v?([0-9.]+) \(Unreleased\)/\1/p' CHANGELOG.md)" +if [[ "${RELEASE}" == "" ]]; then + echo "Error: could not determine next release in CHANGELOG.md" >&2 + exit 3 +fi + +# Replace [GH-nnnn] references with issue links +( set -x; ${debug}$SED -i.bak "s/\[GH-([0-9]+)\]/\(\[#\1\]\(${PROVIDER_URL}\/\1\)\)/g" CHANGELOG.md ) + +# Set the date for the latest release +( set -x; ${debug}$SED -i.bak "s/^(## v?[0-9.]+) \(Unreleased\)/\1 (${DATE})/i" CHANGELOG.md ) + +${debug}rm CHANGELOG.md.bak + +echo "exporting Provider Schema JSON" +( + set -x + ${debug}go run internal/tools/schema-api/main.go -export .release/provider-schema.json +) + +echo "Committing changelog and provider schema..." +( + set -x + ${debug}git commit CHANGELOG.md .release/provider-schema.json -m v"${RELEASE}" + ${debug}git push origin "${BRANCH}" +) \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh index ecfb9e5c851f..58b8f385d5aa 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -52,17 +52,6 @@ if [[ "${GOTIME}" != "1" ]]; then exit 1 fi -if [[ "$(uname)" == "Darwin" ]]; then - echo "(Using BSD sed)" - SED="sed -E" -else - echo "(Using GNU sed)" - SED="sed -r" -fi - -DATE="$(date '+%B %d, %Y')" -PROVIDER_URL="https:\/\/github.com\/hashicorp\/terraform-provider-azurerm\/issues" - BRANCH="$(git rev-parse --abbrev-ref HEAD)" if [[ "${BRANCH}" != "${TRUNK}" ]]; then if [[ "${FORCE}" == "1" ]]; then @@ -87,50 +76,14 @@ else ( set -x; TF_ACC= scripts/run-test.sh ) fi -echo "Preparing changelog for release..." - -if [[ ! -f CHANGELOG.md ]]; then - echo "Error: CHANGELOG.md not found." - exit 2 -fi - -# Get the next release -RELEASE="$($SED -n 's/^## v?([0-9.]+) \(Unreleased\)/\1/p' CHANGELOG.md)" -if [[ "${RELEASE}" == "" ]]; then - echo "Error: could not determine next release in CHANGELOG.md" >&2 - exit 3 -fi - # Ensure latest changes are checked out ( set -x; ${debug}git pull --rebase origin "${TRUNK}" ) -# Replace [GH-nnnn] references with issue links -( set -x; ${debug}$SED -i.bak "s/\[GH-([0-9]+)\]/\(\[#\1\]\(${PROVIDER_URL}\/\1\)\)/g" CHANGELOG.md ) - -# Set the date for the latest release -( set -x; ${debug}$SED -i.bak "s/^(## v?[0-9.]+) \(Unreleased\)/\1 (${DATE})/i" CHANGELOG.md ) - -${debug}rm CHANGELOG.md.bak - if [[ "${NOTAG}" == "1" ]]; then echo "Warning: Skipping commit, tag and push." exit 0 fi -echo "exporting Provider Schema JSON" -( - set -x - ${debug}go run internal/tools/schema-api/main.go -export .release/provider-schema.json -) - -echo "Committing changelog and provider schema..." -( - set -x - ${debug}git commit CHANGELOG.md .release/provider-schema.json -m v"${RELEASE}" - ${debug}git push origin "${BRANCH}" -) - - echo "Releasing v${RELEASE}..." ( From 1a8229bb067db1b89abe462b9fdee362ff5167a6 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 4 Dec 2024 18:13:29 -0800 Subject: [PATCH 2/2] address pr comments and remove commit from changelog script --- scripts/changelog-update-for-release.sh | 7 ------- scripts/release.sh | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/changelog-update-for-release.sh b/scripts/changelog-update-for-release.sh index 8c6d80384b5c..a43177341edd 100755 --- a/scripts/changelog-update-for-release.sh +++ b/scripts/changelog-update-for-release.sh @@ -39,11 +39,4 @@ echo "exporting Provider Schema JSON" ( set -x ${debug}go run internal/tools/schema-api/main.go -export .release/provider-schema.json -) - -echo "Committing changelog and provider schema..." -( - set -x - ${debug}git commit CHANGELOG.md .release/provider-schema.json -m v"${RELEASE}" - ${debug}git push origin "${BRANCH}" ) \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh index 58b8f385d5aa..35ea2f149d5a 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -52,6 +52,14 @@ if [[ "${GOTIME}" != "1" ]]; then exit 1 fi +if [[ "$(uname)" == "Darwin" ]]; then + echo "(Using BSD sed)" + SED="sed -E" +else + echo "(Using GNU sed)" + SED="sed -r" +fi + BRANCH="$(git rev-parse --abbrev-ref HEAD)" if [[ "${BRANCH}" != "${TRUNK}" ]]; then if [[ "${FORCE}" == "1" ]]; then @@ -76,6 +84,13 @@ else ( set -x; TF_ACC= scripts/run-test.sh ) fi +# Get the next release +RELEASE="$($SED -n 's/^## v?([0-9.]+) \(Unreleased\)/\1/p' CHANGELOG.md)" +if [[ "${RELEASE}" == "" ]]; then + echo "Error: could not determine next release in CHANGELOG.md" >&2 + exit 3 +fi + # Ensure latest changes are checked out ( set -x; ${debug}git pull --rebase origin "${TRUNK}" )