ci: add new release version alert #23
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Version Alert | |
on: | |
pull_request: | |
branches: [main] | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Get PR information | |
id: pr-info | |
run: | | |
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") | |
PR_HASH=$(git rev-parse HEAD) | |
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
echo "PR_HASH=$PR_HASH" >> $GITHUB_ENV | |
- name: Check versions | |
id: check-versions | |
run: | | |
CHECK_NEW_VERSION_RESPONSE=$(bash scripts/check-new-release-version.sh) | |
if [[ "$CHECK_NEW_VERSION_RESPONSE" == "New release version"* ]]; then | |
echo "Sending Slack notification..." | |
MESSAGE="$CHECK_NEW_VERSION_RESPONSE :rocket: Coming soon in PR: https://github.com/$GITHUB_REPOSITORY/pull/$PR_NUMBER " | |
echo "SLACK_MESSAGE=$MESSAGE" >> $GITHUB_ENV | |
else | |
echo "No new non-dev version found. Skipping Slack notification." | |
fi | |
- name: Generate Message Hash | |
id: generate-hash | |
run: | | |
MESSAGE_HASH=$(echo "${env.SLACK_MESSAGE}" | sha256sum | cut -d ' ' -f1) | |
echo "MESSAGE_HASH=$MESSAGE_HASH" >> $GITHUB_ENV | |
- name: Retrieve Messages from Cache | |
id: retrieve-cache | |
uses: actions/cache@v2 | |
with: | |
path: $HOME/messages_cache.txt | |
key: messages-cache-${{ runner.os }}-${{ env.MESSAGE_HASH }} | |
restore-keys: | | |
messages-cache-${{ runner.os }}-${{ env.MESSAGE_HASH }} | |
- name: Check for Duplicates | |
run: | | |
DUPLICATE_CHECK=$(grep -Fx "${env.SLACK_MESSAGE}" $HOME/messages_cache.txt || true) | |
if [ -n "$DUPLICATE_CHECK" ]; then | |
echo "Message already posted. Skipping duplicate Slack notification." | |
exit 0 # Exit without posting a message | |
fi | |
- name: Write Message to Cache File | |
run: | | |
echo "${env.SLACK_MESSAGE}" >> $HOME/messages_cache.txt | |
- name: Store Messages in Cache | |
uses: actions/cache@v2 | |
with: | |
path: $HOME/messages_cache.txt | |
key: messages-cache-${{ runner.os }}-${{ env.MESSAGE_HASH }} | |
- name: Slack Notification | |
if: env.SLACK_MESSAGE != '' | |
uses: slackapi/[email protected] | |
with: | |
channel-id: 'C05RVKRFCCF' | |
slack-message: ${{ env.SLACK_MESSAGE }} | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} |