From d829c9b1f6b3dd6ba10574c59f62193bf38c0e8f Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 17 Oct 2024 18:04:49 +0100 Subject: [PATCH 1/8] CLOUDP-278929: Send a remind if an API version is approching the release date --- .github/scripts/upcoming_api_releases.sh | 48 +++++++++++++++++++++ .github/workflows/api-versions-reminder.yml | 31 +++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 .github/scripts/upcoming_api_releases.sh create mode 100644 .github/workflows/api-versions-reminder.yml diff --git a/.github/scripts/upcoming_api_releases.sh b/.github/scripts/upcoming_api_releases.sh new file mode 100755 index 0000000000..af0a4010f1 --- /dev/null +++ b/.github/scripts/upcoming_api_releases.sh @@ -0,0 +1,48 @@ +#!/bin/bash +set -eou pipefail + + +URL="https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.json" + +# Fetch the version.json file +response=$(curl -s "${URL}") + +# Parse the dates from the JSON response using jq +dates=$(echo "${response}" | jq -r '.[]') + +# Initialize an empty list to store dates within 3 weeks +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 date in $dates; do + # Convert the date to seconds since epoch with explicit format + date_in_seconds=$($date_command "${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 + dates_within_3_weeks+=("${date}") + fi +done + +if [[ ${#dates_within_3_weeks[@]} -gt 0 ]]; then + echo "API Versions that will be release in the next 3 weeks: ${dates_within_3_weeks[*]}" + echo api_versions="${dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}" +else + echo "No API Versions that will be released within the next 3 weeks." +fi \ No newline at end of file diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml new file mode 100644 index 0000000000..6613a3c076 --- /dev/null +++ b/.github/workflows/api-versions-reminder.yml @@ -0,0 +1,31 @@ +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: Check if there are upcoming API versions releases + id: check-api-versions + run: .github/scripts/upcoming_api_releases.sh + - name: Get Start and End Dates + id: Send the Slack Notification + if: steps.check-api-versions.outputs.api_versions != 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 }} + 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}. CC @apix-2-on-call","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + From e60f6df1554e79834ef432d3e8771fc7533711a4 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 17 Oct 2024 18:08:12 +0100 Subject: [PATCH 2/8] Update upcoming_api_releases.sh --- .github/scripts/upcoming_api_releases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/upcoming_api_releases.sh b/.github/scripts/upcoming_api_releases.sh index af0a4010f1..852cfc6b97 100755 --- a/.github/scripts/upcoming_api_releases.sh +++ b/.github/scripts/upcoming_api_releases.sh @@ -45,4 +45,4 @@ if [[ ${#dates_within_3_weeks[@]} -gt 0 ]]; then echo api_versions="${dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}" else echo "No API Versions that will be released within the next 3 weeks." -fi \ No newline at end of file +fi From 48997032d689951eb70220bae537f57b0243e27d Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Thu, 17 Oct 2024 18:29:52 +0100 Subject: [PATCH 3/8] CLOUDP-278929: Send a remind if an API version is approching the release date --- .github/workflows/api-versions-reminder.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 6613a3c076..a13e3fc84b 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -18,7 +18,6 @@ jobs: id: check-api-versions run: .github/scripts/upcoming_api_releases.sh - name: Get Start and End Dates - id: Send the Slack Notification if: steps.check-api-versions.outputs.api_versions != null env: SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }} @@ -27,5 +26,5 @@ jobs: 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}. CC @apix-2-on-call","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') - + --data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following API Versions are scheduled to be released in the next 3 weeks: '"${API_VERSIONS}"'. CC @apix-2-on-call","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + echo "message_id=${message_id}" From 6fd4900e74bb55f9963493f60c6956cd82be88fc Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Fri, 18 Oct 2024 11:17:41 +0100 Subject: [PATCH 4/8] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index a13e3fc84b..d4522ff455 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -3,7 +3,7 @@ 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 + - cron: '0 9 * * 1' # Run at 09:00 UTC every Monday jobs: send-changelog-report: From 98ec78ff69f9390f52e09d59e599a3a9961c272c Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 23 Oct 2024 13:48:46 +0100 Subject: [PATCH 5/8] Add logic to check for a Jira ticket with the same title This commit update the logic in the create_jira_ticket.sh to check for a ticket with the same title before creating the ticket --- .github/scripts/create_jira_ticket.sh | 34 +++++++++++++++++++-- .github/scripts/upcoming_api_releases.sh | 20 ++++++------ .github/workflows/api-versions-reminder.yml | 18 +++++++++-- .github/workflows/failure-handler.yml | 5 ++- 4 files changed, 59 insertions(+), 18 deletions(-) diff --git a/.github/scripts/create_jira_ticket.sh b/.github/scripts/create_jira_ticket.sh index 6727ef875f..49c2e6a639 100755 --- a/.github/scripts/create_jira_ticket.sh +++ b/.github/scripts/create_jira_ticket.sh @@ -1,6 +1,36 @@ #!/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" + printf '%s' "$string" | xxd -p | sed 's/\(..\)/%\1/g' +} + +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:?}" \ @@ -11,14 +41,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" diff --git a/.github/scripts/upcoming_api_releases.sh b/.github/scripts/upcoming_api_releases.sh index 852cfc6b97..0bb5939159 100755 --- a/.github/scripts/upcoming_api_releases.sh +++ b/.github/scripts/upcoming_api_releases.sh @@ -7,11 +7,11 @@ URL="https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.j # Fetch the version.json file response=$(curl -s "${URL}") -# Parse the dates from the JSON response using jq -dates=$(echo "${response}" | jq -r '.[]') +# Parse the version_dates from the JSON response using jq +version_dates=$(echo "${response}" | jq -r '.[]') -# Initialize an empty list to store dates within 3 weeks -dates_within_3_weeks=() +# 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) @@ -26,9 +26,9 @@ else fi # Iterate through each date -for date in $dates; do +for version_date in ${version_dates}; do # Convert the date to seconds since epoch with explicit format - date_in_seconds=$($date_command "${date}" +%s 2>/dev/null) + 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) )) @@ -36,13 +36,13 @@ for date in $dates; do # 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 - dates_within_3_weeks+=("${date}") + version_dates_within_3_weeks+=("${date}") fi done -if [[ ${#dates_within_3_weeks[@]} -gt 0 ]]; then - echo "API Versions that will be release in the next 3 weeks: ${dates_within_3_weeks[*]}" - echo api_versions="${dates_within_3_weeks[*]}" >> "${GITHUB_OUTPUT:?}" +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 diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index d4522ff455..ee449a4f0f 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -3,7 +3,7 @@ name: 'Send a Slack Notification for upcoming release of API versions' on: workflow_dispatch: # Allow manual triggering schedule: - - cron: '0 9 * * 1' # Run at 09:00 UTC every Monday + - cron: '0 9 * * *' # Run once a day at 09:00 UTC jobs: send-changelog-report: @@ -17,14 +17,26 @@ jobs: - name: Check if there are upcoming API versions releases id: check-api-versions run: .github/scripts/upcoming_api_releases.sh - - name: Get Start and End Dates + + # 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 + + - 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}"'. CC @apix-2-on-call","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + --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}" diff --git a/.github/workflows/failure-handler.yml b/.github/workflows/failure-handler.yml index dbf9ac01aa..26d7b97df6 100644 --- a/.github/workflows/failure-handler.yml +++ b/.github/workflows/failure-handler.yml @@ -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 }} From 9ebf20209113dfe0da3a22f8ce5265d3cbbe20bb Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 23 Oct 2024 13:51:44 +0100 Subject: [PATCH 6/8] Update upcoming_api_releases.sh --- .github/scripts/upcoming_api_releases.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/scripts/upcoming_api_releases.sh b/.github/scripts/upcoming_api_releases.sh index 0bb5939159..a698801c5c 100755 --- a/.github/scripts/upcoming_api_releases.sh +++ b/.github/scripts/upcoming_api_releases.sh @@ -1,6 +1,17 @@ #!/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" From 64a240e09a1b7a782194d5e5d256a269b8d988cf Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 23 Oct 2024 14:22:16 +0100 Subject: [PATCH 7/8] fixes --- .github/scripts/create_jira_ticket.sh | 18 ++++++++++-------- .github/workflows/api-versions-reminder.yml | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/scripts/create_jira_ticket.sh b/.github/scripts/create_jira_ticket.sh index 49c2e6a639..08e4e6944f 100755 --- a/.github/scripts/create_jira_ticket.sh +++ b/.github/scripts/create_jira_ticket.sh @@ -13,21 +13,23 @@ set -eou pipefail url_encode() { local string="$1" - printf '%s' "$string" | xxd -p | sed 's/\(..\)/%\1/g' + 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) + --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" + echo "There is already a Jira ticket with the title \"${JIRA_TICKET_TITLE:?}\"" + echo "No new Jira ticket will be created." exit 0 fi @@ -47,7 +49,7 @@ json_response=$(curl --request POST \ }, "customfield_12751": [{ "id": "22223" - }], + }], "description": "'"${JIRA_TICKET_DESCRIPTION:?}"'", "components": [ { diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index ee449a4f0f..1294904a5f 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -14,6 +14,12 @@ jobs: 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 @@ -28,6 +34,7 @@ jobs: 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: From fa6b290852d5f1e8d7764ff47cd70d3206b992c2 Mon Sep 17 00:00:00 2001 From: Andrea Angiolillo Date: Wed, 23 Oct 2024 15:24:26 +0100 Subject: [PATCH 8/8] Update .github/scripts/upcoming_api_releases.sh Co-authored-by: Bianca Lisle <40155621+blva@users.noreply.github.com> --- .github/scripts/upcoming_api_releases.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/upcoming_api_releases.sh b/.github/scripts/upcoming_api_releases.sh index a698801c5c..95c5444d83 100755 --- a/.github/scripts/upcoming_api_releases.sh +++ b/.github/scripts/upcoming_api_releases.sh @@ -3,7 +3,7 @@ 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 +# 1. Fetches and parses the `versions.json` file using in the `mongodb/openapi` repository on 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`: