Skip to content

Commit

Permalink
fix slack job
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Hlushchenko committed Apr 8, 2024
1 parent 9bdb149 commit edb4ff1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
74 changes: 37 additions & 37 deletions .github/workflows/slack_notification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,45 @@ on:
required: true

jobs:
Slack_notification:
slack_notification:
runs-on: ubuntu-latest
steps: slack_notification
- name: Prepare Slack Message
if: ${{ steps.publish.outcome == 'success' && !contains(matrix.package, 'Meta') }}
id: slack-prepare
shell: bash
env:
SLACK_ID: ${{ inputs.slack_id }}
run: |
channel_id=$(echo "$SLACK_ID" | jq -r .\"${{ github.actor }}\")
echo "::add-mask::$channel_id"
echo SLACK_CHANNEL=$channel_id >> $GITHUB_ENV
payload='{"blocks":[]}'
if [[ ${{ inputs.slack_header }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "section","text": {"type": "mrkdwn","text": "${{ inputs.slack_header }}"}}]')
fi
if [[ ${{ inputs.slack_message_body }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "section","text": {"type": "mrkdwn","text": "${{ inputs.slack_message_body }}"}}]')
fi
if [[ ${{ inputs.slack_context }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "context","elements":[{"type": "mrkdwn", "text": "${{ inputs.slack_message_body }}"}]}]')
fi
echo SLACK_PAYLOAD=$payload >> $GITHUB_ENV
- name: Prepare Slack Message
if: ${{ steps.publish.outcome == 'success' && !contains(matrix.package, 'Meta') }}
id: slack-prepare
shell: bash
env:
SLACK_ID: ${{ inputs.slack_id }}
run: |
channel_id=$(echo "$SLACK_ID" | jq -r .\"${{ github.actor }}\")
echo "::add-mask::$channel_id"
echo SLACK_CHANNEL=$channel_id >> $GITHUB_ENV
payload='{"blocks":[]}'
if [[ ${{ inputs.slack_header }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "section","text": {"type": "mrkdwn","text": "${{ inputs.slack_header }}"}}]')
fi
if [[ ${{ inputs.slack_message_body }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "section","text": {"type": "mrkdwn","text": "${{ inputs.slack_message_body }}"}}]')
fi
if [[ ${{ inputs.slack_context }} != '']];then
payload=$(echo "$payload" | jq '.blocks += [{"type": "context","elements":[{"type": "mrkdwn", "text": "${{ inputs.slack_message_body }}"}]}]')
fi
echo SLACK_PAYLOAD=$payload >> $GITHUB_ENV
header="Package *${{ matrix.package }}* version *${{ matrix.version }}* published to <https://www.npmjs.com/package/$(jq -r .name "packages/${{ matrix.package }}/package.json")/v/${{ matrix.version }}|NPM>"
echo SLACK_MESSAGE_HEADER=${{ inputs.slack_header }} >> $GITHUB_ENV
header="Package *${{ matrix.package }}* version *${{ matrix.version }}* published to <https://www.npmjs.com/package/$(jq -r .name "packages/${{ matrix.package }}/package.json")/v/${{ matrix.version }}|NPM>"
echo SLACK_MESSAGE_HEADER=${{ inputs.slack_header }} >> $GITHUB_ENV
context="*GitHub Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }} ${{ github.run_number }}>\n*Commit:* <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|$(echo "${{ github.sha }}" | cut -c1-8) $(echo -e "${{ github.event.head_commit.message }}" | head -n1 | sed -e 's/"/\\"/g')>"
echo SLACK_MESSAGE_CONTEXT=${{ inputs.slack_context }} >> $GITHUB_ENV
context="*GitHub Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }} ${{ github.run_number }}>\n*Commit:* <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|$(echo "${{ github.sha }}" | cut -c1-8) $(echo -e "${{ github.event.head_commit.message }}" | head -n1 | sed -e 's/"/\\"/g')>"
echo SLACK_MESSAGE_CONTEXT=${{ inputs.slack_context }} >> $GITHUB_ENV
- name: Send to Slack
id: slack
if: steps.slack-prepare.outcome == 'success'
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_CHANNEL }}
payload: ${{ env.SLACK_PAYLOAD }}
env:
SLACK_BOT_TOKEN: ${{ inputs.slack_token }}
- name: Send to Slack
id: slack
if: steps.slack-prepare.outcome == 'success'
uses: slackapi/[email protected]
with:
channel-id: ${{ env.SLACK_CHANNEL }}
payload: ${{ env.SLACK_PAYLOAD }}
env:
SLACK_BOT_TOKEN: ${{ inputs.slack_token }}
2 changes: 1 addition & 1 deletion .github/workflows/slack_notification_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:


jobs:
Slack_notification_test:
slack_notification_test:
runs-on: ubuntu-latest
name: slack_notification
steps:
Expand Down

0 comments on commit edb4ff1

Please sign in to comment.