Skip to content

Commit 1d07015

Browse files
CLOUDP-311380: release cleanup (#741)
1 parent 8d28e8a commit 1d07015

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# get_list_files_to_delete.sh returns a list of files in the repo that are related to "Upcoming" api versions
3+
# that are released to a "Stable" api and are not longer needed.
4+
# This script is used in the release cleanup pipeline.
5+
set -eou pipefail
6+
7+
pushd openapi/v2
8+
upcoming_api_versions=$(find . -maxdepth 1 -name 'openapi-*.upcoming.json' -exec basename {} \; | sed -e "s/^openapi-//" -e "s/\.json$//")
9+
echo "upcoming_api_versions: ${upcoming_api_versions}"
10+
11+
api_versions=$(cat versions.json)
12+
echo "api_versions: ${api_versions}"
13+
14+
15+
if [ -z "${upcoming_api_versions}" ]; then
16+
echo "No upcoming API versions found. Exiting."
17+
exit 0
18+
fi
19+
20+
files_to_delete=()
21+
# Populate upcoming_array line by line from the multi-line upcoming_api_versions string
22+
while IFS= read -r line; do
23+
# Add to array only if line is not empty
24+
if [ -n "$line" ]; then
25+
upcoming_array+=("$line")
26+
fi
27+
done <<< "${upcoming_api_versions}"
28+
echo "upcoming_array: ${upcoming_array[*]}"
29+
30+
for upcoming_version_item in "${upcoming_array[@]}"; do
31+
# Check if the exact upcoming_version_item string (e.g., "2023-01-01.upcoming"),
32+
# when quoted (e.g., "\"2023-01-01.upcoming\""), is NOT found in the api_versions string.
33+
# The condition is true if grep does not find the string (exit status 1).
34+
echo "upcoming_version_item: $upcoming_version_item"
35+
if ! echo "${api_versions}" | grep -qF "\"${upcoming_version_item}\""; then
36+
# If upcoming_version_item is NOT found in api_versions,
37+
# add its corresponding OpenAPI file name (e.g., openapi-2023-01-01.upcoming.json)
38+
# to the files_to_delete array.
39+
files_to_delete+=("openapi-${upcoming_version_item}.json")
40+
files_to_delete+=("openapi-${upcoming_version_item}.yaml")
41+
fi
42+
done
43+
44+
# Display the files marked for deletion
45+
if [ ${#files_to_delete[@]} -gt 0 ]; then
46+
echo "V2_OPEN_API_FILES_TO_DELETE=${files_to_delete[*]}" >> "${GITHUB_OUTPUT:?}"
47+
for file_to_del in "${files_to_delete[@]}"; do
48+
echo "${file_to_del}"
49+
done
50+
else
51+
echo "No files marked for deletion."
52+
fi
53+
54+
popd
55+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Release Cleanup creates a PR to delete any autogenerated file (OAS or changelog) that is no longer needed.
2+
# This may include:
3+
# 1) OASes files of upcoming APIs that are released to a stable api. In this event, we want to keep only the stable OAS.
4+
name: 'Release Cleanup'
5+
on:
6+
workflow_call:
7+
inputs:
8+
env:
9+
description: 'Environment used for the release.'
10+
required: true
11+
type: string
12+
branch:
13+
description: 'Branch used for the release.'
14+
required: true
15+
type: string
16+
secrets:
17+
api_bot_pat:
18+
required: true
19+
jobs:
20+
delete-upcoming-versions-with-stable:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
25+
with:
26+
ref: ${{ inputs.branch }}
27+
token: ${{secrets.api_bot_pat}}
28+
- name: Download release scripts
29+
uses: actions/download-artifact@v4
30+
with:
31+
name: release-scripts
32+
github-token: ${{ secrets.api_bot_pat }}
33+
run-id: ${{ github.run_id }}
34+
path: release-scripts
35+
- name: Add permissions to execute scripts
36+
run: |
37+
chmod +x release-scripts/*.sh
38+
- name: Get List of Files to Delete
39+
id: list_files_to_delete
40+
run: ./release-scripts/get_list_files_to_delete.sh
41+
- name: Delete files
42+
env:
43+
V2_OPEN_API_FILES_TO_DELETE: ${{ steps.list_files_to_delete.outputs.V2_OPEN_API_FILES_TO_DELETE }}
44+
run: |
45+
pushd openapi/v2
46+
47+
FILES_CHANGED=false
48+
if [ -z "${V2_OPEN_API_FILES_TO_DELETE}" ]; then
49+
echo "V2_OPEN_API_FILES_TO_DELETE is empty. No files to delete."
50+
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"
51+
exit 0
52+
fi
53+
for file_to_delete in ${V2_OPEN_API_FILES_TO_DELETE}; do
54+
if [ -f "${file_to_delete}" ]; then
55+
echo "Deleting file: ${file_to_delete}"
56+
FILES_CHANGED=true
57+
rm -f "${file_to_delete}"
58+
fi
59+
done
60+
echo "FILES_CHANGED=${FILES_CHANGED}" >> "$GITHUB_ENV"
61+
62+
popd
63+
- name: Create PR
64+
uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e
65+
if: env.FILES_CHANGED == 'true'
66+
with:
67+
token: ${{ secrets.api_bot_pat }}
68+
title: "APIx-Bot: Release Cleanup 🧹🍃"
69+
commit-message: "release cleanup"
70+
delete-branch: true
71+
branch: release-cleanup-${{ github.run_id }}
72+
add-paths: |
73+
openapi/v2/*
74+
body: |
75+
> NOTE: This PR is autogenerated.
76+
> DO NOT MERGE THE PR IF YOU ARE UNSURE ABOUT THE CHANGE.
77+
78+
# Description
79+
This PR deletes files related to an `Upcoming` api that has been released to a `Stable` API.
80+
81+
## Why?
82+
The MongoDB Admin API renders OpenAPI specifications and changelog files from this repository.
83+
Since this API version is now `Stable`, the files corresponding to its previous `Upcoming` state are obsolete.
84+
Deleting these files prevents the Admin API from inadvertently displaying outdated or irrelevant information from these older specifications and changelogs.

.github/workflows/release-spec.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ jobs:
184184
branch: ${{ inputs.branch }}
185185
foascli_version: ${{ inputs.foascli_version }}
186186

187+
release-cleanup:
188+
needs: [ release, release-changelog]
189+
uses: ./.github/workflows/release-cleanup.yml
190+
with:
191+
env: ${{ inputs.env }}
192+
branch: ${{ inputs.branch }}
193+
secrets:
194+
api_bot_pat: ${{ secrets.api_bot_pat }}
195+
187196
retry-handler:
188197
needs: [ release, release-postman, release-changelog]
189198
if: ${{ always() && contains(needs.*.result, 'failure') && fromJSON(github.run_attempt) < 3}}

0 commit comments

Comments
 (0)