From 04dc85b3c951984f0d122cd00d67025dd9f42f0c Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 11:42:15 +0000 Subject: [PATCH 1/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 87 ++++++++++++++++++++- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 00b4831862..35b712f3d8 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -1,4 +1,4 @@ -name: 'Send a Slack Notification for upcoming release of API versions' +name: 'Send a Slack Notification for APIs important events' on: workflow_dispatch: # Allow manual triggering @@ -6,7 +6,8 @@ on: - cron: '0 9 * * 1-5' # Run once a day at 09:00 UTC between Monday and Friday jobs: - send-api-version-reminder: + new-api-version-reminder: + name: New API Version Release Reminder runs-on: ubuntu-latest steps: - name: Checkout repository (dev branch) @@ -47,3 +48,85 @@ jobs: -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 + with: + sparse-checkout: + .github/scripts/upcoming_api_releases.sh + + - 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/dev/openapi/v2/versions.json" + run: | + three_weeks_date="" + # Determine if the system is macOS or Linux + if [[ "$(uname)" == "Darwin" ]]; then + # macOS date command format + three_weeks_date=$(date -v+3w +"%Y-%m-%d") + else + # Linux date command format + three_weeks_date=$(date --date="3 weeks" +"%Y-%m-%d") + fi + + current_date=$(date +%s) + sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_weeks_date}") + if [[ "$(sunset_apis)" != "null" ]]; then + echo "API Versions that will be sunsets in the next 3 weeks: ${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 sunset_apis="${sunset_apis}" >> "${GITHUB_OUTPUT:?}" + echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}" + + else + echo "No API Versions will be sunset within the next 3 weeks." + 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.sunset_apis != null + env: + JIRA_API_TOKEN: ${{ secrets.jira_api_token }} + JIRA_TICKET_TITLE: "[API Platform] Some APIs are approaching their sunset date. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}" + JIRA_TICKET_DESCRIPTION: "The following APIs will be sunset in the next 3 weeks. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {code:json}${{steps.retrieve-sunset-apis.outputs.sunset_apis}}{code}" + 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 }} + SUNSET_APIS: ${{ steps.retrieve-sunset-apis.outputs.sunset_apis }} + 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 APIs are scheduled to be sunset in the next 3 weeks: see :thread:. 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}"] + + sleep 2 # wait for 2 seconds to avoid slack rate limit + + curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ + -H 'Content-type: application/json' \ + --data '{"channel":"'"${SLACK_CHANNEL_ID}"'",{"thread_ts":"'"${message_id}"'","text":"'"${SUNSET_APIS}"'","parse": "full",}' https://slack.com/api/chat.postMessage From 7e2bd756f05ca3b14e298484472e0c5e7488139c Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 11:46:31 +0000 Subject: [PATCH 2/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 35b712f3d8..21949d5d9b 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -127,6 +127,7 @@ jobs: sleep 2 # wait for 2 seconds to avoid slack rate limit + # Add the JSON array as a reply to message thread curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ -H 'Content-type: application/json' \ --data '{"channel":"'"${SLACK_CHANNEL_ID}"'",{"thread_ts":"'"${message_id}"'","text":"'"${SUNSET_APIS}"'","parse": "full",}' https://slack.com/api/chat.postMessage From 1aede4697f8f378e890a1cf24fa1f12f1dcbed13 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 12:00:35 +0000 Subject: [PATCH 3/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 21949d5d9b..bc9eae27fe 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -93,7 +93,8 @@ jobs: # 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 sunset_apis="${sunset_apis}" >> "${GITHUB_OUTPUT:?}" echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}" From fb07d7376e03e06829ad609bd92350c283ad0279 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 17:54:06 +0000 Subject: [PATCH 4/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 39 +++++++++++---------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index bc9eae27fe..857fd2f731 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -55,9 +55,11 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 + + - name: Install Python + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b with: - sparse-checkout: - .github/scripts/upcoming_api_releases.sh + python-version: '3.12' - name: Install FOASCLI env: @@ -84,20 +86,23 @@ jobs: three_weeks_date=$(date --date="3 weeks" +"%Y-%m-%d") fi - current_date=$(date +%s) + echo "three_weeks_date: ${three_weeks_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_weeks_date}") if [[ "$(sunset_apis)" != "null" ]]; then echo "API Versions that will be sunsets in the next 3 weeks: ${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 sunset_apis="${sunset_apis}" >> "${GITHUB_OUTPUT:?}" 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 weeks." fi @@ -105,12 +110,15 @@ jobs: # 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.sunset_apis != null + 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. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}" - JIRA_TICKET_DESCRIPTION: "The following APIs will be sunset in the next 3 weeks. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {code:json}${{steps.retrieve-sunset-apis.outputs.sunset_apis}}{code}" - run: .github/scripts/create_jira_ticket.sh + run: | + sunset_apis=$(cat sunset_apis.json | sed 's/"/\\"/g') + JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next 3 weeks. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {code:json}${sunset_apis}{code}" + export JIRA_TICKET_DESCRIPTION + .github/scripts/create_jira_ticket.sh # Send Slack notification only if the Jira ticket was created - name: Send Slack Notification @@ -118,17 +126,10 @@ jobs: env: SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }} SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }} - SUNSET_APIS: ${{ steps.retrieve-sunset-apis.outputs.sunset_apis }} 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 weeks: see :thread:. Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + --data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"The following APIs are scheduled to be sunset in the next 3 weeks. 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}"] - - sleep 2 # wait for 2 seconds to avoid slack rate limit - - # Add the JSON array as a reply to message thread - curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ - -H 'Content-type: application/json' \ - --data '{"channel":"'"${SLACK_CHANNEL_ID}"'",{"thread_ts":"'"${message_id}"'","text":"'"${SUNSET_APIS}"'","parse": "full",}' https://slack.com/api/chat.postMessage From a8aa1d06332d05ab8b939a655b3c3677d05e74b1 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 18:15:47 +0000 Subject: [PATCH 5/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 29 +++++++++++---------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 857fd2f731..60c9516921 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -74,26 +74,27 @@ jobs: - name: Retrieve Sunset APIs id: retrieve-sunset-apis env: - openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/dev/openapi/v2/versions.json" + openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/v2.json" run: | - three_weeks_date="" + three_months_date="" + # Determine if the system is macOS or Linux if [[ "$(uname)" == "Darwin" ]]; then - # macOS date command format - three_weeks_date=$(date -v+3w +"%Y-%m-%d") + # macOS date command format + three_months_date=$(date -v+3m +"%Y-%m-%d") else - # Linux date command format - three_weeks_date=$(date --date="3 weeks" +"%Y-%m-%d") + # Linux date command format + three_months_date=$(date --date="3 months" +"%Y-%m-%d") fi - echo "three_weeks_date: ${three_weeks_date}" + 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_weeks_date}") - if [[ "$(sunset_apis)" != "null" ]]; then - echo "API Versions that will be sunsets in the next 3 weeks: ${sunset_apis}" + 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 @@ -104,7 +105,7 @@ jobs: echo "${sunset_apis}" > sunset_apis.json else - echo "No API Versions will be sunset within the next 3 weeks." + 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 @@ -113,10 +114,10 @@ jobs: 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. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}" + 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=$(cat sunset_apis.json | sed 's/"/\\"/g') - JIRA_TICKET_DESCRIPTION="The following APIs will be sunset in the next 3 weeks. Please follow our [wiki|https://wiki.corp.mongodb.com/display/MMS/API+eXperience+Production+Checklist#APIeXperienceProductionChecklist-APISunsetActionItems]. {code:json}${sunset_apis}{code}" + 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]. {code:json}${sunset_apis}{code}" export JIRA_TICKET_DESCRIPTION .github/scripts/create_jira_ticket.sh @@ -131,5 +132,5 @@ jobs: 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 weeks. See Jira Ticket: https://jira.mongodb.org/browse/'"${JIRA_TICKET_ID}"'","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + --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}"] From a313b2b46f32e597bc432d5e19495c829f7fe0c1 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 18:17:45 +0000 Subject: [PATCH 6/7] Update create_jira_ticket.sh --- .github/scripts/create_jira_ticket.sh | 60 +++++++++++++++++---------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/.github/scripts/create_jira_ticket.sh b/.github/scripts/create_jira_ticket.sh index 08e4e6944f..1ea87e21bd 100755 --- a/.github/scripts/create_jira_ticket.sh +++ b/.github/scripts/create_jira_ticket.sh @@ -19,7 +19,7 @@ url_encode() { } encoded_jira_ticket_title=$(url_encode "${JIRA_TICKET_TITLE:?}") -echo "${encoded_jira_ticket_title}" +echo "encoded_jira_ticket_title: ${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:?}"'"' \ @@ -27,41 +27,57 @@ found_issue=$(curl --request GET \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' | jq .total) +echo "found_issue: ${found_issue}" 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 +echo "Creating Jira ticket...." +echo "JIRA_TICKET_TITLE: ${JIRA_TICKET_TITLE}" +echo "JIRA_TICKET_DESCRIPTION: ${JIRA_TICKET_DESCRIPTION}" + json_response=$(curl --request POST \ --url 'https://jira.mongodb.org/rest/api/2/issue' \ --header 'Authorization: Bearer '"${JIRA_API_TOKEN:?}" \ --header 'Accept: application/json' \ --header 'Content-Type: application/json' \ ---data '{ - "fields": { - "project": { - "id": "10984" - }, - "summary": "'"${JIRA_TICKET_TITLE:?}"'", - "issuetype": { - "id": "12" - }, - "customfield_12751": [{ - "id": "22223" - }], - "description": "'"${JIRA_TICKET_DESCRIPTION:?}"'", - "components": [ - { - "id": "35986" - } - ] - } -}') +--data @- <> "${GITHUB_OUTPUT}" +if [ "${JIRA_TICKET_ID}" != "null" ]; then + echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}" + exit 0 +fi + +exit 1 + From f62ef40fe3805487593fe7342dac501fd808ea97 Mon Sep 17 00:00:00 2001 From: andreaangiolillo Date: Wed, 8 Jan 2025 18:35:35 +0000 Subject: [PATCH 7/7] Update api-versions-reminder.yml --- .github/workflows/api-versions-reminder.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/api-versions-reminder.yml b/.github/workflows/api-versions-reminder.yml index 60c9516921..9483783e4b 100644 --- a/.github/workflows/api-versions-reminder.yml +++ b/.github/workflows/api-versions-reminder.yml @@ -116,8 +116,8 @@ jobs: 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=$(cat sunset_apis.json | sed 's/"/\\"/g') - 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]. {code:json}${sunset_apis}{code}" + 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