Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/scripts/get_list_files_to_delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
# This script is used in the release cleanup pipeline.
set -eou pipefail

add_changelog_files_to_delete() {
pushd ../../changelog/version-diff

upcoming_version_item="$1"
changelog_files=(./*)

for file in "${changelog_files[@]}"; do
filename=$(basename "$file")
echo "CHANGELOG - upcoming_version_item: ${upcoming_version_item}"
if [[ "${filename}" == *"${upcoming_version_item}"* ]]; then
changelog_files_to_delete+=("${filename}")
fi
done

popd
}

pushd openapi/v2
upcoming_api_versions=$(find . -maxdepth 1 -name 'openapi-*.upcoming.json' -exec basename {} \; | sed -e "s/^openapi-//" -e "s/\.json$//")
echo "upcoming_api_versions: ${upcoming_api_versions}"
Expand All @@ -18,6 +35,7 @@ if [ -z "${upcoming_api_versions}" ]; then
fi

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

# Display the files marked for deletion
if [ ${#files_to_delete[@]} -gt 0 ]; then
echo "V2_OPEN_API_FILES_TO_DELETE=${files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}"
echo "V2_CHANGELOG_FILES_TO_DELETE=${changelog_files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}"

echo "Files to delete:"
for file_to_del in "${files_to_delete[@]}"; do
echo "${file_to_del}"
done

echo "Changelog files to delete:"
for api_to_del in "${changelog_files_to_delete[@]}"; do
echo "${api_to_del}"
done
else
echo "No files marked for deletion."
fi
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/release-cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ jobs:
- name: Delete files
env:
V2_OPEN_API_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_OPEN_API_FILES_TO_DELETE }}
V2_CHANGELOG_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_CHANGELOG_FILES_TO_DELETE }}
run: |
# Delete OpenAPI specs files
pushd openapi/v2

FILES_CHANGED=false
if [ -z "${V2_OPEN_API_FILES_TO_DELETE}" ]; then
echo "V2_OPEN_API_FILES_TO_DELETE is empty. No files to delete."
Expand All @@ -57,9 +58,26 @@ jobs:
rm -f "${file_to_delete}"
fi
done
popd

# Delete Changelog files
pushd changelog/version-diff
if [ -z "${V2_CHANGELOG_FILES_TO_DELETE}" ]; then
echo "V2_CHANGELOG_FILES_TO_DELETE is empty. No changelog files to delete."
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"
exit 0
fi
for file_to_delete in ${V2_CHANGELOG_FILES_TO_DELETE}; do
if [ -f "${file_to_delete}" ]; then
echo "Deleting file: ${file_to_delete}"
FILES_CHANGED=true
rm -f "${file_to_delete}"
fi
done
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"

popd

- name: Create PR
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
if: env.FILES_CHANGED == 'true'
Expand All @@ -71,6 +89,7 @@ jobs:
branch: release-cleanup-${{ github.run_id }}
add-paths: |
openapi/v2/*
changelog/version-diff/*
body: |
> NOTE: This PR is autogenerated.
> DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE.
Expand Down