Skip to content

Commit

Permalink
#27490: Slack notification for broken build
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms committed Apr 9, 2024
1 parent c4932c7 commit 33f1c08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
22 changes: 18 additions & 4 deletions .github/workflows/build-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CICD Reports
run-name: Reports - ${{ github.event.workflow_run.name }}
on:
workflow_run:
workflows: ['Maven CICD Pipeline']
workflows: ['Maven CICD Pipeline']
types: [completed]

permissions:
Expand All @@ -17,6 +17,7 @@ jobs:
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Download Workflow Data
id: data-download
uses: dawidd6/action-download-artifact@v2
Expand Down Expand Up @@ -45,6 +46,7 @@ jobs:
then
echo "::warn title=Artifact 'workflow-data' missing::Expected artifact 'workflow-data' does not exist for pull_request event."
else
jq . workflow-data.json
json=$(jq -c '.' workflow-data.json)
trigger_event_name=$(echo $json | jq -r '.trigger_event_name // "null"')
status=$(echo $json | jq -r '.aggregate_status // "null"')
Expand All @@ -65,6 +67,7 @@ jobs:
branch_url="https://github.com/$source_repository/tree/$branch"
commit_id_url="https://github.com/$source_repository/pull/$pr_number/commits/$head_sha"
test_results_url="https://github.com/$source_repository/pull/${pr_number}/checks"
if [[ -z "${{ steps.test-reporter.outputs.conclusion }}" ]]; then
test_conclusion="Not Run"
test_passed=0
Expand All @@ -79,7 +82,6 @@ jobs:
test_elapsed=${{ steps.test-reporter.outputs.time }}
fi
if [[ "$status" == "SUCCESS" ]]; then
echo "status_icon=✅" >> $GITHUB_OUTPUT
else
Expand All @@ -95,7 +97,6 @@ jobs:
else
echo "report_type=$trigger_event_name" >> $GITHUB_OUTPUT
fi
echo "json=$json" >> $GITHUB_OUTPUT
echo "trigger_event_name=$trigger_event_name" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -123,8 +124,20 @@ jobs:
echo "test_failed=$test_failed" >> $GITHUB_OUTPUT
echo "test_skipped=$test_skipped" >> $GITHUB_OUTPUT
echo "test_elapsed=$test_elapsed" >> $GITHUB_OUTPUT
fi
- name: Slack Notification
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_WEBHOOK: ${{ secrets.MASTER_BUILD_SLACK_WEBHOOK }}
SLACK_USERNAME: dotBot
SLACK_TITLE: "Broken build!"
SLACK_MSG_AUTHOR: " "
MSG_MINIMAL: true
SLACK_FOOTER: ""
SLACK_ICON: https://slackmojis.com/emojis/5432-this-is-fine/download
SLACK_MESSAGE: "Attention <!channel>! Broken build at `${{ github.ref_name }}`.\nPlease check the run at: ${{ steps.workflow-data.outputs.action_run_url }}"
if: steps.workflow-data.outputs.status != 'SUCCESS'

- name: Prepare Slack Message Payload
id: prepare-slack-message
Expand Down Expand Up @@ -206,6 +219,7 @@ jobs:
)
echo "payload=$(echo $payload | jq -c .)" >> $GITHUB_OUTPUT
echo "payload=$payload"
- name: Post to Slack
if: steps.workflow-data.outputs.has-json == 'true' && github.repository == 'dotcms/core'
uses: slackapi/slack-github-action@v1.24.0
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/maven-cicd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
backend=${{ steps.filter.outputs.backend }}
build=${{ steps.filter.outputs.build }}
jvm_unit_test=${{ steps.filter.outputs.jvm_unit_test }}
# Check if the commit is to the master branch
is_master=$(echo ${{ github.ref }} | sed -n 's/refs\/heads\/master/&/p')
skip_tests=${CICD_SKIP_TESTS:-false} # Use environment variable, default to 'false'
Expand All @@ -76,6 +76,7 @@ jobs:
backend=true
jvm_unit_test=true
fi
# The below line ensures that if skip_tests is true, all tests are set to false.
if [ "$skip_tests" == "true" ]; then
echo "Skipping tests as per CICD_SKIP_TESTS flag."
Expand Down Expand Up @@ -174,12 +175,20 @@ jobs:
path: ${{ env.DOCKER_BUILD_CONTEXT }}/docker-build.tar
- name: Save Docker image to a tar file
run: docker save ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} > image.tar

- name: Upload Docker image as artifact
uses: actions/upload-artifact@v4
with:
name: docker-image
path: image.tar
- name: Core Build Report
uses: actions/upload-artifact@v4
if: always() && !cancelled()
with:
name: "build-reports-Initial JDK 11 Build"
path: |
target/build-reports.json
LICENSE
retention-days: 2

#
# Run all JVM Unit Tests in parallel with other tests
Expand Down Expand Up @@ -695,7 +704,6 @@ jobs:
echo '"pr_author": "'${{ github.event.pull_request.user.login }}'",' >> workflow-data.json
echo '"pr_merge_state": "'${{ github.event.pull_request.mergeable_state }}'",' >> workflow-data.json
echo '"build_reports": [' >> workflow-data.json
total_reports=$(find /tmp/build-step-reports/build-reports-*/target -name build-report.json 2>/dev/null | wc -l)
Expand Down

0 comments on commit 33f1c08

Please sign in to comment.