From e773fb65a8a659da4687e340186e70fec0c6d413 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 25 May 2021 11:21:41 +0200 Subject: [PATCH] CI: migrate push notification to helper script --- .github/workflows/push.yml | 17 +++++++++-------- ci/notify.sh | 15 ++++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b73fb5b22..b5583c1d3 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -30,13 +30,12 @@ jobs: - name: "prepare env" run: | sudo apt-get update - sudo apt-get -y install git-core + sudo apt-get -y install git-core jq sudo apt-get -y install \ build-essential \ cmake \ extra-cmake-modules \ gettext \ - jq \ kio-dev \ libatasmart-dev \ libboost-python-dev \ @@ -80,17 +79,19 @@ jobs: run: make install VERBOSE=1 - name: "notify: ok" if: ${{ success() && github.repository == 'calamares/calamares' }} + env: + MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }} + MATRIX_ROOM: ${{ secrets.MATRIX_ROOM }} run: | - curl -s -XPOST -d '{"msgtype":"m.text", "body":"OK ${{ github.workflow }} in ${{ github.repository }} ${{ github.actor }} on ${{ github.event.ref }}\n.. ${{ steps.pre_build.outputs.message }}"}' 'https://matrix.org/_matrix/client/r0/rooms/%21${{ secrets.MATRIX_ROOM }}/send/m.room.message?access_token=${{ secrets.MATRIX_TOKEN }}' > /dev/null + "$SRCDIR/ci/notify.sh" OK '${{ github.workflow }}' '${{ github.repository }}' '${{ github.actor }}' '${{ github.event.ref }}' \ + '${{ steps.pre_build.outputs.message }}' \ + '' - name: "notify: fail" if: ${{ failure() && github.repository == 'calamares/calamares' }} - run: | - curl -s -XPOST -d '{"msgtype":"m.text", "body": "FAIL ${{ github.workflow }} in ${{ github.repository }} ${{ github.actor }} on ${{ github.event.ref }}\n.. ${{ steps.pre_build.outputs.message }}\n.. DIFF ${{ github.event.compare }}" }' 'https://matrix.org/_matrix/client/r0/rooms/%21${{ secrets.MATRIX_ROOM }}/send/m.room.message?access_token=${{ secrets.MATRIX_TOKEN }}' > /dev/null - - name: "notify: check" env: MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }} MATRIX_ROOM: ${{ secrets.MATRIX_ROOM }} run: | - "$SRCDIR/ci/notify.sh" OK '${{ github.workflow }}' '${{ github.repository }}' '${{ github.actor }}' '${{ github.event.ref }}' \ - '(test)${{ steps.pre_build.outputs.message }}' \ + "$SRCDIR/ci/notify.sh" FAIL '${{ github.workflow }}' '${{ github.repository }}' '${{ github.actor }}' '${{ github.event.ref }}' \ + '${{ steps.pre_build.outputs.message }}' \ '${{ github.event.compare }}' diff --git a/ci/notify.sh b/ci/notify.sh index a51d48cd3..d9a2a4f4b 100755 --- a/ci/notify.sh +++ b/ci/notify.sh @@ -42,14 +42,11 @@ test -z "$EVENT" && { echo "! No event data" ; exit 1 ; } # It's ok for summary or the compare URL to be empty url="https://matrix.org/_matrix/client/r0/rooms/%21${MATRIX_ROOM}/send/m.room.message?access_token=${MATRIX_TOKEN}" - -status_line="${STATUS} ${WORKFLOW} in ${REPOSITORY} ${ACTOR} on ${EVENT}" -summary_line="" -compare_line="" - -test -n "$SUMMARY" && summary_line="\n.. ${SUMMARY}" -test -n "$COMPARE" && compare_line="\n.. DIFF ${COMPARE}" - -message_data=$(jq -Rs --arg body "${status_line}${summary_line}${compare_line}" '{"msgtype": "m.text", $body}' < /dev/null) +message_data=$( +{ + echo "${STATUS} ${WORKFLOW} in ${REPOSITORY} ${ACTOR} on ${EVENT}" + test -n "$SUMMARY" && echo ".. ${SUMMARY}" + test -n "$COMPARE" && echo ".. DIFF ${COMPARE}" +} | jq -Rs '{"msgtype": "m.text", "body":@text}' ) curl -s -XPOST -d "$message_data" "$url" > /dev/null