Skip to content

Commit fb07d73

Browse files
Update api-versions-reminder.yml
1 parent 1aede46 commit fb07d73

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

.github/workflows/api-versions-reminder.yml

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ jobs:
5555
steps:
5656
- name: Checkout repository
5757
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
58+
59+
- name: Install Python
60+
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
5861
with:
59-
sparse-checkout:
60-
.github/scripts/upcoming_api_releases.sh
62+
python-version: '3.12'
6163

6264
- name: Install FOASCLI
6365
env:
@@ -84,51 +86,50 @@ jobs:
8486
three_weeks_date=$(date --date="3 weeks" +"%Y-%m-%d")
8587
fi
8688
87-
current_date=$(date +%s)
89+
echo "three_weeks_date: ${three_weeks_date}"
90+
91+
current_date=$(date +"%Y-%m-%d")
92+
echo "current_date: ${current_date}"
93+
8894
sunset_apis=$(foascli sunset ls -s "${openapi_spec_url}" --from "${current_date}" --to "${three_weeks_date}")
8995
if [[ "$(sunset_apis)" != "null" ]]; then
9096
echo "API Versions that will be sunsets in the next 3 weeks: ${sunset_apis}"
91-
97+
9298
# We calculate the md5sum of the JSON object which will be included in the Jira ticket title.
9399
# This approach ensures we create a new jira ticket only if the there is not already a ticket
94100
# with the same title
95101
hash_code_sunset_apis=$(echo "$sunset_apis" | jq -cS . | md5sum | awk '{print $1}')
96102
echo "hash: ${hash_code_sunset_apis}"
97-
98-
echo sunset_apis="${sunset_apis}" >> "${GITHUB_OUTPUT:?}"
99103
echo hash_code_sunset_apis="${hash_code_sunset_apis}" >> "${GITHUB_OUTPUT:?}"
100-
104+
echo "${sunset_apis}" > sunset_apis.json
105+
101106
else
102107
echo "No API Versions will be sunset within the next 3 weeks."
103108
fi
104109
105110
# Create a JIRA ticket only if the there is not already a ticket with the same title
106111
- name: Create JIRA Ticket
107112
id: create-jira-ticket
108-
if: steps.retrieve-sunset-apis.outputs.sunset_apis != null
113+
if: steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis != null
109114
env:
110115
JIRA_API_TOKEN: ${{ secrets.jira_api_token }}
111116
JIRA_TICKET_TITLE: "[API Platform] Some APIs are approaching their sunset date. ID: ${{steps.retrieve-sunset-apis.outputs.hash_code_sunset_apis}}"
112-
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}"
113-
run: .github/scripts/create_jira_ticket.sh
117+
run: |
118+
sunset_apis=$(cat sunset_apis.json | sed 's/"/\\"/g')
119+
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}"
120+
export JIRA_TICKET_DESCRIPTION
121+
.github/scripts/create_jira_ticket.sh
114122
115123
# Send Slack notification only if the Jira ticket was created
116124
- name: Send Slack Notification
117125
if: steps.create-jira-ticket.outputs.jira-ticket-id != null
118126
env:
119127
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID_APIX_2 }}
120128
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
121-
SUNSET_APIS: ${{ steps.retrieve-sunset-apis.outputs.sunset_apis }}
122129
JIRA_TICKET_ID: ${{ steps.create-jira-ticket.outputs.jira-ticket-id }}
123130
run: |
131+
echo "JIRA_TICKET_ID: ${JIRA_TICKET_ID}"
124132
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
125133
-H 'Content-type: application/json' \
126-
--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')
134+
--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')
127135
echo "message_id=${message_id}"]
128-
129-
sleep 2 # wait for 2 seconds to avoid slack rate limit
130-
131-
# Add the JSON array as a reply to message thread
132-
curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
133-
-H 'Content-type: application/json' \
134-
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'",{"thread_ts":"'"${message_id}"'","text":"'"${SUNSET_APIS}"'","parse": "full",}' https://slack.com/api/chat.postMessage

0 commit comments

Comments
 (0)