Skip to content

Commit a733fb5

Browse files
CLOUDP-311383: add a cleanup step after the changelog release process (#765)
1 parent dfa08df commit a733fb5

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

.github/scripts/get_list_files_to_delete.sh

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,23 @@
44
# This script is used in the release cleanup pipeline.
55
set -eou pipefail
66

7+
add_changelog_files_to_delete() {
8+
pushd ../../changelog/version-diff
9+
10+
upcoming_version_item="$1"
11+
changelog_files=(./*)
12+
13+
for file in "${changelog_files[@]}"; do
14+
filename=$(basename "$file")
15+
echo "CHANGELOG - upcoming_version_item: ${upcoming_version_item}"
16+
if [[ "${filename}" == *"${upcoming_version_item}"* ]]; then
17+
changelog_files_to_delete+=("${filename}")
18+
fi
19+
done
20+
21+
popd
22+
}
23+
724
pushd openapi/v2
825
upcoming_api_versions=$(find . -maxdepth 1 -name 'openapi-*.upcoming.json' -exec basename {} \; | sed -e "s/^openapi-//" -e "s/\.json$//")
926
echo "upcoming_api_versions: ${upcoming_api_versions}"
@@ -18,6 +35,7 @@ if [ -z "${upcoming_api_versions}" ]; then
1835
fi
1936

2037
files_to_delete=()
38+
changelog_files_to_delete=()
2139
# Populate upcoming_array line by line from the multi-line upcoming_api_versions string
2240
while IFS= read -r line; do
2341
# Add to array only if line is not empty
@@ -31,22 +49,31 @@ for upcoming_version_item in "${upcoming_array[@]}"; do
3149
# Check if the exact upcoming_version_item string (e.g., "2023-01-01.upcoming"),
3250
# when quoted (e.g., "\"2023-01-01.upcoming\""), is NOT found in the api_versions string.
3351
# The condition is true if grep does not find the string (exit status 1).
34-
echo "upcoming_version_item: $upcoming_version_item"
52+
echo "OPENAPI - upcoming_version_item: $upcoming_version_item"
3553
if ! echo "${api_versions}" | grep -qF "\"${upcoming_version_item}\""; then
3654
# If upcoming_version_item is NOT found in api_versions,
3755
# add its corresponding OpenAPI file name (e.g., openapi-2023-01-01.upcoming.json)
3856
# to the files_to_delete array.
3957
files_to_delete+=("openapi-${upcoming_version_item}.json")
4058
files_to_delete+=("openapi-${upcoming_version_item}.yaml")
59+
add_changelog_files_to_delete "${upcoming_version_item}"
4160
fi
4261
done
4362

4463
# Display the files marked for deletion
4564
if [ ${#files_to_delete[@]} -gt 0 ]; then
4665
echo "V2_OPEN_API_FILES_TO_DELETE=${files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}"
66+
echo "V2_CHANGELOG_FILES_TO_DELETE=${changelog_files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}"
67+
68+
echo "Files to delete:"
4769
for file_to_del in "${files_to_delete[@]}"; do
4870
echo "${file_to_del}"
4971
done
72+
73+
echo "Changelog files to delete:"
74+
for api_to_del in "${changelog_files_to_delete[@]}"; do
75+
echo "${api_to_del}"
76+
done
5077
else
5178
echo "No files marked for deletion."
5279
fi

.github/workflows/release-cleanup.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ jobs:
4141
- name: Delete files
4242
env:
4343
V2_OPEN_API_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_OPEN_API_FILES_TO_DELETE }}
44+
V2_CHANGELOG_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_CHANGELOG_FILES_TO_DELETE }}
4445
run: |
46+
# Delete OpenAPI specs files
4547
pushd openapi/v2
46-
4748
FILES_CHANGED=false
4849
if [ -z "${V2_OPEN_API_FILES_TO_DELETE}" ]; then
4950
echo "V2_OPEN_API_FILES_TO_DELETE is empty. No files to delete."
@@ -57,9 +58,26 @@ jobs:
5758
rm -f "${file_to_delete}"
5859
fi
5960
done
61+
popd
62+
63+
# Delete Changelog files
64+
pushd changelog/version-diff
65+
if [ -z "${V2_CHANGELOG_FILES_TO_DELETE}" ]; then
66+
echo "V2_CHANGELOG_FILES_TO_DELETE is empty. No changelog files to delete."
67+
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"
68+
exit 0
69+
fi
70+
for file_to_delete in ${V2_CHANGELOG_FILES_TO_DELETE}; do
71+
if [ -f "${file_to_delete}" ]; then
72+
echo "Deleting file: ${file_to_delete}"
73+
FILES_CHANGED=true
74+
rm -f "${file_to_delete}"
75+
fi
76+
done
6077
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"
6178
6279
popd
80+
6381
- name: Create PR
6482
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
6583
if: env.FILES_CHANGED == 'true'
@@ -71,6 +89,7 @@ jobs:
7189
branch: release-cleanup-${{ github.run_id }}
7290
add-paths: |
7391
openapi/v2/*
92+
changelog/version-diff/*
7493
body: |
7594
> NOTE: This PR is autogenerated.
7695
> DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE.

0 commit comments

Comments
 (0)