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
55 changes: 55 additions & 0 deletions .github/scripts/get_list_files_to_delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/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: ${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_OUTPUT:?}"
for file_to_del in "${files_to_delete[@]}"; do
echo "${file_to_del}"
done
else
echo "No files marked for deletion."
fi

popd

84 changes: 84 additions & 0 deletions .github/workflows/release-cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 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: 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
- 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: "APIx-Bot: Release Cleanup 🧹🍃"
commit-message: "release cleanup"
delete-branch: true
branch: release-cleanup-${{ github.run_id }}
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.
9 changes: 9 additions & 0 deletions .github/workflows/release-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down