Skip to content

Send a Slack Notification for APIs important events #107

Send a Slack Notification for APIs important events

Send a Slack Notification for APIs important events #107

name: 'Send a Slack Notification for APIs important events'
on:
workflow_dispatch: # Allow manual triggering
schedule:
- cron: '0 9 * * 1' # at 9:00 UTC on Monday
jobs:
sunset-api-version-3months-reminder:
name: Sunset APIs Reminder
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- name: Install Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
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/.raw/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
./.github/scripts/get_sunset_apis.sh "${openapi_spec_url}" "${three_months_date}"
# 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_TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_PLATFORM}}
JIRA_TICKET_TITLE: "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 }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
SLACK_APIX_PLATFORM_ONCALL_USER: ${{secrets.SLACK_APIX_PLATFORM_ONCALL_USER}}
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 ('"${SLACK_APIX_PLATFORM_ONCALL_USER}"'). 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}"
sunset-api-version-1month-reminder:
name: Sunset APIs Reminder
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- name: Install Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
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/.raw/v2.json"
run: |
one_month_date=""
# Determine if the system is macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
# macOS date command format
one_month_date=$(date -v+1m +"%Y-%m-%d")
else
# Linux date command format
one_month_date=$(date --date="1 months" +"%Y-%m-%d")
fi
./.github/scripts/get_sunset_apis.sh "${openapi_spec_url}" "${one_month_date}"
# 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_TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_PLATFORM}}
JIRA_TICKET_TITLE: "Some APIs are approaching their sunset date in the next month. 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 month. 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 }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
SLACK_APIX_PLATFORM_ONCALL_USER: ${{secrets.SLACK_APIX_PLATFORM_ONCALL_USER}}
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 month ('"${SLACK_APIX_PLATFORM_ONCALL_USER}"'). 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}"
sunset-api-version-1week-reminder:
name: Sunset APIs Reminder
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
- name: Install Python
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
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/.raw/v2.json"
run: |
one_week_date=""
# Determine if the system is macOS or Linux
if [[ "$(uname)" == "Darwin" ]]; then
# macOS date command format
one_week_date=$(date -v+1w +"%Y-%m-%d")
else
# Linux date command format
one_week_date=$(date --date="+1 week" +"%Y-%m-%d")
fi
./.github/scripts/get_sunset_apis.sh "${openapi_spec_url}" "${one_week_date}"
# 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_TEAM_ID: ${{ vars.JIRA_TEAM_ID_APIX_PLATFORM}}
JIRA_TICKET_TITLE: "Some APIs are approaching their sunset date in the next week. 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 week. 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 }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
SLACK_APIX_PLATFORM_ONCALL_USER: ${{secrets.SLACK_APIX_PLATFORM_ONCALL_USER}}
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 week ('"${SLACK_APIX_PLATFORM_ONCALL_USER}"'). 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}"