-
Notifications
You must be signed in to change notification settings - Fork 7
136 lines (118 loc) · 6.78 KB
/
api-versions-reminder.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: 'Send a Slack Notification for APIs important events'
on:
workflow_dispatch: # Allow manual triggering
schedule:
- cron: '0 9 * * 1-5' # Run once a day at 09:00 UTC between Monday and Friday
jobs:
new-api-version-reminder:
name: New API Version Release Reminder
runs-on: ubuntu-latest
steps:
- name: Checkout repository (dev branch)
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
sparse-checkout:
.github/scripts/upcoming_api_releases.sh
- name: Install Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: '3.12'
- name: Check if there are upcoming API versions releases
id: check-api-versions
run: .github/scripts/upcoming_api_releases.sh
# Create a JIRA ticket for the upcoming API versions only if the there is not already a ticket with the same title
- name: Create JIRA Ticket
id: create-jira-ticket
if: steps.check-api-versions.outputs.api_versions != null
env:
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
JIRA_TICKET_TITLE: "[API Platform] API Versions (${{steps.check-api-versions.outputs.api_versions}}) are about to be released"
JIRA_TICKET_DESCRIPTION: "The following API Versions are scheduled to be released in the next 3 weeks: ${{steps.check-api-versions.outputs.api_versions}}. Please follow https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APIVersionReleasechecks"
run: .github/scripts/create_jira_ticket.sh
# Send Slack notification only if the Jira ticket was created
- name: Send Slack Notification
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
API_VERSIONS: ${{ steps.check-api-versions.outputs.api_versions }}
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
run: |
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
-H 'Content-type: application/json' \
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following API Versions are scheduled to be released in the next 3 weeks: '"${API_VERSIONS}"'. Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
echo "message_id=${message_id}"
sunset-api-version-reminder:
name: Sunset APIs Reminder
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Install Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: '3.12'
- name: Install FOASCLI
env:
foascli_version: ${{ vars.FOASCLI_VERSION }}
run: |
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
tar -xzvf foascli.tar.gz
pushd mongodb-foas-cli_*
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
popd
- name: Retrieve Sunset APIs
id: retrieve-sunset-apis
env:
openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/v2.json"
run: |
three_months_date=""
# Determine if the system is macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
# macOS date command format
three_months_date=$(date -v+3m +"%Y-%m-%d")
else
# Linux date command format
three_months_date=$(date --date="3 months" +"%Y-%m-%d")
fi
echo "three_months_date: ${three_months_date}"
current_date=$(date +"%Y-%m-%d")
echo "current_date: ${current_date}"
sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_months_date}")
if [[ "${sunset_apis}" != "null" ]]; then
echo "API Versions that will be sunsets in the next 3 months: ${sunset_apis}"
# We calculate the md5sum of the JSON object which will be included in the Jira ticket title.
# This approach ensures we create a new jira ticket only if the there is not already a ticket
# with the same title
hash_code_sunset_apis=$(echo "$sunset_apis" | jq -cS . | md5sum | awk '{print $1}')
echo "hash: ${hash_code_sunset_apis}"
echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}"
echo "${sunset_apis}" > sunset_apis.json
else
echo "No API Versions will be sunset within the next 3 months."
fi
# Create a JIRA ticket only if the there is not already a ticket with the same title
- name: Create JIRA Ticket
id: create-jira-ticket
if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null
env:
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
JIRA_TICKET_TITLE: "[API Platform] Some APIs are approaching their sunset date in the next 3 months. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}"
run: |
sunset_apis=$(sed 's/"/\\"/g' sunset_apis.json)
JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next 3 months. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {noformat}${sunset_apis}{noformat}"
export JIRA_TICKET_DESCRIPTION
.github/scripts/create_jira_ticket.sh
# Send Slack notification only if the Jira ticket was created
- name: Send Slack Notification
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
run: |
echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}"
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
-H 'Content-type: application/json' \
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next 3 months. See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
echo "message_id=${message_id}"]