Skip to content

Commit

Permalink
Check for notification script to element
Browse files Browse the repository at this point in the history
  • Loading branch information
SagarGi committed Nov 29, 2023
1 parent 8566683 commit 2892809
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 19 deletions.
43 changes: 43 additions & 0 deletions .github/scripts/notify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# helper functions
log_error() {
echo -e "\e[31m$1\e[0m"
}

log_info() {
echo -e "\e[37m$1\e[0m"
}

log_success() {
echo -e "\e[32m$1\e[0m"
}

sudo apt-get install jq -y
response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$RUN_ID/jobs")


if [[ "$response" != *"jobs"* ]]; then
log_error "No jobs found in the below response!"
log_info "$response"
exit 1
fi

jobs_informations=$(echo "$response" | jq '.jobs[:-1]')
jobs_conclusions=$(echo "$jobs_informations" | jq -r '.[].conclusion')

workflow_status="Success"
if [[ " ${jobs_conclusions[*]} " == *"failure"* ]]; then
workflow_status="Failure"
fi

send_message_to_room_response=$(curl -XPOST -d '{"msgtype": "m.text","body": "", "format": "org.matrix.custom.html","formatted_body": "<a href='https://github.com/nextcloud/integration_openproject/actions/runs/$RUN_ID'>NC-Nightly-'$BRANCH_NAME'</a><br></br><b><i>Status: '$workflow_status'</i></b>"}' "https://matrix.openproject.org/_matrix/client/r0/rooms/%21$E_ROOM_ID/send/m.room.message?access_token=$U_TOKEN")

if [[ "$send_message_to_room_response" != *"event_id"* ]]; then
log_error "Failed to send message to element. Below response did not contain event_id!"
log_info "$send_message_to_room_response"
exit 1
fi

log_success "Notification of the nightly build has been sent to Element chat (OpenProject + Nextcloud)"
24 changes: 24 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Filter Issues CI/CD from try_cron branch

on:
push:
branches: try_cron
pull_request:
branches: try_cron
# schedule:
# - cron: "*/6 * * * *"

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Chekout code
uses: actions/checkout@v3

- name: Install node required
uses: actions/setup-node@v3
with:
node-version: 16.x

- name: Install dependencies
run: npm ci
10 changes: 3 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ on:
pull_request:
branches:
- main
schedule:
- cron: "*/6 * * * *"
workflow_run:
workflows:
- "Name of Your Workflow"
types:
- completed
# schedule:
# - cron: "*/6 * * * *"

jobs:
main:
uses: ./.github/workflows/shared_steps.yml
secrets: inherit
with:
branch: main
19 changes: 10 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: Release Workflow
# name: Release Workflow

on:
schedule:
- cron: "*/60 * * * *"
# on:
# schedule:
# - cron: "*/6 * * * *"

jobs:
try_cron:
uses: ./.github/workflows/shared_steps.yml
with:
branch: try_cron
# jobs:
# try_cron:
# uses: ./.github/workflows/shared_steps.yml
# secrets: inherit
# with:
# branch: try_cron
18 changes: 15 additions & 3 deletions .github/workflows/shared_steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,21 @@ jobs:
needs:
- unit-test
- api-test
if: always()
if: ${{ always() && github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
ref: main

- name: Step 2
run: |
echo "workflow run ID: ${{ github.run_id }}"
env:
E_ROOM_ID: ${{ secrets.E_ROOM_ID }}
U_TOKEN: ${{ secrets.U_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: SagarGi
REPO_NAME: ceck-expect-failure
RUN_ID: ${{ github.run_id }}
BRANCH_NAME: ${{ inputs.branch }}
run: ./.github/scripts/notify.sh

0 comments on commit 2892809

Please sign in to comment.