Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
38 changes: 35 additions & 3 deletions .github/scripts/create_jira_ticket.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
#!/bin/bash

# This script creates a JIRA ticket if one does not already exist with the same title.
# It performs the following steps:
# 1. Defines a function to URL encode a given string.
# 2. URL encodes the JIRA ticket title.
# 3. Checks if a JIRA ticket with the same title already exists in the specified project (id=10984) and component (id=35986).
# 4. If a ticket already exists, it exits without creating a new ticket.
# 5. If no ticket exists, it creates a new JIRA ticket with the provided title and description.
# 6. Outputs the ID of the created JIRA ticket and sets it as a GitHub Actions output variable.

set -eou pipefail

url_encode() {
local string="$1"
local encoded=""
encoded=$(python3 -c "import urllib.parse; print(urllib.parse.quote('''$string'''))")
echo "$encoded"
}

encoded_jira_ticket_title=$(url_encode "${JIRA_TICKET_TITLE:?}")
echo "${encoded_jira_ticket_title}"

found_issue=$(curl --request GET \
--url 'https://jira.mongodb.org/rest/api/2/search?jql=project=10984%20AND%20issuetype=12%20AND%20component=35986%20AND%20summary~"'"${encoded_jira_ticket_title:?}"'"' \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' | jq .total)

if [ "$found_issue" -ne 0 ]; then
echo "There is already a Jira ticket with the title \"${JIRA_TICKET_TITLE:?}\""
echo "No new Jira ticket will be created."
exit 0
fi

json_response=$(curl --request POST \
--url 'https://jira.mongodb.org/rest/api/2/issue' \
--header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \
Expand All @@ -11,14 +43,14 @@ json_response=$(curl --request POST \
"project": {
"id": "10984"
},
"summary": "('"${TARGET_ENV:?}"') The '"${RELEASE_NAME:?}"' release has failed",
"summary": "'"${JIRA_TICKET_TITLE:?}"'",
"issuetype": {
"id": "12"
},
"customfield_12751": [{
"id": "22223"
}],
"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.",
}],
"description": "'"${JIRA_TICKET_DESCRIPTION:?}"'",
"components": [
{
"id": "35986"
Expand Down
59 changes: 59 additions & 0 deletions .github/scripts/upcoming_api_releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -eou pipefail

# This script checks for upcoming API version releases within the next 3 weeks.
# It performs the following steps:
# 1. Fetches and oarse the `versions.json` file using in the `mongodb/openapi` repository deom the `dev` branch
# 2. Gets the current date in seconds since epoch.
# 3. Determines if the system is macOS or Linux to use the appropriate `date` command format.
# 4. Iterates through each date in the `version_dates`:
# a. Converts the date to seconds since epoch.
# b. Calculates the difference in days between the date and the current date.
# c. Checks if the date is within 3 weeks (21 days) and adds it to the list if it is.
# 5. Outputs the API versions that will be released in the next 3 weeks to the GitHub Actions output variable if any are found.


URL="https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.json"

# Fetch the version.json file
response=$(curl -s "${URL}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering what will be our plan long-term with .sh logic in our platform since in the past it has proven itself difficult to maintain, perharps we can add unit tests here like it was explored with the postman project? OK to make it in a follow-up PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a ticket to investigate how much time we might need to migrate these scripts to golang


# Parse the version_dates from the JSON response using jq
version_dates=$(echo "${response}" | jq -r '.[]')

# Initialize an empty list to store version_dates within 3 weeks
version_dates_within_3_weeks=()

# Get the current date in seconds since epoch
current_date=$(date +%s)

# Determine if the system is macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
# macOS date command format
date_command="date -j -f %Y-%m-%d"
else
# Linux date command format
date_command="date -d"
fi

# Iterate through each date
for version_date in ${version_dates}; do
# Convert the date to seconds since epoch with explicit format
date_in_seconds=$($date_command "${version_date}" +%s 2>/dev/null)

# Calculate the difference in days between the date and the current date
diff_in_days=$(( (date_in_seconds - current_date) / (60 * 60 * 24) ))

# Check if the date is within 3 weeks (21 days)
if [[ "${diff_in_days}" -ge 0 && "${diff_in_days}" -le 21 ]]; then
# Add the date to the list if within 3 weeks
version_dates_within_3_weeks+=("${date}")
fi
done

if [[ ${#version_dates_within_3_weeks[@]} -gt 0 ]]; then
echo "API Versions that will be release in the next 3 weeks: ${version_dates_within_3_weeks[*]}"
echo api_versions="${version_dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}"
else
echo "No API Versions that will be released within the next 3 weeks."
fi
49 changes: 49 additions & 0 deletions .github/workflows/api-versions-reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'Send a Slack Notification for upcoming release of API versions'

on:
workflow_dispatch: # Allow manual triggering
schedule:
- cron: '0 9 * * *' # Run once a day at 09:00 UTC

jobs:
send-changelog-report:
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@f677139bbe7f9c59b41e40162b753c062f5d49a3
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: "New 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}}"
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/'"${env.JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
echo "message_id=${message_id}"
5 changes: 2 additions & 3 deletions .github/workflows/failure-handler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ jobs:
if: ${{ steps.create-issue.outputs.number != null }}
id: create-jira-ticket
env:
TARGET_ENV: ${{ inputs.env }}
RELEASE_NAME: ${{ inputs.release_name }}
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
ISSUE_ID: ${{ steps.create-issue.outputs.number }}
JIRA_TICKET_TITLE: "(${{inputs.env}}) The ${{inputs.release_name}} release has failed. GH Issue: ${{steps.create-issue.outputs.number}}"
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."
run: .github/scripts/create_jira_ticket.sh
- name: Add comment to GH Issue
if: ${{ steps.create-issue.outputs.number != null }}
Expand Down
Loading