Skip to content

Cutoff changelog

Cutoff changelog #45

name: Cutoff changelog
on:
workflow_dispatch:
inputs:
patch_version:
description: Patch version (integer)
required: true
env:
NODE_ENV: production
RELEASE_VERSION: "${{ format('{0}.{1}', github.ref_name, github.event.inputs.patch_version) }}"
jobs:
cutoff_changelog:
name: Cutoff changelog
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Check branch
run: echo "${{ github.ref_name }}" | grep -Pq '^v3\.\d+$'
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Update changelog
run: 'cat CHANGELOG.md | tr ''\n'' ''\000'' |
sed ''s/## [A-Z][a-z]*\x00\x00#/\x01\x00#/g''|
sed ''s/## \[Unreleased\]/## \[Unreleased\]\x00\x00### Added\x00\x00### Changed\x00\x00### Deprecated\x00\x00### Removed\x00\x00### Fixed\x00\x00### Security\x00\x00''"## \\[${RELEASE_VERSION#v}\\] - unreleased"''/'' |
tr ''\000'' ''\n'' |
sed ''/\x01/d'' |
sed "s/\[unreleased\]: https:\/\/github.com\/$(echo "${GITHUB_REPOSITORY}" | sed ''s/\//\\\//g'')\/compare\/\(v3\.[0-9][0-9]*\.[0-9][0-9]*\)\.\.\.\(v3\.[0-9][0-9]*\)/[unreleased]: https:\/\/github.com\/$(echo "${GITHUB_REPOSITORY}" | sed ''s/\//\\\//g'')\/compare\/${RELEASE_VERSION}...${GITHUB_REF_NAME}\n[${RELEASE_VERSION#v}]: https:\/\/github.com\/$(echo "${GITHUB_REPOSITORY}" | sed ''s/\//\\\//g'')\/compare\/\1...${RELEASE_VERSION}/" > CHANGELOG2.md
&& mv -f CHANGELOG2.md CHANGELOG.md
&& git add CHANGELOG.md'
- name: Prepare a PR
run: |
git config user.name "The Things Bot"
git config user.email "[email protected]"
git checkout -b "changelog/${RELEASE_VERSION}"
git add CHANGELOG.md
git commit -m "all: Cut off changelog version ${RELEASE_VERSION#v}"
git push --set-upstream origin "changelog/${RELEASE_VERSION}"
export PR_URL=$(mktemp)
gh pr create \
--assignee '${{ github.actor }}' \
--head "changelog/${RELEASE_VERSION}" \
--base '${{ github.ref_name }}' \
--body "This pull request cuts off the ${RELEASE_VERSION} changelog." \
--label "release" \
--title "Changelog cutoff ${RELEASE_VERSION}" \
| tee "${PR_URL}"
# Try adding a milestone but ignore errors
gh pr edit < "${PR_URL}" \
--milestone "${RELEASE_VERSION}" \
|| true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}