Skip to content

Commit

Permalink
Notify build results on workflow run
Browse files Browse the repository at this point in the history
  • Loading branch information
jun66j5 committed Feb 12, 2023
1 parent 6cc201f commit 2245c31
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
69 changes: 69 additions & 0 deletions .github/workflows/build-completed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
name: build-completed

on:
workflow_run:
workflows: ['build']
types: ['completed']
# branches: ['trunk', '*.*-stable']
# tags: ['trac-*']

jobs:
build-completed:
# if: ${{ github.event_name == 'push' && github.repository == 'edgewall/trac' }}

runs-on: ubuntu-22.04

steps:
- name: Send summary of the workflow run
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
RUN_NAME: ${{ github.event.workflow_run.name }}
RUN_URL: ${{ github.event.workflow_run.html_url }}
RUN_SHA: ${{ github.event.workflow_run.head_sha }}
RUN_BRANCH: ${{ github.event.workflow_run.head_branch }}
RUN_CONCLUSION: ${{ github.event.workflow_run.conclusion }}
RUN_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
RUN_NUMBER: ${{ github.event.workflow_run.run_number }}
RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }}
RUN_UPDATED_AT: ${{ github.event.workflow_run.updated_at }}
SMTP_URL: ${{ secrets.SMTP_URL }}
SMTP_USER: ${{ secrets.SMTP_USER }}
SMTP_MAIL_FROM: ${{ secrets.SMTP_MAIL_FROM }}
SMTP_MAIL_RCPT: ${{ secrets.SMTP_MAIL_RCPT }}
if: ${{ env.SMTP_URL != null }}
run: |
set -ex
rev="$(echo -n "$RUN_MESSAGE" | sed -n '/^git-svn-id:/ { s/.*@\([0-9]*\) .*/r\1/; p; q }')"
[ -z "$rev" ] && rev="$(expr substr "$RUN_SHA" 1 9)"
repos="$GITHUB_REPOSITORY"
label="$RUN_NAME #$RUN_NUMBER"
if [ "$RUN_ATTEMPT" -ne 1 ]; then
label="$label, attempt #$RUN_ATTEMPT"
fi
msgid="github.com/$repos/run/$RUN_ID/$RUN_ATTEMPT@${SMTP_MAIL_FROM#*@}"
date="$(TZ=UTC date -R -d "$RUN_UPDATED_AT")"
tmpfile="$(mktemp)"
{
echo "From: <$SMTP_MAIL_FROM>"
echo "To: <$SMTP_MAIL_RCPT>"
echo "Date: $date"
echo "Message-ID: <$msgid>"
echo "Content-Type: text/plain; charset=utf-8"
echo "Content-Transfer-Encoding: 8bit"
echo "Subject: [$repos] Run $RUN_CONCLUSION: $label - $RUN_BRANCH ($rev)"
echo
echo "View this run on GitHub: $RUN_URL"
gh run view "$RUN_ID" --repo "$repos"
} >"$tmpfile"
case "$SMTP_URL" in
smtps:*) ssl_reqd=--ssl-reqd ;;
*) ssl_reqd= ;;
esac
curl --url "$SMTP_URL" $ssl_reqd --user "$SMTP_USER" \
--mail-from "$SMTP_MAIL_FROM" --mail-rcpt "$SMTP_MAIL_RCPT" \
--upload-file "$tmpfile"
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ concurrency:
jobs:

posix-test-minimum:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 30
Expand Down Expand Up @@ -64,6 +65,7 @@ jobs:


posix-test:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 50
Expand Down Expand Up @@ -138,6 +140,7 @@ jobs:


posix-prepare:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 50
Expand Down Expand Up @@ -198,6 +201,7 @@ jobs:


windows-test-minimum:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 30
Expand Down Expand Up @@ -252,6 +256,7 @@ jobs:


windows-test:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 80
Expand Down Expand Up @@ -321,6 +326,7 @@ jobs:


windows-prepare:
if: ${{ false }}
runs-on: ${{ matrix.os }}

timeout-minutes: 50
Expand Down Expand Up @@ -415,7 +421,7 @@ jobs:
os: [ubuntu-22.04]
python-version: ['3.11']

needs: [posix-test-minimum, posix-test, windows-test-minimum, windows-test]
# needs: [posix-test-minimum, posix-test, windows-test-minimum, windows-test]

env:
PIP_NO_PYTHON_VERSION_WARNING: '1'
Expand Down

0 comments on commit 2245c31

Please sign in to comment.