Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 51 additions & 26 deletions .github/scripts/notify-to-element.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# SPDX-FileCopyrightText: 2023-2024 Jankari Tech Pvt. Ltd.
# SPDX-License-Identifier: AGPL-3.0-or-later

set -e

# helper functions
log_error() {
echo -e "\e[31m$1\e[0m"
Expand All @@ -15,42 +17,65 @@ log_success() {
echo -e "\e[32m$1\e[0m"
}

log_info "Fetching all workflow jobs....."
required_vars=(
ELEMENT_CHAT_URL
ELEMENT_ROOM_ID
NIGHTLY_CI_USER_TOKEN
GITHUB_REPOSITORY
GITHUB_RUN_ID
BRANCH_NAME
NEEDS_JSON
)

response=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$RUN_ID/jobs?per_page=50")
for var in "${required_vars[@]}"; do
if [[ -z "${!var}" ]]; then
log_error "❌ Missing required environment variable: $var"
log_info ""
log_info "Required environment variables:"
log_info "- ELEMENT_CHAT_URL : URL of the Element chat (e.g. https://matrix.element.io)"
log_info "- ELEMENT_ROOM_ID : Matrix room ID (e.g. abcdefg:matrix.element.io)"
log_info "- NIGHTLY_CI_USER_TOKEN : Access token for sending messages (e.g. "sometoken")"
log_info "- GITHUB_REPOSITORY : GitHub repository (e.g. user/repo) set by GitHub Actions environment variable"
log_info "- GITHUB_RUN_ID : GitHub run ID (e.g. 123456789) set by GitHub Actions environment variable"
log_info "- BRANCH_NAME : Branch name (e.g. master)"
log_info "- NEEDS_JSON : JSON string containing job results"
log_info ""
exit 1
fi
done

log_info "Fetching jobs informations succeeded!
"
if [[ "$response" != *"jobs"* ]]; then
log_error "No jobs found in the below response!"
log_info "$response"
jobs=$(echo "$NEEDS_JSON" | jq -r 'keys[]' 2>/dev/null)
if [[ -z "$jobs" ]]; then
log_error "❌ No jobs found in below JSON:"
log_info "$NEEDS_JSON"
exit 1
fi

jobs_informations=$(echo "$response" | jq '.jobs[:-1]')
jobs_conclusions=$(echo "$jobs_informations" | jq -r '.[].conclusion')
results=$(echo "$NEEDS_JSON" | jq -r '.[].result' 2>/dev/null)

workflow_status="Success"
if [[ " ${jobs_conclusions[*]} " == *"failure"* ]]; then
workflow_status="Failure"
elif [[ " ${jobs_conclusions[*]} " == *"cancelled"* ]]; then
workflow_status="Cancelled"
elif [[ " ${jobs_conclusions[*]} " == *"skipped"* ]]; then
workflow_status="Skipped"
workflow_status="Success"
if [[ "${results[*]}" == *"failure"* ]]; then
workflow_status="Failure"
elif [[ "${results[*]}" == *"cancelled"* ]]; then
workflow_status="⚠️ Cancelled"
elif [[ "${results[*]}" == *"skipped"* ]]; then
workflow_status="⚠️ Skipped"
fi

log_info "Sending report to the element chat...."

payload=$(cat <<EOF
{
"msgtype": "m.text",
"body": "",
"format": "org.matrix.custom.html",
"formatted_body": "<a href=\"https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}\">NC-Nightly-${BRANCH_NAME}</a><br></br><b>Status: ${workflow_status}</b>"
}
EOF
)

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

if [[ "$send_message_to_room_response" != *"event_id"* ]]; then
Expand All @@ -59,4 +84,4 @@ if [[ "$send_message_to_room_response" != *"event_id"* ]]; then
exit 1
fi

log_success "Notification of the nightly build has been sent to Element chat (OpenProject + Nextcloud)"
log_success "Notification of the nightly build has been sent to Element chat (OpenProject + Nextcloud)"
2 changes: 1 addition & 1 deletion .github/workflows/app-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
nextcloud_versions:
required: false
type: string
default: "31 32"
default: "master"
php_versions:
required: false
type: string
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/nighlty-ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,26 @@ jobs:
secrets: inherit
with:
branch: master

app-upgrade-test:
uses: ./.github/workflows/app-upgrade.yml
with:
branch: master

notify-nightly-report:
needs: [builds, app-upgrade-test]
if: ${{ always() }}
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

- name: Notify Element (nightly builds)
env:
ELEMENT_CHAT_URL: ${{ secrets.ELEMENT_CHAT_URL }}
ELEMENT_ROOM_ID: ${{ secrets.ELEMENT_ROOM_ID }}
NIGHTLY_CI_USER_TOKEN: ${{ secrets.NIGHTLY_CI_USER_TOKEN }}
BRANCH_NAME: master
NEEDS_JSON: ${{ toJson(needs) }}
run: |
./.github/scripts/notify-to-element.sh
26 changes: 25 additions & 1 deletion .github/workflows/nighlty-ci-release-2-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@ jobs:
secrets: inherit
with:
branch: release/2.11
nextcloud_versions: "31 32"
nextcloud_versions: "31 32"

app-upgrade-test:
uses: ./.github/workflows/app-upgrade.yml
with:
branch: release/2.11
Comment thread
saw-jan marked this conversation as resolved.
nextcloud_versions: "31 32"

notify-nightly-report:
needs: [builds, app-upgrade-test]
if: ${{ always() }}
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

- name: Notify Element (nightly builds)
env:
ELEMENT_CHAT_URL: ${{ secrets.ELEMENT_CHAT_URL }}
ELEMENT_ROOM_ID: ${{ secrets.ELEMENT_ROOM_ID }}
NIGHTLY_CI_USER_TOKEN: ${{ secrets.NIGHTLY_CI_USER_TOKEN }}
BRANCH_NAME: release/2.11
NEEDS_JSON: ${{ toJson(needs) }}
run: |
./.github/scripts/notify-to-element.sh
26 changes: 25 additions & 1 deletion .github/workflows/nighty-ci-release-3-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,28 @@ jobs:
secrets: inherit
with:
branch: release/3.0
nextcloud_versions: "33"
nextcloud_versions: "33 master"

app-upgrade-test:
uses: ./.github/workflows/app-upgrade.yml
with:
branch: release/3.0
nextcloud_versions: "33"

notify-nightly-report:
needs: [builds, app-upgrade-test]
if: ${{ always() }}
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

- name: Notify Element (nightly builds)
env:
ELEMENT_CHAT_URL: ${{ secrets.ELEMENT_CHAT_URL }}
ELEMENT_ROOM_ID: ${{ secrets.ELEMENT_ROOM_ID }}
NIGHTLY_CI_USER_TOKEN: ${{ secrets.NIGHTLY_CI_USER_TOKEN }}
BRANCH_NAME: release/3.0
NEEDS_JSON: ${{ toJson(needs) }}
run: |
./.github/scripts/notify-to-element.sh
24 changes: 1 addition & 23 deletions .github/workflows/shared_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -326,26 +326,4 @@ jobs:
- name: API Tests
env:
NEXTCLOUD_BASE_URL: http://localhost
run: make api-test

notify-nightly-report:
needs:
- js-lint-unit
- api-phpunit-tests
if: ${{ always() && github.event_name == 'schedule' }}
runs-on: ubuntu-22.04
steps:
- name: checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8

- name: Notify nightly report to element
env:
ELEMENT_CHAT_URL: ${{ secrets.ELEMENT_CHAT_URL }}
ELEMENT_ROOM_ID: ${{ secrets.ELEMENT_ROOM_ID }}
NIGHTLY_CI_USER_TOKEN: ${{ secrets.NIGHTLY_CI_USER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO_OWNER: nextcloud
REPO_NAME: integration_openproject
RUN_ID: ${{ github.run_id }}
BRANCH_NAME: ${{ inputs.branch }}
run: ./.github/scripts/notify-to-element.sh
run: make api-test
Loading