Skip to content

Commit 9b3b72c

Browse files
CLOUDP-278929: Send a remind if an API version is approching the release date (#260)
1 parent 1fd4a30 commit 9b3b72c

File tree

4 files changed

+145
-6
lines changed

4 files changed

+145
-6
lines changed

.github/scripts/create_jira_ticket.sh

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,38 @@
11
#!/bin/bash
2+
3+
# This script creates a JIRA ticket if one does not already exist with the same title.
4+
# It performs the following steps:
5+
# 1. Defines a function to URL encode a given string.
6+
# 2. URL encodes the JIRA ticket title.
7+
# 3. Checks if a JIRA ticket with the same title already exists in the specified project (id=10984) and component (id=35986).
8+
# 4. If a ticket already exists, it exits without creating a new ticket.
9+
# 5. If no ticket exists, it creates a new JIRA ticket with the provided title and description.
10+
# 6. Outputs the ID of the created JIRA ticket and sets it as a GitHub Actions output variable.
11+
212
set -eou pipefail
313

14+
url_encode() {
15+
local string="$1"
16+
local encoded=""
17+
encoded=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$string'''))")
18+
echo "$encoded"
19+
}
20+
21+
encoded_jira_ticket_title=$(url_encode "${JIRA_TICKET_TITLE:?}")
22+
echo "${encoded_jira_ticket_title}"
23+
24+
found_issue=$(curl --request GET \
25+
--url 'https://jira.mongodb.org/rest/api/2/search?jql=project=10984%20AND%20issuetype=12%20AND%20component=35986%20AND%20summary~"'"${encoded_jira_ticket_title:?}"'"' \
26+
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
27+
--header 'Accept: application/json' \
28+
--header 'Content-Type: application/json' | jq .total)
29+
30+
if [ "$found_issue" -ne 0 ]; then
31+
echo "There is already a Jira ticket with the title \"${JIRA_TICKET_TITLE:?}\""
32+
echo "No new Jira ticket will be created."
33+
exit 0
34+
fi
35+
436
json_response=$(curl --request POST \
537
--url 'https://jira.mongodb.org/rest/api/2/issue' \
638
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
@@ -11,14 +43,14 @@ json_response=$(curl --request POST \
1143
"project": {
1244
"id": "10984"
1345
},
14-
"summary": "('"${TARGET_ENV:?}"') The '"${RELEASE_NAME:?}"' release has failed",
46+
"summary": "'"${JIRA_TICKET_TITLE:?}"'",
1547
"issuetype": {
1648
"id": "12"
1749
},
1850
"customfield_12751": [{
1951
"id": "22223"
20-
}],
21-
"description": "The release process '"${RELEASE_NAME:?}"' in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-'"${ISSUE_ID:?}"'|https://github.com/mongodb/openapi/issues/'"${ISSUE_ID}"'] for more details.",
52+
}],
53+
"description": "'"${JIRA_TICKET_DESCRIPTION:?}"'",
2254
"components": [
2355
{
2456
"id": "35986"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
set -eou pipefail
3+
4+
# This script checks for upcoming API version releases within the next 3 weeks.
5+
# It performs the following steps:
6+
# 1. Fetches and parses the `versions.json` file using in the `mongodb/openapi` repository on the `dev` branch
7+
# 2. Gets the current date in seconds since epoch.
8+
# 3. Determines if the system is macOS or Linux to use the appropriate `date` command format.
9+
# 4. Iterates through each date in the `version_dates`:
10+
# a. Converts the date to seconds since epoch.
11+
# b. Calculates the difference in days between the date and the current date.
12+
# c. Checks if the date is within 3 weeks (21 days) and adds it to the list if it is.
13+
# 5. Outputs the API versions that will be released in the next 3 weeks to the GitHub Actions output variable if any are found.
14+
15+
16+
URL="https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.json"
17+
18+
# Fetch the version.json file
19+
response=$(curl -s "${URL}")
20+
21+
# Parse the version_dates from the JSON response using jq
22+
version_dates=$(echo "${response}" | jq -r '.[]')
23+
24+
# Initialize an empty list to store version_dates within 3 weeks
25+
version_dates_within_3_weeks=()
26+
27+
# Get the current date in seconds since epoch
28+
current_date=$(date +%s)
29+
30+
# Determine if the system is macOS or Linux
31+
if [[ "$(uname)" == "Darwin" ]]; then
32+
# macOS date command format
33+
date_command="date -j -f %Y-%m-%d"
34+
else
35+
# Linux date command format
36+
date_command="date -d"
37+
fi
38+
39+
# Iterate through each date
40+
for version_date in ${version_dates}; do
41+
# Convert the date to seconds since epoch with explicit format
42+
date_in_seconds=$($date_command "${version_date}" +%s 2>/dev/null)
43+
44+
# Calculate the difference in days between the date and the current date
45+
diff_in_days=$(( (date_in_seconds - current_date) / (60 * 60 * 24) ))
46+
47+
# Check if the date is within 3 weeks (21 days)
48+
if [[ "${diff_in_days}" -ge 0 && "${diff_in_days}" -le 21 ]]; then
49+
# Add the date to the list if within 3 weeks
50+
version_dates_within_3_weeks+=("${date}")
51+
fi
52+
done
53+
54+
if [[ ${#version_dates_within_3_weeks[@]} -gt 0 ]]; then
55+
echo "API Versions that will be release in the next 3 weeks: ${version_dates_within_3_weeks[*]}"
56+
echo api_versions="${version_dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}"
57+
else
58+
echo "No API Versions that will be released within the next 3 weeks."
59+
fi
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: 'Send a Slack Notification for upcoming release of API versions'
2+
3+
on:
4+
workflow_dispatch: # Allow manual triggering
5+
schedule:
6+
- cron: '0 9 * * *' # Run once a day at 09:00 UTC
7+
8+
jobs:
9+
send-changelog-report:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository (dev branch)
13+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
14+
with:
15+
sparse-checkout:
16+
.github/scripts/upcoming_api_releases.sh
17+
18+
- name: Install Python
19+
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
20+
with:
21+
python-version: '3.12'
22+
23+
- name: Check if there are upcoming API versions releases
24+
id: check-api-versions
25+
run: .github/scripts/upcoming_api_releases.sh
26+
27+
# Create a JIRA ticket for the upcoming API versions only if the there is not already a ticket with the same title
28+
- name: Create JIRA Ticket
29+
id: create-jira-ticket
30+
if: steps.check-api-versions.outputs.api_versions != null
31+
env:
32+
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
33+
JIRA_TICKET_TITLE: "New API Versions ${{steps.check-api-versions.outputs.api_versions}} are about to be released"
34+
JIRA_TICKET_DESCRIPTION: "The following API Versions are scheduled to be released in the next 3 weeks: ${{steps.check-api-versions.outputs.api_versions}}"
35+
run: .github/scripts/create_jira_ticket.sh
36+
37+
# Send Slack notification only if the Jira ticket was created
38+
- name: Send Slack Notification
39+
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
40+
env:
41+
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
42+
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
43+
API_VERSIONS: ${{ steps.check-api-versions.outputs.api_versions }}
44+
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
45+
run: |
46+
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
47+
-H 'Content-type: application/json' \
48+
--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/'"${env.JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
49+
echo "message_id=${message_id}"

.github/workflows/failure-handler.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ jobs:
6969
if: ${{ steps.create-issue.outputs.number != null }}
7070
id: create-jira-ticket
7171
env:
72-
TARGET_ENV: ${{ inputs.env }}
73-
RELEASE_NAME: ${{ inputs.release_name }}
7472
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
75-
ISSUE_ID: ${{ steps.create-issue.outputs.number }}
73+
JIRA_TICKET_TITLE: "(${{inputs.env}}) The ${{inputs.release_name}} release has failed. GH Issue: ${{steps.create-issue.outputs.number}}"
74+
JIRA_TICKET_DESCRIPTION: "The release process ${{inputs.release_name}} in [mongodb/openapi|https://github.com/mongodb/openapi] has failed. Please, look at the [issue-${{steps.create-issue.outputs.number}}|https://github.com/mongodb/openapi/issues/${{steps.create-issue.outputs.number}}] for more details."
7675
run: .github/scripts/create_jira_ticket.sh
7776
- name: Add comment to GH Issue
7877
if: ${{ steps.create-issue.outputs.number != null }}

0 commit comments

Comments
 (0)