Skip to content

Send Changelog Report To Slack Channel #8

Send Changelog Report To Slack Channel

Send Changelog Report To Slack Channel #8

name: 'Send Changelog Report'
on:
workflow_dispatch:
inputs:
start_date:
description: 'Start date for the changelog report. Example: 2024-01-01'
required: true
end_date:
description: 'End date for the changelog report. Example: 2024-01-10'
required: true
jobs:
send-changelog-report:
runs-on: ubuntu-latest
steps:
- name: Checkout repository (dev branch)
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: dev
sparse-checkout:
changelog/
- 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: Get Start and End Dates
id: get-dates
env:
START_DATE: ${{ inputs.start_date }}
END_DATE: ${{ inputs.end_date }}
run: |
start_date="${START_DATE}"
if [[ -z "${START_DATE}" ]]; then
echo "Start date not provided"
start_date=$(date -j -v-7d "+%Y-%m-%d")
echo "Using 7 days ago as start date: ${start_date}"
fi
end_date="${END_DATE}"
if [[ -z "${END_DATE}" ]]; then
echo "End date not provided"
end_date=$(date -j -v-1d "+%Y-%m-%d")
echo "Using yesterday as end date: ${end_date}"
fi
echo start_date="${start_date}" >> "${GITHUB_OUTPUT}"
echo end_date="${end_date}" >> "${GITHUB_OUTPUT}"
- name: Send Initial Slack Message
id: send-initial-slack-message
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
START_DATE: ${{ steps.get-dates.outputs.start_date }}
END_DATE: ${{ steps.get-dates.outputs.end_date }}
run: |
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
-H 'Content-type: application/json' \
--data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":":aileaft: List of API changes (*cloud-dev*) from *'"${START_DATE}"'* to *'"${END_DATE}"'*","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts')
echo "response=${response}"
echo "message_id=${message_id}"
echo "message_id=${message_id}" >> "${GITHUB_OUTPUT}"
sleep 2 # wait for 2 second to avoid slack rate limit
- name: Get Changelog Entries
env:
START_DATE: ${{ steps.get-dates.outputs.start_date }}
END_DATE: ${{ steps.get-dates.outputs.end_date }}
run: |
changelog_entries=$(jq --arg start_date "${START_DATE}" --arg end_date "${END_DATE}" ' map(select(.date >= $start_date and .date <= $end_date))' changelog/internal/changelog-all.json)
echo "${changelog_entries}" > entries.json
- name: Upload entries for debugging
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
with:
name: changelog_entries
path: |
entries.json
- name: Send Changelog Entries as Slack Thread
id: send-changelog-entries
env:
SLACK_CHANNEL_ID: ${{ secrets.SLACK_CHANNEL_ID }}
SLACK_BEARER_TOKEN: ${{ secrets.SLACK_BEARER_TOKEN }}
MESSAGE_ID: ${{ steps.send-initial-slack-message.outputs.message_id }}
run: |
messages=$(foascli changelog convert slack --path entries.json --msg-id "${MESSAGE_ID}" -c "${SLACK_CHANNEL_ID}")
for message in "${messages[@]}"; do
echo "Sending message:"
echo "${message}"
curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
-H 'Content-type: application/json' \
--data "${message}" https://slack.com/api/chat.postMessage
sleep 2 # wait for 2 second to avoid slack rate limit
done