Skip to content

Commit bac54da

Browse files
make changes dirs reflect the version
1 parent 4885290 commit bac54da

25 files changed

+63
-128
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

.changie.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: BUSL-1.1
33

44
changesDir: .changes
5-
unreleasedDir: dev
5+
unreleasedDir: v1.12
66
versionFooterPath: version_footer.tpl.md
77
changelogPath: CHANGELOG.md
88
versionExt: md

.github/workflows/changelog.yml

Lines changed: 49 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,8 @@ jobs:
2828
check-changelog-entry:
2929
name: "Check Changelog Entry"
3030
runs-on: ubuntu-latest
31-
env:
32-
# These are used to ensure the correct changelog entry is added for the PR.
33-
# Please update the labels on every minor release.
34-
CURRENT_LABEL: 1.10-backport
35-
NEXT_LABEL: 1.11-backport
3631
concurrency:
37-
group: changelog-${{ github.ref }}
32+
group: changelog-${{ github.head_ref }}
3833
cancel-in-progress: true
3934

4035
steps:
@@ -43,21 +38,25 @@ jobs:
4338
id: changelog
4439
with:
4540
filters: |
46-
dev:
47-
- '.changes/dev/*.yaml'
48-
next:
49-
- '.changes/next/*.yaml'
50-
current:
51-
- '.changes/current/*.yaml'
41+
changes:
42+
- '.changes/*/*.yaml'
5243
changelog:
5344
- 'CHANGELOG.md'
5445
version:
5546
- 'version/VERSION'
47+
list-files: json
48+
49+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
50+
with:
51+
sparse-checkout: |
52+
version/VERSION
53+
ref: ${{ github.ref }} # Ref refers to the target branch of this PR
5654

5755
- name: "Check for changelog entry"
5856
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
5957
with:
6058
script: |
59+
const fs = require("fs");
6160
async function createOrUpdateChangelogComment(commentDetails, deleteComment) {
6261
const commentStart = "## Changelog Warning"
6362
@@ -105,9 +104,9 @@ jobs:
105104
}
106105
}
107106
108-
const devChangesPresent = ${{steps.changelog.outputs.dev}};
109-
const nextChangesPresent = ${{steps.changelog.outputs.next}};
110-
const currentChangesPresent = ${{steps.changelog.outputs.current}};
107+
// TODO: Does this need a JSON.parse?
108+
const changesPresent = ${{steps.changelog.outputs.changes}};
109+
const changedChangesFiles = ${{steps.changelog.outputs.changes_files}};
111110
const changelogChangesPresent = ${{steps.changelog.outputs.changelog}};
112111
const versionChangesPresent = ${{steps.changelog.outputs.version}};
113112
@@ -116,8 +115,28 @@ jobs:
116115
owner: context.repo.owner,
117116
repo: context.repo.repo
118117
});
119-
const nextBackportLabel = prLabels.data.find(label => label.name === ${{ env.NEXT_LABEL }});
120-
const currentBackportLabel = prLabels.data.find(label => label.name === ${{ env.CURRENT_LABEL }});
118+
const backportLabels = prLabels.data.filter(label => label.name.endsWith("-backport"));
119+
const backportVersions = backportLabels.map(label => label.name.split("-")[0]);
120+
121+
const currentVersionFile = fs.readFileSync("./version/VERSION", "utf-8");
122+
const currentVersionParts = currentVersionFile.split(".");
123+
currentVersionParts.pop();
124+
const currentVersion = currentVersionParts.join(".");
125+
126+
const allVersions = [currentVersion, ...backportVersions]
127+
allVersions.sort((a, b) => {
128+
const as = a.split(".").map(Number);
129+
const bs = b.split(".").map(Number);
130+
131+
if (as[0] !== bs[0]) {
132+
return as[0] - bs[0];
133+
}
134+
135+
if (as[1] !== bs[1]) {
136+
return as[1] - bs[1];
137+
}
138+
});
139+
121140
const noChangelogNeededLabel = prLabels.data.find(label => label.name === 'no-changelog-needed');
122141
const dependenciesLabel = prLabels.data.find(label => label.name === 'dependencies');
123142
@@ -136,7 +155,7 @@ jobs:
136155
}
137156
138157
if (noChangelogNeededLabel) {
139-
if (devChangesPresent || nextChangesPresent) {
158+
if (changesPresent) {
140159
await createOrUpdateChangelogComment("Please remove either the 'no-changelog-needed' label or the changelog entry from this PR.");
141160
return;
142161
}
@@ -146,58 +165,21 @@ jobs:
146165
return;
147166
}
148167
168+
// We only want to have a changelog entry for the oldest version this PR will
169+
// land in.
170+
const onlyExpectedChangeVersion = allVersions[0]
171+
const missingChangelogEntry = !changedChangesFiles.some(filePath => filePath.includes("/v"+onlyExpectedChangeVersion+"/"))
172+
const unexpectedChangelogEntry = changedChangesFiles.filter(filePath => !filePath.includes("/v"+onlyExpectedChangeVersion+"/"))
149173
150-
// If we want to backport this to the current branch, the backlog entry should only exist in the ./.changes/current directory
151-
if (currentBackportLabel) {
152-
if (devChangesPresent) {
153-
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.");
154-
return;
155-
}
156174
157-
if (nextChangesPresent) {
158-
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.");
159-
return;
160-
}
161-
162-
if (!currentChangesPresent) {
163-
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.");
164-
return;
165-
}
166-
167-
// If we have no current backport label, but a next backport label we should only have a changelog entry in the ./.changes/next directory
168-
} else if (nextBackportLabel) {
169-
if (devChangesPresent) {
170-
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.");
171-
return;
172-
}
173-
174-
if (currentChangesPresent) {
175-
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.");
176-
return;
177-
}
178-
179-
180-
if (!nextChangesPresent) {
181-
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.");
182-
return;
183-
}
184-
185-
// If we don't have a backport label we only expect changes in the ./.changes/dev directory
186-
} else {
187-
if (nextChangesPresent) {
188-
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.");
189-
return;
190-
}
191-
192-
if (currentChangesPresent) {
193-
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.");
194-
return;
195-
}
175+
if (missingChangelogEntry) {
176+
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.`);
177+
return;
178+
}
196179
197-
if (!devChangesPresent) {
198-
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.");
199-
return;
200-
}
180+
if (unexpectedChangelogEntry.length > 0) {
181+
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.`);
182+
return;
201183
}
202184
203185
// Nothing to complain about, so delete any existing comment

scripts/changelog.sh

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,8 @@ Commands:
2828
`release`: will make the initial minor release for this branch.
2929
`patch`: will generate a new patch release
3030
31-
prepareMainBranch:
31+
nextMinor:
3232
Run on main branch: Updates the minor version.
33-
34-
prepareReleaseBranch:
35-
Run on newly created release branch: Makes sure we can backport changes properly.
36-
37-
prepareMaintenanceBranch:
38-
Run on newly created maintenance branch: Makes sure we can backport changes properly.
3933
EOF
4034
}
4135

