blob: 238d77b6ce4c9c5ffca85a7caa5bc97589c7bf8d [file]
# Copyright 2024 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# Checks the result status of each job provided by 'jobs-json' and sends an
# alert if at least one job failed.
#
# Usage:
# ```yml
# jobs:
# job_1:
# ...
# job_2:
# ...
# my_summary:
# if: always()
# needs:
# - job_1
# - job_2
# uses: ./.github/workflows/workflow_summary.yml
# secrets: inherit
# with:
# jobs-json: ${{ toJson(needs) }}
# ```
name: Workflow Summary
on:
workflow_call:
inputs:
ci-deferred:
type: boolean
default: false
description: Whether CI is deferred for an upper stack PR.
jobs-json:
type: string
description: The output of `toJson(needs)`
permissions:
contents: read
jobs:
summary:
runs-on: ubuntu-24.04
steps:
- name: Getting failed jobs
id: failed_jobs
run: |
echo '${{ inputs.jobs-json }}'
FAILED_JOBS="$(echo '${{ inputs.jobs-json }}' \
| jq --raw-output \
'map_values(select(.result!="success" and .result!="skipped")) | keys | join(",")' \
)"
echo "failed-jobs=${FAILED_JOBS}" >> $GITHUB_OUTPUT
if [[ "${FAILED_JOBS}" != "" ]]; then
echo "The following jobs failed: ${FAILED_JOBS}"
exit 1
fi
- name: Require CI before merging
if: inputs.ci-deferred
run: |
message="CI is deferred. This PR must become the lowest unmerged PR in its stack and pass CI before merging."
echo "::error::${message}"
echo "${message}" >> "${GITHUB_STEP_SUMMARY}"
exit 1
- name: Post to Discord on Failure
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
if: failure() && github.ref_name == 'main' && github.repository_owner == 'iree-org'
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
description: "The following jobs failed: ${{ steps.failed_jobs.outputs.failed-jobs }}"
url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}"