aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/status-embed.yaml
blob: f90b211b3c24c3953f79de8ec74fa47a19a6d238 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Status Embed

on:
  workflow_run:
    workflows:
      - CI
    types:
      - completed

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  status_embed:
    name:  Send Status Embed to Discord
    runs-on: ubuntu-latest

    steps:
      # A workflow_run event does not contain all the information
      # we need for a PR embed. That's why we upload an artifact
      # with that information in the Lint workflow.
      - name: Get Pull Request Information
        id: pr_info
        if: github.event.workflow_run.event == 'pull_request'
        run: |
          curl -s -H "Authorization: token $GITHUB_TOKEN" ${{ github.event.workflow_run.artifacts_url }} > artifacts.json
          DOWNLOAD_URL=$(cat artifacts.json | jq -r '.artifacts[] | select(.name == "pull-request-payload") | .archive_download_url')
          [ -z "$DOWNLOAD_URL" ] && exit 1
          curl -sSL -H "Authorization: token $GITHUB_TOKEN" -o pull_request_payload.zip $DOWNLOAD_URL || exit 2
          unzip -p pull_request_payload.zip > pull_request_payload.json
          [ -s pull_request_payload.json ] || exit 3
          echo "pr_author_login=$(jq -r '.user.login // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
          echo "pr_number=$(jq -r '.number // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
          echo "pr_title=$(jq -r '.title // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
          echo "pr_source=$(jq -r '.head.label // empty' pull_request_payload.json)" >> $GITHUB_OUTPUT
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      # Send an informational status embed to Discord instead of the
      # standard embeds that Discord sends. This embed will contain
      # more information and we can fine tune when we actually want
      # to send an embed.
      - name: GitHub Actions Status Embed for Discord
        uses: SebastiaanZ/[email protected]
        with:
          # Our GitHub Actions webhook
          webhook_id: '784184528997842985'
          webhook_token: ${{ secrets.GHA_WEBHOOK_TOKEN }}

          # We need to provide the information of the workflow that
          # triggered this workflow instead of this workflow.
          workflow_name: ${{ github.event.workflow_run.name }}
          run_id: ${{ github.event.workflow_run.id }}
          run_number: ${{ github.event.workflow_run.run_number }}
          status: ${{ github.event.workflow_run.conclusion }}
          sha: ${{ github.event.workflow_run.head_sha }}

          pr_author_login: ${{ steps.pr_info.outputs.pr_author_login }}
          pr_number: ${{ steps.pr_info.outputs.pr_number }}
          pr_title: ${{ steps.pr_info.outputs.pr_title }}
          pr_source: ${{ steps.pr_info.outputs.pr_source }}