|
1 | | -name: 'Send a Slack Notification for upcoming release of API versions' |
| 1 | +name: 'Send a Slack Notification for APIs important events' |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | workflow_dispatch: # Allow manual triggering |
5 | 5 | schedule: |
6 | 6 | - cron: '0 9 * * 1-5' # Run once a day at 09:00 UTC between Monday and Friday |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - send-api-version-reminder: |
| 9 | + new-api-version-reminder: |
| 10 | + name: New API Version Release Reminder |
10 | 11 | runs-on: ubuntu-latest |
11 | 12 | steps: |
12 | 13 | - name: Checkout repository (dev branch) |
|
47 | 48 | -H 'Content-type: application/json' \ |
48 | 49 | --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') |
49 | 50 | echo "message_id=${message_id}" |
| 51 | +
|
| 52 | + sunset-api-version-reminder: |
| 53 | + name: Sunset APIs Reminder |
| 54 | + runs-on: ubuntu-latest |
| 55 | + steps: |
| 56 | + - name: Checkout repository |
| 57 | + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 |
| 58 | + |
| 59 | + - name: Install Python |
| 60 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b |
| 61 | + with: |
| 62 | + python-version: '3.12' |
| 63 | + |
| 64 | + - name: Install FOASCLI |
| 65 | + env: |
| 66 | + foascli_version: ${{ vars.FOASCLI_VERSION }} |
| 67 | + run: | |
| 68 | + 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 |
| 69 | + tar -xzvf foascli.tar.gz |
| 70 | + pushd mongodb-foas-cli_* |
| 71 | + echo "$(pwd)/bin" >> "${GITHUB_PATH}" |
| 72 | + popd |
| 73 | +
|
| 74 | + - name: Retrieve Sunset APIs |
| 75 | + id: retrieve-sunset-apis |
| 76 | + env: |
| 77 | + openapi_spec_url: "https://raw.githubusercontent.com/mongodb/openapi/refs/heads/dev/openapi/v2.json" |
| 78 | + run: | |
| 79 | + three_months_date="" |
| 80 | + |
| 81 | + # Determine if the system is macOS or Linux |
| 82 | + if [[ "$(uname)" == "Darwin" ]]; then |
| 83 | + # macOS date command format |
| 84 | + three_months_date=$(date -v+3m +"%Y-%m-%d") |
| 85 | + else |
| 86 | + # Linux date command format |
| 87 | + three_months_date=$(date --date="3 months" +"%Y-%m-%d") |
| 88 | + fi |
| 89 | + |
| 90 | + echo "three_months_date: ${three_months_date}" |
| 91 | + |
| 92 | + current_date=$(date +"%Y-%m-%d") |
| 93 | + echo "current_date: ${current_date}" |
| 94 | + |
| 95 | + sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_months_date}") |
| 96 | + if [[ "${sunset_apis}" != "null" ]]; then |
| 97 | + echo "API Versions that will be sunsets in the next 3 months: ${sunset_apis}" |
| 98 | + |
| 99 | + # We calculate the md5sum of the JSON object which will be included in the Jira ticket title. |
| 100 | + # This approach ensures we create a new jira ticket only if the there is not already a ticket |
| 101 | + # with the same title |
| 102 | + hash_code_sunset_apis=$(echo "$sunset_apis" | jq -cS . | md5sum | awk '{print $1}') |
| 103 | + echo "hash: ${hash_code_sunset_apis}" |
| 104 | + echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}" |
| 105 | + echo "${sunset_apis}" > sunset_apis.json |
| 106 | + |
| 107 | + else |
| 108 | + echo "No API Versions will be sunset within the next 3 months." |
| 109 | + fi |
| 110 | +
|
| 111 | + # Create a JIRA ticket only if the there is not already a ticket with the same title |
| 112 | + - name: Create JIRA Ticket |
| 113 | + id: create-jira-ticket |
| 114 | + if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null |
| 115 | + env: |
| 116 | + JIRA_API_TOKEN: ${{ secrets.jira_api_token }} |
| 117 | + 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}}" |
| 118 | + run: | |
| 119 | + sunset_apis=$(sed 's/"/\\"/g' sunset_apis.json) |
| 120 | + 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}" |
| 121 | + export JIRA_TICKET_DESCRIPTION |
| 122 | + .github/scripts/create_jira_ticket.sh |
| 123 | +
|
| 124 | + # Send Slack notification only if the Jira ticket was created |
| 125 | + - name: Send Slack Notification |
| 126 | + if: steps.create-jira-ticket.outputs.jira-ticket-id != null |
| 127 | + env: |
| 128 | + SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }} |
| 129 | + SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }} |
| 130 | + JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }} |
| 131 | + run: | |
| 132 | + echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}" |
| 133 | + message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ |
| 134 | + -H 'Content-type: application/json' \ |
| 135 | + --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') |
| 136 | + echo "message_id=${message_id}"] |
0 commit comments