summaryrefslogtreecommitdiffstats
path: root/.github/workflows/comment-ir-version-check.yml
blob: 462e2ec9c6f3cb0632b4f1c7f3bd2bb20738e0a1 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
name: Comment IR Version Check Results

on:
  workflow_run:
    workflows: ["CI"]
    types:
      - completed

jobs:
  comment:
    runs-on: ubuntu-latest
    if: github.event.workflow_run.event == 'pull_request'

    steps:
      - name: Download artifacts
        id: download
        uses: actions/github-script@v7
        with:
          script: |
            const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: ${{ github.event.workflow_run.id }},
            });

            const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
              return artifact.name == "ir-version-check-results"
            })[0];

            if (!matchArtifact) {
              console.log('No IR version check artifacts found - nothing to comment');
              return false;
            }

            const download = await github.rest.actions.downloadArtifact({
              owner: context.repo.owner,
              repo: context.repo.repo,
              artifact_id: matchArtifact.id,
              archive_format: 'zip',
            });

            const fs = require('fs');
            fs.writeFileSync('${{github.workspace}}/ir-version-check-results.zip', Buffer.from(download.data));
            return true;

      - name: Extract artifacts
        if: steps.download.outputs.result == 'true'
        run: unzip ir-version-check-results.zip

      - name: Read PR number
        if: steps.download.outputs.result == 'true'
        id: pr
        run: |
          echo "number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT

      - name: Find existing comment
        if: steps.download.outputs.result == 'true'
        id: find-comment
        uses: peter-evans/find-comment@v3
        with:
          token: ${{ secrets.SLANGBOT_PAT }}
          issue-number: ${{ steps.pr.outputs.number }}
          body-includes: "<!-- slang-ir-version-check -->"

      - name: Create or update comment
        if: steps.download.outputs.result == 'true'
        uses: peter-evans/create-or-update-comment@v4
        with:
          token: ${{ secrets.SLANGBOT_PAT }}
          issue-number: ${{ steps.pr.outputs.number }}
          comment-id: ${{ steps.find-comment.outputs.comment-id }}
          body-path: comment-body.txt
          edit-mode: replace