Skip to content

Update Changelog PR #1402

Update Changelog PR

Update Changelog PR #1402

name: Update Changelog PR
permissions:
pull-requests: write
contents: write
on:
workflow_run:
workflows: [GetChangelogEntry]
types:
- completed
jobs:
# if there is a changelog entry, check for PR Open
download:
runs-on: ubuntu-latest
outputs:
message: ${{ steps.pull.outputs.message }}
steps:
- name: Get run ID of "Test" workflow
id: get-run-id
run: |
OTHER_REPO="${{ github.repository }}"
WF_NAME="GetChangelogEntry"
RUN_ID=`gh run --repo ${OTHER_REPO} list --workflow ${WF_NAME} --json databaseId --jq .[0].databaseId`
echo "Detected latest run id of ${RUN_ID} for workflow ${WF_NAME}"
echo "run-id=${RUN_ID}" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download artifact from "Get Changelog Entry" workflow
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # 4.3.0
with:
name: changelog_entry # Match name used in changelog_entry.yml upload artifact step
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run-id: ${{ steps.get-run-id.outputs.run-id }}
- name: 'Store entry'
id: pull
run: |
echo message="$(cat changelog_entry.txt)" >> $GITHUB_OUTPUT
# check-for-changelog-entry
changelog-entry:
# if contains to check for bug, enhancement, feature
if: ${{ contains(needs.download.outputs.message, '[BUG]') || contains(needs.download.outputs.message, '[ENHANCEMENT]') || contains(needs.download.outputs.message, '[FEATURE]') }}
runs-on: ubuntu-latest
needs: download
outputs:
optIn: ${{ steps.in.outputs.bool }}
entry: ${{ needs.download.outputs.message }}
steps:
- name: changelog entry opt in
id: in
continue-on-error: true
run: echo "opted in to changelog entry" | echo bool="true" >> $GITHUB_OUTPUT
# if there is a changelog entry, check for PR Open
update-changelog:
if: needs.changelog-entry.outputs.optIn
runs-on: ubuntu-latest
needs: changelog-entry
steps:
- name: Check if PR exists
id: check
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json title \
--label "changelog" \
--jq 'length')
if [[ $prs -gt 0 ]]; then
echo "existing=true" >> "$GITHUB_OUTPUT"
fi
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: check for branch
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
BRANCH=automated-changelog
if gh api repos/hashicorp/terraform-provider-azurerm/branches/$BRANCH > /dev/null 2>&1; then
echo "Branch exists on remote..."
git fetch origin $BRANCH
git checkout $BRANCH
else
echo "Branch does not exist on remote, creating locally..."
git checkout -b $BRANCH
fi
- name: Create pull request
#if changelog PR isn't already open, open one
#create a new PR, start with appending the release number and (unreleased)
if: '!steps.check.outputs.existing'
env:
GH_TOKEN: ${{ secrets.SERVICE_ACCOUNT_TERRAFORM_TOKEN }}
continue-on-error: true
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
#new pull request for new release needs the headers all added to the top
FILE="CHANGELOG.md"
version=$(head -n 1 "$FILE")
IFS='.' read major minor patch <<< "$version"
((minor++))
patch=$(echo $patch | sed 's/ (.*)//')
new_version="${major}.$minor.${patch} (Unreleased)"
headers="${new_version}\n\nENHANCEMENTS:\n\nFEATURES:\n\nBUG FIXES:\n"
temp_file=$(mktemp)
echo -e "$headers" > "$temp_file"
cat "$FILE" >> "$temp_file"
mv "$temp_file" "$FILE"
echo "File has been updated."
major=$(echo $major | sed 's/## //')
RELEASENUM="${major}.$minor.${patch}"
git add CHANGELOG.md
git commit -m "staring new changelog PR"
git push --set-upstream origin automated-changelog
echo "Creating a new pull request"
gh pr create \
--repo "$GITHUB_REPOSITORY" \
--base main \
--head automated-changelog \
-t "CHANGELOG.md for $RELEASENUM" \
-b "Automated changelog for next release, $RELEASENUM"
- name: Add changelog label
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
gh pr edit automated-changelog \
--add-label "changelog"
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0
with:
go-version: '1.22'
- name: Add commit message to changelog pull request
# at this point a PR is opened for sure, now add entry
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
go run internal/tools/changelog-updater/update_changelog.go CHANGELOG.md '${{ needs.changelog-entry.outputs.entry }}'
git add CHANGELOG.md
git commit -m "Update changelog"
git push --set-upstream origin automated-changelog