diff --git a/.github/actions/workflow-dispatch/action.yml b/.github/actions/workflow-dispatch/action.yml index 64f7702..921396b 100644 --- a/.github/actions/workflow-dispatch/action.yml +++ b/.github/actions/workflow-dispatch/action.yml @@ -29,6 +29,18 @@ outputs: failures: description: The errors, one per line, empty if all targets succeeded value: ${{ steps.dispatch.outputs.failures }} + started: + description: Number of started runs + value: ${{ steps.dispatch.outputs.started }} + succeeded: + description: Number of started runs that succeeded, only counted with wait + value: ${{ steps.dispatch.outputs.succeeded }} + cancelled: + description: Number of started runs that were cancelled or skipped, only counted with wait + value: ${{ steps.dispatch.outputs.cancelled }} + failed: + description: Number of errors, i.e. lines of failures, including targets that could not be started + value: ${{ steps.dispatch.outputs.failed }} runs: using: composite diff --git a/.github/actions/workflow-dispatch/dispatch.sh b/.github/actions/workflow-dispatch/dispatch.sh index caf6b3c..4c19c59 100755 --- a/.github/actions/workflow-dispatch/dispatch.sh +++ b/.github/actions/workflow-dispatch/dispatch.sh @@ -144,13 +144,29 @@ if [ -n "${GITHUB_STEP_SUMMARY:-}" ] && [ "${#RUNS[@]}" -gt 0 ]; then } >> "$GITHUB_STEP_SUMMARY" fi -if [ "${#FAILURES[@]}" -gt 0 ]; then - if [ -n "${GITHUB_OUTPUT:-}" ]; then - { +SUCCEEDED=0 +CANCELLED=0 +for result in "${RESULTS[@]}"; do + case "$result" in + success) SUCCEEDED=$((SUCCEEDED + 1)) ;; + cancelled | skipped) CANCELLED=$((CANCELLED + 1)) ;; + esac +done + +if [ -n "${GITHUB_OUTPUT:-}" ]; then + { + echo "started=${#RUNS[@]}" + echo "succeeded=${SUCCEEDED}" + echo "cancelled=${CANCELLED}" + echo "failed=${#FAILURES[@]}" + if [ "${#FAILURES[@]}" -gt 0 ]; then echo 'failures<<__FAILURES_EOF__' printf '%s\n' "${FAILURES[@]}" echo '__FAILURES_EOF__' - } >> "$GITHUB_OUTPUT" - fi + fi + } >> "$GITHUB_OUTPUT" +fi + +if [ "${#FAILURES[@]}" -gt 0 ]; then exit 1 fi diff --git a/.github/workflows/snapshot-refresh.yml b/.github/workflows/snapshot-refresh.yml index e5da447..1ee0353 100644 --- a/.github/workflows/snapshot-refresh.yml +++ b/.github/workflows/snapshot-refresh.yml @@ -54,13 +54,46 @@ jobs: wait: 'true' token: ${{ secrets.DISPATCH_TOKEN }} + - name: Compose the message + id: message + if: ${{ !cancelled() }} + env: + OUTCOME: ${{ steps.dispatch.outcome }} + STARTED: ${{ steps.dispatch.outputs.started }} + SUCCEEDED: ${{ steps.dispatch.outputs.succeeded }} + CANCELLED: ${{ steps.dispatch.outputs.cancelled }} + FAILED: ${{ steps.dispatch.outputs.failed }} + FAILURES: ${{ steps.dispatch.outputs.failures }} + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + run: | + COUNTS="${SUCCEEDED:-0} of ${STARTED:-0} deploys succeeded" + [ "${CANCELLED:-0}" = 0 ] || COUNTS="${COUNTS}, ${CANCELLED} cancelled" + ERRORS="${FAILED:-0} errors" + [ "${FAILED:-0}" != 1 ] || ERRORS='1 error' + case "$OUTCOME" in + success) + MESSAGE="✅ Snapshot refresh: ${COUNTS}, ${RUN_URL}" + echo "success=true" >> "$GITHUB_OUTPUT" + ;; + failure) + MESSAGE="❌ Snapshot refresh failed: ${COUNTS}, ${ERRORS}, ${RUN_URL}"$'\n'"${FAILURES}" + ;; + *) + MESSAGE="❌ Snapshot refresh failed before dispatching, ${RUN_URL}" + ;; + esac + { + echo 'text<<__MESSAGE_EOF__' + echo "$MESSAGE" + echo '__MESSAGE_EOF__' + } >> "$GITHUB_OUTPUT" + - name: Notify Matrix - if: failure() + if: ${{ !cancelled() && (steps.message.outputs.success != 'true' || vars.SNAPSHOT_REFRESH_NOTIFY_SUCCESS != 'false') }} + continue-on-error: true uses: $/.github/actions/matrix-notify with: - message: | - ❌ Snapshot refresh failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} - ${{ steps.dispatch.outputs.failures }} + message: ${{ steps.message.outputs.text }} homeserver: ${{ vars.MATRIX_HOMESERVER }} room-id: ${{ vars.MATRIX_ROOM_ID }} token: ${{ secrets.MATRIX_ACCESS_TOKEN }} diff --git a/README.md b/README.md index 9aa9747..54c413b 100644 --- a/README.md +++ b/README.md @@ -145,14 +145,14 @@ The workflows read these organization variables from the calling repository, lik ## Notifications -Releases, version branches and failures of the snapshot refresh are reported to a Matrix room: +Releases, version branches and the snapshot refresh are reported to a Matrix room: | Workflow | Message | |----------------------------|---------------------------------------------------------------------------------------------------| | `maven-release.yml` | Released, released with a failing Docker push or GitHub release, failed or cancelled, rolled back | | `maven-version-branch.yml` | Branch created or failed | | `node-release.yml` | Published, published without GitHub release, failed | -| `snapshot-refresh.yml` | Failed, with the failing targets | +| `snapshot-refresh.yml` | Number of succeeded deploys, after a failure with the failing targets | The room is set by organization variables, which the workflows read from the calling repository: diff --git a/docs/snapshot-refresh.md b/docs/snapshot-refresh.md index ef59a29..4e25362 100644 --- a/docs/snapshot-refresh.md +++ b/docs/snapshot-refresh.md @@ -35,7 +35,8 @@ flowchart LR so the 90 days start again. 4. The workflow waits until all started deploys have finished, at most 5 hours. It fails if one of them failed or did not finish in time, and its job summary lists every deploy with its result and a link to its log. -5. If the run failed, a message with the failing targets goes to Matrix, see [Monitoring](#monitoring). +5. A message with the number of succeeded deploys goes to Matrix, after a failure with the failing targets, see + [Monitoring](#monitoring). Only one refresh runs at a time. A run started by hand while another one waits for its deploys starts afterwards. @@ -88,8 +89,12 @@ build twice. - A deploy that fails makes the refresh fail, with its link in the annotations and in the job summary. Since the refresh runs weekly and a snapshot lasts 90 days, there are several weeks to fix a broken build before its snapshot expires. -- A failed refresh sends a message to the Matrix room of the [notifications](../README.md#notifications), - with the link to the run and every failing target, so the whole team sees it. +- Every refresh that is not cancelled sends a message to the Matrix room of the + [notifications](../README.md#notifications), if Matrix is configured, e.g. + `✅ Snapshot refresh: 13 of 13 deploys succeeded` with the link to the run. After a failure it starts with ❌, counts + the errors and lists every failing target, so the whole team sees it. The weekly message on success shows that the + schedule still runs: a Monday without message means a dropped or disabled refresh. The repository variable + `SNAPSHOT_REFRESH_NOTIFY_SUCCESS` set to `false` turns the message on success off, failures are always reported. - A deploy that was cancelled is only a warning. A push to the same branch during the refresh replaces the dispatched run within the concurrency group of the project, and that run deploys the snapshot as well. - GitHub notifies the user who created the workflow about failed scheduled runs, or whoever changed the cron