CI: migrate push notification to helper script

main
Adriaan de Groot 4 years ago
parent a73ad23b9f
commit e773fb65a8

@ -30,13 +30,12 @@ jobs:
- name: "prepare env" - name: "prepare env"
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get -y install git-core sudo apt-get -y install git-core jq
sudo apt-get -y install \ sudo apt-get -y install \
build-essential \ build-essential \
cmake \ cmake \
extra-cmake-modules \ extra-cmake-modules \
gettext \ gettext \
jq \
kio-dev \ kio-dev \
libatasmart-dev \ libatasmart-dev \
libboost-python-dev \ libboost-python-dev \
@ -80,17 +79,19 @@ jobs:
run: make install VERBOSE=1 run: make install VERBOSE=1
- name: "notify: ok" - name: "notify: ok"
if: ${{ success() && github.repository == 'calamares/calamares' }} if: ${{ success() && github.repository == 'calamares/calamares' }}
env:
MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }}
MATRIX_ROOM: ${{ secrets.MATRIX_ROOM }}
run: | 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" - name: "notify: fail"
if: ${{ failure() && github.repository == 'calamares/calamares' }} 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: env:
MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }} MATRIX_TOKEN: ${{ secrets.MATRIX_TOKEN }}
MATRIX_ROOM: ${{ secrets.MATRIX_ROOM }} MATRIX_ROOM: ${{ secrets.MATRIX_ROOM }}
run: | run: |
"$SRCDIR/ci/notify.sh" OK '${{ github.workflow }}' '${{ github.repository }}' '${{ github.actor }}' '${{ github.event.ref }}' \ "$SRCDIR/ci/notify.sh" FAIL '${{ github.workflow }}' '${{ github.repository }}' '${{ github.actor }}' '${{ github.event.ref }}' \
'(test)${{ steps.pre_build.outputs.message }}' \ '${{ steps.pre_build.outputs.message }}' \
'${{ github.event.compare }}' '${{ github.event.compare }}'

@ -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 # 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}" url="https://matrix.org/_matrix/client/r0/rooms/%21${MATRIX_ROOM}/send/m.room.message?access_token=${MATRIX_TOKEN}"
message_data=$(
status_line="${STATUS} ${WORKFLOW} in ${REPOSITORY} ${ACTOR} on ${EVENT}" {
summary_line="" echo "${STATUS} ${WORKFLOW} in ${REPOSITORY} ${ACTOR} on ${EVENT}"
compare_line="" test -n "$SUMMARY" && echo ".. ${SUMMARY}"
test -n "$COMPARE" && echo ".. DIFF ${COMPARE}"
test -n "$SUMMARY" && summary_line="\n.. ${SUMMARY}" } | jq -Rs '{"msgtype": "m.text", "body":@text}' )
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)
curl -s -XPOST -d "$message_data" "$url" > /dev/null curl -s -XPOST -d "$message_data" "$url" > /dev/null

Loading…
Cancel
Save