@@ -141,7 +135,7 @@ function generate {
141135

142136
# This function expects the current branch to be main. Run it if you want to set main to the next
143137
# minor version.
144-
function prepareMainBranch {
138+
function nextMinor {
145139
# Prepend the latest version to the previous releases
146140
LATEST_VERSION=$(npx -y changie@$CHANGIE_VERSION latest -r --skip-prereleases)
147141
LATEST_VERSION=${LATEST_VERSION%.*} # Remove the patch version
@@ -152,54 +146,22 @@ function prepareMainBranch {
152146
NEXT_VERSION=$(npx -y changie@$CHANGIE_VERSION next minor)
153147
# Remove all existing per-release changelogs
154148
rm ./.changes/*.*.*.md
155-
# Remove all unreleased changes
156-
rm ./.changes/unreleased/*.yaml
157-
# Remove all backported changes
158-
rm ./.changes/backported/*.yaml
149+
159150
# Create a new empty version file for the next minor version
160151
touch ./.changes/$NEXT_VERSION.md
161152

162-
generate "dev"
163-
}
164-
165-
# This function is expected to be run on the upcoming release branch. It will make sure
166-
# that backports work properly
167-
# Transitions from dev -> next
168-
function prepareReleaseBranch {
169-
# For the maintenance branch we don't want to base our changelog on the unreleased but the backported folder instead
170-
awk '{sub(/unreleasedDir: dev/, "unreleasedDir: next")}1' ./.changie.yaml > temp && mv temp ./.changie.yaml
171-
172-
# If we have backported changes, we need to remove them now since they were backported into the
173-
# last version
174-
rm -f ./.changes/next/*.yaml
153+
LATEST_MAJOR_MINOR=$(echo $LATEST_VERSION | awk -F. '{print $1"."$2}')
154+
NEXT_MAJOR_MINOR=$(echo $NEXT_VERSION | awk -F. '{print $1"."$2}')
175155

176-
# If we have unreleased changes, they will be released in the next patch, therefore they need
177-
# to go into the next folder
178-
if [ "$(ls -A ./.changes/dev/)" ]; then
179-
mv ./.changes/dev/* ./.changes/next/
180-
fi
156+
# Create a new changes directory for the next minor version
157+
mkdir ./.changes/v$NEXT_MAJOR_MINOR
158+
touch ./.changes/v$NEXT_MAJOR_MINOR/.gitkeep
181159

160+
# Set changies changes dir to the new version
161+
awk "{sub(/unreleasedDir: v$LATEST_MAJOR_MINOR/, \"unreleasedDir: v$NEXT_MAJOR_MINOR\")}1" ./.changie.yaml > temp && mv temp ./.changie.yaml
182162
generate "dev"
183-
}
184-
185-
# This function is expected to be run on the upcoming release branch. It will make sure
186-
# that backports work properly
187-
# Transitions from next -> current
188-
function prepareMaintenanceBranch {
189-
# For the maintenance branch we don't want to base our changelog on the unreleased but the backported folder instead
190-
awk '{sub(/unreleasedDir: next/, "unreleasedDir: current")}1' ./.changie.yaml > temp && mv temp ./.changie.yaml
191-
192-
# If we have backported changes, we need to remove them now since they were backported into the
193-
# last version
194-
rm -f ./.changes/current/*.yaml
195163

196-
# If we have unreleased changes, they will be released in the next patch, therefore they need
197-
# to go into the current folder
198-
if [ "$(ls -A ./.changes/next/)" ]; then
199-
mv ./.changes/next/* ./.changes/current/
200-
fi
201-
202-
generate "dev"
164+
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."
203165
}
204166

205167
function main {
@@ -208,18 +170,9 @@ function main {
208170
generate "${@:2}"
209171
;;
210172

211-
prepareMainBranch)
212-
prepareMainBranch "${@:2}"
173+
nextMinor)
174+
nextMinor "${@:2}"
213175
;;
214-
215-
prepareReleaseBranch)
216-
prepareReleaseBranch "${@:2}"
217-
;;
218-
219-
prepareMaintenanceBranch)
220-
prepareMaintenanceBranch "${@:2}"
221-
;;
222-
223176
*)
224177
usage
225178
exit 1

0 commit comments

Comments
 (0)