---
# yamllint disable rule:truthy

on:
  workflow_run:
    # Must restrict to given workflows:
    # https://github.com/community/community/discussions/16059
    workflows: [MacOS, Windows]
    types: [completed]

env:
  CONCLUSION: ${{ github.event.workflow_run.conclusion }}
  GIT_COMMIT: ${{ github.event.workflow_run.head_commit.id }}
  GIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }}
  JOB_URL: ${{ github.event.workflow_run.html_url }}
  JOB_NAME: ${{ github.event.workflow_run.name }}
  REPO_URL: ${{ github.event.workflow_run.head_repository.html_url }}

jobs:
  on-anything:
    runs-on: ubuntu-latest
    env:
      zulip_api_key: ${{ secrets.ZULIP_API_KEY }}
    steps:
      - run: echo "GITHUB_ACTOR=$GITHUB_ACTOR" >> $GITHUB_ENV
      - run: echo "SHORT_SHA=${GITHUB_SHA:0:8}" >> $GITHUB_ENV
      - if: ${{ env.zulip_api_key != ''}} 
        name: Tell Zulip
        uses: zulip/github-actions-zulip/send-message@v1
        with:
          email: github-actions-bot@opencpn.zulipchat.com
          api-key: ${{ secrets.ZULIP_API_KEY }}
          organization-url: 'https://opencpn.zulipchat.com'
          type: 'stream'
          to: 'CI'
          topic: 'OpenCPN'
          content: |
            Workflow ${{ env.JOB_NAME }} completed: [
            ${{ env.CONCLUSION }}](${{ env.JOB_URL }})
            -  Started by: ${{ env.GITHUB_ACTOR }}
            -  last commit: [${{ env.SHORT_SHA }}, ${{ env.GIT_MESSAGE }}](
               ${{ env.REPO_URL }}/commit/${{ env.GIT_COMMIT }})
