From 7d8cfaaac4b68864b4bba16af122a221ac7824c1 Mon Sep 17 00:00:00 2001 From: Wojtek Piotrowiak Date: Fri, 6 Oct 2023 19:19:24 +0200 Subject: [PATCH] [AAE-17087] new-notification when build time exceeded (#333) Co-authored-by: Anahide Tchertchian <608958+atchertchian@users.noreply.github.com> Co-authored-by: Giovanni Toraldo <71768+gionn@users.noreply.github.com> --- .../action.yml | 32 +++++++++++++++++++ docs/README.md | 13 ++++++++ version.txt | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .github/actions/send-slack-notification-slow-job/action.yml diff --git a/.github/actions/send-slack-notification-slow-job/action.yml b/.github/actions/send-slack-notification-slow-job/action.yml new file mode 100644 index 000000000..e02c50459 --- /dev/null +++ b/.github/actions/send-slack-notification-slow-job/action.yml @@ -0,0 +1,32 @@ +name: Send a notification for exceeded build time +description: Send a slack notification if build took more than planned + +inputs: + max-build-time-seconds: + description: Maximum acceptable build time in seconds + required: true + slack-token: + description: The slack token + required: true + slack-channel: + description: The slack channel id, channel name, or user id to post to + required: true + +runs: + using: composite + steps: + - name: Fetch billable time from gh API + id: fetch_time + shell: bash + run: | + total_time=$(gh api /repos/${{github.repository}}/actions/runs/${{github.run_id}}/timing | jq ' .billable.UBUNTU.total_ms /1000') + echo "total_time in seconds: ${total_time}" + echo "total_time=${total_time}" >> $GITHUB_OUTPUT + + - name: Slack Notification + if: fromJSON(steps.fetch_time.outputs.total_time) > fromJSON(inputs.max-build-time-seconds) + uses: Alfresco/alfresco-build-tools/.github/actions/send-slack-notification@v3.4.0 + with: + channel-id: ${{ inputs.slack-channel }} + message: 'Max build time exceeded: took ${{ steps.fetch_time.outputs.total_time }} seconds (expected max: ${{ inputs.max-build-time-seconds }} seconds)' + token: ${{ inputs.slack-token }} diff --git a/docs/README.md b/docs/README.md index 3890c238f..e80c7e75d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1040,6 +1040,19 @@ This will give the following sample output on the GH Actions run summary (when u ![GH Actions Summary Report Portal](./images/rp-gh-summary.png) +### send-slack-notification-slow-job + +Sends a slack notification when current run took more time than specified via `max-build-time-seconds` input. +This action should be added at the end to correctly measure the time. + +```yaml + - uses: Alfresco/alfresco-build-tools/.github/actions/send-slack-notification-slow-job@ref + with: + channel-id: 'channel-id' + token: ${{ secrets.SLACK_BOT_TOKEN }} + max-build-time-seconds: '10' +``` + ### send-slack-notification Sends a slack notification with a pre-defined payload, relying on the [slackapi/slack-github-action](https://github.com/slackapi/slack-github-action) official action. diff --git a/version.txt b/version.txt index 3d67a549d..c0c4025db 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -v3.4.1 +v3.5.0