Skip to content

ci: add new release version alert #29

ci: add new release version alert

ci: add new release version alert #29

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: 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}}" messages_cache.txt || true)
if [ -n "$DUPLICATE_CHECK" ]; then
echo "Message already posted. Skipping duplicate Slack notification."
echo "SKIP_STEPS=true" >> $GITHUB_ENV # Set an environment variable to indicate skipping steps
fi
- name: Write Message to Cache File
run: |
if: env.SKIP_STEPS != 'true'
echo "${{env.SLACK_MESSAGE}}" >> messages_cache.txt
cat messages_cache.txt
- name: Store Messages in Cache
if: env.SKIP_STEPS != 'true'
uses: actions/cache/save@v3
with:
path: messages_cache.txt
key: messages-cache-${{ runner.os }}-${{ env.MESSAGE_HASH }}
- name: Slack Notification
if: env.SLACK_MESSAGE != '' && env.SKIP_STEPS != 'true'
uses: slackapi/[email protected]
with:
channel-id: 'C05RVKRFCCF'
slack-message: ${{ env.SLACK_MESSAGE }}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}