Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/scripts/upcoming_api_releases.sh
Original file line number Diff line number Diff line change
@@ -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}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering what will be our plan long-term with .sh logic in our platform since in the past it has proven itself difficult to maintain, perharps we can add unit tests here like it was explored with the postman project? OK to make it in a follow-up PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will create a ticket to investigate how much time we might need to migrate these scripts to golang


# 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
30 changes: 30 additions & 0 deletions .github/workflows/api-versions-reminder.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

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
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')
echo "message_id=${message_id}"
Loading