Skip to content

Commit 7924099

Browse files
author
Sophia Marie Terry
committed
Merge branch 'main' into CLOUDP-328955
2 parents 4e790b4 + bda07c6 commit 7924099

File tree

2 files changed

+190
-28
lines changed

2 files changed

+190
-28
lines changed

.github/scripts/get_sunset_apis.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/usr/bin/env bash
2+
# get_sunset_apis.sh - Identifies API versions scheduled for sunset
3+
#
4+
# This script queries an OpenAPI specification to find API versions that will be
5+
# sunset within a specified date range. When sunset APIs are found,
6+
# it generates a hash code from the results to help with deduplication in
7+
# downstream processes (like JIRA ticket creation) and saves the list to a file.
8+
#
9+
# Usage:
10+
# ./get_sunset_apis.sh <openapi_spec_url> <to_date>
11+
#
12+
# Parameters:
13+
# openapi_spec_url - URL of the OpenAPI specification to analyze
14+
# to_date - End date for the sunset check (format: YY-MM-DD)
15+
#
16+
# Outputs:
17+
# - Prints information about sunset APIs to stdout
18+
# - Writes hash_code_sunset_apis to GitHub Actions output if sunset APIs are found
19+
# - Creates sunset_apis.json containing the list of sunset APIs if any are found
20+
#
21+
# Dependencies:
22+
# - foascli - CLI tool for querying sunset information from OpenAPI specs
23+
# - jq - JSON processor for hash code generation
24+
#
25+
# Exit Status:
26+
# - 0 if the script completes successfully, regardless if sunset APIs are found
27+
# - Non-zero if any commands fail (due to set -e)
28+
set -eou pipefail
29+
30+
if [ $# -lt 2 ]; then
31+
echo "Error: Missing required arguments"
32+
echo "Usage: ./get_sunset_apis.sh <openapi_spec_url> <to_date>"
33+
echo "Example: ./get_sunset_apis.sh openapi/openapi/v2.json 2025-09-22"
34+
exit 1
35+
fi
36+
37+
openapi_spec_url="$1"
38+
to_date="$2"
39+
from_date=$(date +"%y-%m-%d")
40+
41+
echo "openapi_spec_url: ${openapi_spec_url}"
42+
echo "from_date: ${from_date}, to_date: ${to_date}"
43+
44+
sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${from_date}" --to "${to_date}")
45+
if [[ "${sunset_apis}" != "null" ]]; then
46+
echo "api versions that will be sunsets between '${from_date}' - '${to_date}' are: ${sunset_apis}"
47+
48+
# we calculate the md5sum of the json object which will be included in the jira ticket title.
49+
# this approach ensures we create a new jira ticket only if the there is not already a ticket
50+
# with the same title
51+
hash_code_sunset_apis=$(echo "${sunset_apis}" | jq -cs . | md5sum | awk '{print $1}')
52+
echo "hash: ${hash_code_sunset_apis}"
53+
echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}"
54+
echo "${sunset_apis}" > sunset_apis.json
55+
56+
else
57+
echo "no api versions will be sunset within the next 3 months."
58+
fi

.github/workflows/api-versions-reminder.yml

Lines changed: 132 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@ on:
66
- cron: '0 9 * * 1' # at 9:00 UTC on Monday
77

