make changes dirs reflect the version

pull/36525/head
Daniel Schmidt 1 year ago
parent 4885290984
commit bac54da23e

@ -2,7 +2,7 @@
# SPDX-License-Identifier: BUSL-1.1
changesDir: .changes
unreleasedDir: dev
unreleasedDir: v1.12
versionFooterPath: version_footer.tpl.md
changelogPath: CHANGELOG.md
versionExt: md

@ -28,13 +28,8 @@ jobs:
check-changelog-entry:
name: "Check Changelog Entry"
runs-on: ubuntu-latest
env:
# These are used to ensure the correct changelog entry is added for the PR.
# Please update the labels on every minor release.
CURRENT_LABEL: 1.10-backport
NEXT_LABEL: 1.11-backport
concurrency:
group: changelog-${{ github.ref }}
group: changelog-${{ github.head_ref }}
cancel-in-progress: true
steps:
@ -43,21 +38,25 @@ jobs:
id: changelog
with:
filters: |
dev:
- '.changes/dev/*.yaml'
next:
- '.changes/next/*.yaml'
current:
- '.changes/current/*.yaml'
changes:
- '.changes/*/*.yaml'
changelog:
- 'CHANGELOG.md'
version:
- 'version/VERSION'
list-files: json
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
sparse-checkout: |
version/VERSION
ref: ${{ github.ref }} # Ref refers to the target branch of this PR
- name: "Check for changelog entry"
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const fs = require("fs");
async function createOrUpdateChangelogComment(commentDetails, deleteComment) {
const commentStart = "## Changelog Warning"
@ -105,9 +104,9 @@ jobs:
}
}
const devChangesPresent = ${{steps.changelog.outputs.dev}};
const nextChangesPresent = ${{steps.changelog.outputs.next}};
const currentChangesPresent = ${{steps.changelog.outputs.current}};
// TODO: Does this need a JSON.parse?
const changesPresent = ${{steps.changelog.outputs.changes}};
const changedChangesFiles = ${{steps.changelog.outputs.changes_files}};
const changelogChangesPresent = ${{steps.changelog.outputs.changelog}};
const versionChangesPresent = ${{steps.changelog.outputs.version}};
@ -116,8 +115,28 @@ jobs:
owner: context.repo.owner,
repo: context.repo.repo
});
const nextBackportLabel = prLabels.data.find(label => label.name === ${{ env.NEXT_LABEL }});
const currentBackportLabel = prLabels.data.find(label => label.name === ${{ env.CURRENT_LABEL }});
const backportLabels = prLabels.data.filter(label => label.name.endsWith("-backport"));
const backportVersions = backportLabels.map(label => label.name.split("-")[0]);
const currentVersionFile = fs.readFileSync("./version/VERSION", "utf-8");
const currentVersionParts = currentVersionFile.split(".");
currentVersionParts.pop();
const currentVersion = currentVersionParts.join(".");
const allVersions = [currentVersion, ...backportVersions]
allVersions.sort((a, b) => {
const as = a.split(".").map(Number);
const bs = b.split(".").map(Number);
if (as[0] !== bs[0]) {
return as[0] - bs[0];
}
if (as[1] !== bs[1]) {
return as[1] - bs[1];
}
});
const noChangelogNeededLabel = prLabels.data.find(label => label.name === 'no-changelog-needed');
const dependenciesLabel = prLabels.data.find(label => label.name === 'dependencies');
@ -136,7 +155,7 @@ jobs:
}
if (noChangelogNeededLabel) {
if (devChangesPresent || nextChangesPresent) {
if (changesPresent) {
await createOrUpdateChangelogComment("Please remove either the 'no-changelog-needed' label or the changelog entry from this PR.");
return;
}
@ -146,58 +165,21 @@ jobs:
return;
}
// We only want to have a changelog entry for the oldest version this PR will
// land in.
const onlyExpectedChangeVersion = allVersions[0]
const missingChangelogEntry = !changedChangesFiles.some(filePath => filePath.includes("/v"+onlyExpectedChangeVersion+"/"))
const unexpectedChangelogEntry = changedChangesFiles.filter(filePath => !filePath.includes("/v"+onlyExpectedChangeVersion+"/"))
// If we want to backport this to the current branch, the backlog entry should only exist in the ./.changes/current directory
if (currentBackportLabel) {
if (devChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/dev` to `./.changes/current` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (nextChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/next` to `./.changes/current` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (!currentChangesPresent) {
await createOrUpdateChangelogComment("Please add a changelog entry to `./.changes/current` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
// If we have no current backport label, but a next backport label we should only have a changelog entry in the ./.changes/next directory
} else if (nextBackportLabel) {
if (devChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/dev` to `./.changes/next` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (currentChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/current` to `./.changes/next` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (!nextChangesPresent) {
await createOrUpdateChangelogComment("Please add a changelog entry to `./.changes/next` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
// If we don't have a backport label we only expect changes in the ./.changes/dev directory
} else {
if (nextChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/next` to `./.changes/dev` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (currentChangesPresent) {
await createOrUpdateChangelogComment("Please move the changelog entry from `./.changes/current` to `./.changes/dev` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (missingChangelogEntry) {
await createOrUpdateChangelogComment(`Please add a changelog entry for in the .changes/v${onlyExpectedChangeVersion} folder. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.`);
return;
}
if (!devChangesPresent) {
await createOrUpdateChangelogComment("Please add a changelog entry to `./.changes/dev` for this change. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.");
return;
}
if (unexpectedChangelogEntry.length > 0) {
await createOrUpdateChangelogComment(`Please remove the changelog entry for the following paths: ${unexpectedChangelogEntry.join(", ")}. If you believe this change does not need a changelog entry, please add the 'no-changelog-needed' label.`);
return;
}
// Nothing to complain about, so delete any existing comment

@ -28,14 +28,8 @@ Commands:
`release`: will make the initial minor release for this branch.
`patch`: will generate a new patch release
prepareMainBranch:
nextMinor:
Run on main branch: Updates the minor version.
prepareReleaseBranch:
Run on newly created release branch: Makes sure we can backport changes properly.
prepareMaintenanceBranch:
Run on newly created maintenance branch: Makes sure we can backport changes properly.
EOF
}
@ -141,7 +135,7 @@ function generate {
# This function expects the current branch to be main. Run it if you want to set main to the next
# minor version.
function prepareMainBranch {
function nextMinor {
# Prepend the latest version to the previous releases
LATEST_VERSION=$(npx -y changie@$CHANGIE_VERSION latest -r --skip-prereleases)
LATEST_VERSION=${LATEST_VERSION%.*} # Remove the patch version
@ -152,54 +146,22 @@ function prepareMainBranch {
NEXT_VERSION=$(npx -y changie@$CHANGIE_VERSION next minor)
# Remove all existing per-release changelogs
rm ./.changes/*.*.*.md
# Remove all unreleased changes
rm ./.changes/unreleased/*.yaml
# Remove all backported changes
rm ./.changes/backported/*.yaml
# Create a new empty version file for the next minor version
touch ./.changes/$NEXT_VERSION.md
generate "dev"
}
# This function is expected to be run on the upcoming release branch. It will make sure
# that backports work properly
# Transitions from dev -> next
function prepareReleaseBranch {
# For the maintenance branch we don't want to base our changelog on the unreleased but the backported folder instead
awk '{sub(/unreleasedDir: dev/, "unreleasedDir: next")}1' ./.changie.yaml > temp && mv temp ./.changie.yaml
# If we have backported changes, we need to remove them now since they were backported into the
# last version
rm -f ./.changes/next/*.yaml
LATEST_MAJOR_MINOR=$(echo $LATEST_VERSION | awk -F. '{print $1"."$2}')
NEXT_MAJOR_MINOR=$(echo $NEXT_VERSION | awk -F. '{print $1"."$2}')
# If we have unreleased changes, they will be released in the next patch, therefore they need
# to go into the next folder
if [ "$(ls -A ./.changes/dev/)" ]; then
mv ./.changes/dev/* ./.changes/next/
fi
# Create a new changes directory for the next minor version
mkdir ./.changes/v$NEXT_MAJOR_MINOR
touch ./.changes/v$NEXT_MAJOR_MINOR/.gitkeep
# Set changies changes dir to the new version
awk "{sub(/unreleasedDir: v$LATEST_MAJOR_MINOR/, \"unreleasedDir: v$NEXT_MAJOR_MINOR\")}1" ./.changie.yaml > temp && mv temp ./.changie.yaml
generate "dev"
}
# This function is expected to be run on the upcoming release branch. It will make sure
# that backports work properly
# Transitions from next -> current
function prepareMaintenanceBranch {
# For the maintenance branch we don't want to base our changelog on the unreleased but the backported folder instead
awk '{sub(/unreleasedDir: next/, "unreleasedDir: current")}1' ./.changie.yaml > temp && mv temp ./.changie.yaml
# If we have backported changes, we need to remove them now since they were backported into the
# last version
rm -f ./.changes/current/*.yaml
# If we have unreleased changes, they will be released in the next patch, therefore they need
# to go into the current folder
if [ "$(ls -A ./.changes/next/)" ]; then
mv ./.changes/next/* ./.changes/current/
fi
generate "dev"
echo "\n\n Please clean up the .changes folders that are no longer needed, but keep the .gitkeep file for the last two versions to enable backporting."
}
function main {
@ -208,18 +170,9 @@ function main {
generate "${@:2}"
;;
prepareMainBranch)
prepareMainBranch "${@:2}"
nextMinor)
nextMinor "${@:2}"
;;
prepareReleaseBranch)
prepareReleaseBranch "${@:2}"
;;
prepareMaintenanceBranch)
prepareMaintenanceBranch "${@:2}"
;;
*)
usage
exit 1

Loading…
Cancel
Save