From 57c52779324a6ab47a403edc2e2a67fc0ad6802c Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 4 Jun 2025 13:01:16 +0200 Subject: [PATCH 1/4] CLOUDP-311380: release clenup --- .github/scripts/get_list_files_to_delete.sh | 56 +++++++++++++++ .github/workflows/release-cleanup.yml | 79 +++++++++++++++++++++ .github/workflows/release-spec.yml | 9 +++ 3 files changed, 144 insertions(+) create mode 100755 .github/scripts/get_list_files_to_delete.sh create mode 100644 .github/workflows/release-cleanup.yml diff --git a/.github/scripts/get_list_files_to_delete.sh b/.github/scripts/get_list_files_to_delete.sh new file mode 100755 index 0000000000..00315bb4e3 --- /dev/null +++ b/.github/scripts/get_list_files_to_delete.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# get_list_files_to_delete.sh returns a list of files in the repo that are related to "Upcoming" api versions +# that are released to a "Stable" api and are not longer needed. +# This script is used in the release cleanup pipeline. +set -eou pipefail + +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:" +echo "${upcoming_api_versions}" + +api_versions=$(cat versions.json) +echo "api_versions: ${api_versions}" + + +if [ -z "${upcoming_api_versions}" ]; then + echo "No upcoming API versions found. Exiting." + exit 0 +fi + +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 + if [ -n "$line" ]; then + upcoming_array+=("$line") + fi +done <<< "${upcoming_api_versions}" +echo "upcoming_array: ${upcoming_array[*]}" + +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" + 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") + 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_ENV:?}" + for file_to_del in "${files_to_delete[@]}"; do + echo "${file_to_del}" + done +else + echo "No files marked for deletion." +fi + +popd + diff --git a/.github/workflows/release-cleanup.yml b/.github/workflows/release-cleanup.yml new file mode 100644 index 0000000000..c0fda7caef --- /dev/null +++ b/.github/workflows/release-cleanup.yml @@ -0,0 +1,79 @@ +# Release Cleanup creates a PR to delete any autogenerated file (OAS or changelog) that is no longer needed. +# This may include: +# 1) OASes files of upcoming APIs that are released to a stable api. In this event, we want to keep only the stable OAS. +name: 'Release Cleanup' +on: + workflow_call: + inputs: + env: + description: 'Environment used for the release.' + required: true + type: string + branch: + description: 'Branch used for the release.' + required: true + type: string + secrets: + api_bot_pat: + required: true +jobs: + delete-upcoming-versions-with-stable: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + with: + ref: ${{ inputs.branch }} + token: ${{secrets.api_bot_pat}} + - name: Download release scripts + uses: actions/download-artifact@v4 + with: + name: release-scripts + github-token: ${{ secrets.api_bot_pat }} + run-id: ${{ github.run_id }} + path: release-scripts + - name: Get List of Files to Delete + id: list_files_to_delete + run: ./release-scripts/get_list_files_to_delete.sh + - name: Delete files + env: + V2_OPEN_API_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_OPEN_API_FILES_TO_DELETE }} + run: | + 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." + echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV" + exit 0 + fi + for file_to_delete in ${V2_OPEN_API_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' + with: + token: ${{ secrets.api_bot_pat }} + title: "APIBot: Release Cleanup" + commit-message: "release cleanup" + delete-branch: true + branch: release-cleanup-${{ github.run_id }} + body: | + > NOTE: This PR is autogenerated. + > DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE. + + # Description + This PR deletes files related to an "Upcoming" api that has been released to a "Stable" API. + + ## Why? + The MongoDB Admin API renders OpenAPI specifications and changelog files from this repository. + Since this API version is now “Stable,” the files corresponding to its previous “Upcoming” state are obsolete. + Deleting these files prevents the Admin API from inadvertently displaying outdated or irrelevant information from these older specifications and changelogs. diff --git a/.github/workflows/release-spec.yml b/.github/workflows/release-spec.yml index c52a457eec..6c12962127 100644 --- a/.github/workflows/release-spec.yml +++ b/.github/workflows/release-spec.yml @@ -184,6 +184,15 @@ jobs: branch: ${{ inputs.branch }} foascli_version: ${{ inputs.foascli_version }} + release-cleanup: + needs: [ release, release-changelog] + uses: ./.github/workflows/release-cleanup.yml + with: + env: ${{ inputs.env }} + branch: ${{ inputs.branch }} + secrets: + api_bot_pat: ${{ secrets.api_bot_pat }} + retry-handler: needs: [ release, release-postman, release-changelog] if: ${{ always() && contains(needs.*.result, 'failure') && fromJSON(github.run_attempt) < 3}} From 178a718ad85c04ca9a1b682e016e7c89d9cff297 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 5 Jun 2025 14:59:35 +0200 Subject: [PATCH 2/4] Update release-cleanup.yml --- .github/workflows/release-cleanup.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release-cleanup.yml b/.github/workflows/release-cleanup.yml index c0fda7caef..7750f372e7 100644 --- a/.github/workflows/release-cleanup.yml +++ b/.github/workflows/release-cleanup.yml @@ -32,6 +32,9 @@ jobs: github-token: ${{ secrets.api_bot_pat }} run-id: ${{ github.run_id }} path: release-scripts + - name: Add permissions to execute scripts + run: | + chmod +x release-scripts/*.sh - name: Get List of Files to Delete id: list_files_to_delete run: ./release-scripts/get_list_files_to_delete.sh From 9eda719c0e12b49d8abbd87e05c3924f2f27e6fa Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 5 Jun 2025 16:32:02 +0200 Subject: [PATCH 3/4] fixes --- .github/scripts/get_list_files_to_delete.sh | 2 +- .github/workflows/release-cleanup.yml | 26 +++++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/scripts/get_list_files_to_delete.sh b/.github/scripts/get_list_files_to_delete.sh index 00315bb4e3..a732bfa541 100755 --- a/.github/scripts/get_list_files_to_delete.sh +++ b/.github/scripts/get_list_files_to_delete.sh @@ -44,7 +44,7 @@ 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_ENV:?}" + echo "V2_OPEN_API_FILES_TO_DELETE=${files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}" for file_to_del in "${files_to_delete[@]}"; do echo "${file_to_del}" done diff --git a/.github/workflows/release-cleanup.yml b/.github/workflows/release-cleanup.yml index 7750f372e7..02e0f8a645 100644 --- a/.github/workflows/release-cleanup.yml +++ b/.github/workflows/release-cleanup.yml @@ -65,18 +65,20 @@ jobs: if: env.FILES_CHANGED == 'true' with: token: ${{ secrets.api_bot_pat }} - title: "APIBot: Release Cleanup" + title: "APIx-Bot: Release Cleanup 🧹🍃" commit-message: "release cleanup" delete-branch: true branch: release-cleanup-${{ github.run_id }} - body: | - > NOTE: This PR is autogenerated. - > DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE. - - # Description - This PR deletes files related to an "Upcoming" api that has been released to a "Stable" API. - - ## Why? - The MongoDB Admin API renders OpenAPI specifications and changelog files from this repository. - Since this API version is now “Stable,” the files corresponding to its previous “Upcoming” state are obsolete. - Deleting these files prevents the Admin API from inadvertently displaying outdated or irrelevant information from these older specifications and changelogs. + add-paths: | + openapi/v2/* + body: | + > NOTE: This PR is autogenerated. + > DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE. + + # Description + This PR deletes files related to an `Upcoming` api that has been released to a `Stable` API. + + ## Why? + The MongoDB Admin API renders OpenAPI specifications and changelog files from this repository. + Since this API version is now `Stable`, the files corresponding to its previous `Upcoming` state are obsolete. + Deleting these files prevents the Admin API from inadvertently displaying outdated or irrelevant information from these older specifications and changelogs. From 85c23a919d45929a12e1765f7bb77b3d9ff7184b Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 5 Jun 2025 17:27:29 +0200 Subject: [PATCH 4/4] Addressed Melanija's comment --- .github/scripts/get_list_files_to_delete.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/scripts/get_list_files_to_delete.sh b/.github/scripts/get_list_files_to_delete.sh index a732bfa541..463c8806ae 100755 --- a/.github/scripts/get_list_files_to_delete.sh +++ b/.github/scripts/get_list_files_to_delete.sh @@ -6,8 +6,7 @@ set -eou pipefail 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:" -echo "${upcoming_api_versions}" +echo "upcoming_api_versions: ${upcoming_api_versions}" api_versions=$(cat versions.json) echo "api_versions: ${api_versions}"