88
jobs:
9-
sunset-api-version-reminder:
9+
sunset-api-version-3months-reminder:
1010
name: Sunset APIs Reminder
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout repository
1414
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
15-
1615
- name: Install Python
1716
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
1817
with:
1918
python-version: '3.12'
20-
2119
- name: Install FOASCLI
2220
env:
2321
foascli_version: ${{ vars.FOASCLI_VERSION }}
@@ -27,7 +25,6 @@ jobs:
2725
pushd mongodb-foas-cli_*
2826
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
2927
popd
30-
3128
- name: Retrieve Sunset APIs
3229
id: retrieve-sunset-apis
3330
env:
@@ -42,29 +39,8 @@ jobs:
4239
else
4340
# Linux date command format
4441
three_months_date=$(date --date="3 months" +"%Y-%m-%d")
45-
fi
46-
47-
echo "three_months_date: ${three_months_date}"
48-
49-
current_date=$(date +"%Y-%m-%d")
50-
echo "current_date: ${current_date}"
51-
52-
sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_months_date}")
53-
if [[ "${sunset_apis}" != "null" ]]; then
54-
echo "API Versions that will be sunsets in the next 3 months: ${sunset_apis}"
55-
56-
# We calculate the md5sum of the JSON object which will be included in the Jira ticket title.
57-
# This approach ensures we create a new jira ticket only if the there is not already a ticket
58-
# with the same title
59-
hash_code_sunset_apis=$(echo "$sunset_apis" | jq -cS . | md5sum | awk '{print $1}')
60-
echo "hash: ${hash_code_sunset_apis}"
61-
echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}"
62-
echo "${sunset_apis}" > sunset_apis.json
63-
64-
else
65-
echo "No API Versions will be sunset within the next 3 months."
66-
fi
67-
42+
fi
43+
./.github/scripts/get_list_files_to_delete.sh "${openapi_spec_url}" "${three_months_date}"
6844
# Create a JIRA ticket only if the there is not already a ticket with the same title
6945
- name: Create JIRA Ticket
7046
id: create-jira-ticket
@@ -92,4 +68,132 @@ jobs:
9268
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
9369
-H 'Content-type: application/json' \
9470
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next 3 months ('"${SLACK_APIX_2_ONCALL_USER}"'). See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
95-
echo "message_id=${message_id}"]
71+
echo "message_id=${message_id}"
72+
73+
sunset-api-version-1month-reminder:
74+
name: Sunset APIs Reminder
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout repository
78+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
79+
- name: Install Python
80+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
81+
with:
82+
python-version: '3.12'
83+
- name: Install FOASCLI
84+
env:
85+
foascli_version: ${{ vars.FOASCLI_VERSION }}
86+
run: |
87+
wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz
88+
tar -xzvf foascli.tar.gz
89+
pushd mongodb-foas-cli_*
90+
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
91+
popd
92+
- name: Retrieve Sunset APIs
93+
id: retrieve-sunset-apis
94+
env:
95+
openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/.raw/v2.json"
96+
run: |
97+
one_month_date=""
98+
99+
# Determine if the system is macOS or Linux
100+
if [[ "$(uname)" == "Darwin" ]]; then
101+
# macOS date command format
102+
one_month_date=$(date -v+1m +"%Y-%m-%d")
103+
else
104+
# Linux date command format
105+
one_month_date=$(date --date="1 months" +"%Y-%m-%d")
106+
fi
107+
./.github/scripts/get_list_files_to_delete.sh "${openapi_spec_url}" "${one_month_date}"
108+
# Create a JIRA ticket only if the there is not already a ticket with the same title
109+
- name: Create JIRA Ticket
110+
id: create-jira-ticket
111+
if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null
112+
env:
113+
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
114+
JIRA_TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_2}}
115+
JIRA_TICKET_TITLE: "Some APIs are approaching their sunset date in the next month. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}"
116+
run: |
117+
sunset_apis=$(sed 's/"/\\"/g' sunset_apis.json)
118+
JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next month. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {noformat}${sunset_apis}{noformat}"
119+
export JIRA_TICKET_DESCRIPTION
120+
.github/scripts/create_jira_ticket.sh
121+
122+
# Send Slack notification only if the Jira ticket was created
123+
- name: Send Slack Notification
124+
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
125+
env:
126+
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
127+
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
128+
SLACK_APIX_2_ONCALL_USER: ${{secrets.SLACK_APIX_2_ONCALL_USER}}
129+
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
130+
run: |
131+
echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}"
132+
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
133+
-H 'Content-type: application/json' \
134+
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next month ('"${SLACK_APIX_2_ONCALL_USER}"'). See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
135+
echo "message_id=${message_id}"
136+
137+
sunset-api-version-1week-reminder:
138+
name: Sunset APIs Reminder
139+
runs-on: ubuntu-latest
140+
steps:
141+
- name: Checkout repository
142+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
143+
- name: Install Python
144+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065
145+
with:
146+
python-version: '3.12'
147+
- name: Install FOASCLI
148+
env:
149+
foascli_version: ${{ vars.FOASCLI_VERSION }}
150+
run: |
151+
wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz
152+
tar -xzvf foascli.tar.gz
153+
pushd mongodb-foas-cli_*
154+
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
155+
popd
156+
- name: Retrieve Sunset APIs
157+
id: retrieve-sunset-apis
158+
env:
159+
openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/.raw/v2.json"
160+
run: |
161+
1_week_date=""
162+
163+
# Determine if the system is macOS or Linux
164+
if [[ "$(uname)" == "Darwin" ]]; then
165+
# macOS date command format
166+
1_week_date=$(date -v+1w +"%Y-%m-%d")
167+
else
168+
# Linux date command format
169+
1_week_date=$(date --date="+1 week" +"%Y-%m-%d")
170+
fi
171+
./.github/scripts/get_list_files_to_delete.sh "${openapi_spec_url}" "${1_week_date}"
172+
# Create a JIRA ticket only if the there is not already a ticket with the same title
173+
- name: Create JIRA Ticket
174+
id: create-jira-ticket
175+
if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null
176+
env:
177+
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
178+
JIRA_TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_2}}
179+
JIRA_TICKET_TITLE: "Some APIs are approaching their sunset date in the next week. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}"
180+
run: |
181+
sunset_apis=$(sed 's/"/\\"/g' sunset_apis.json)
182+
JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next week. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {noformat}${sunset_apis}{noformat}"
183+
export JIRA_TICKET_DESCRIPTION
184+
.github/scripts/create_jira_ticket.sh
185+
186+
# Send Slack notification only if the Jira ticket was created
187+
- name: Send Slack Notification
188+
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
189+
env:
190+
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
191+
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
192+
SLACK_APIX_2_ONCALL_USER: ${{secrets.SLACK_APIX_2_ONCALL_USER}}
193+
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
194+
run: |
195+
echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}"
196+
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
197+
-H 'Content-type: application/json' \
198+
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next week ('"${SLACK_APIX_2_ONCALL_USER}"'). See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
199+
echo "message_id=${message_id}"

0 commit comments

Comments
 (0)