File: linux-appimage-comment.yml

package info (click to toggle)
nextcloud-desktop 4.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,404 kB
  • sloc: cpp: 118,401; objc: 752; python: 606; sh: 395; ansic: 391; ruby: 174; makefile: 44; javascript: 32; xml: 6
file content (91 lines) | stat: -rw-r--r-- 3,867 bytes parent folder | download
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: GPL-2.0-or-later
name: Linux Appimage Comment
on:
  workflow_run:
    workflows: ["Linux Appimage Package"]
    types: [completed]

jobs:
  comment-appimage:
    name: Create a comment with a link to the built AppImage
    runs-on: ubuntu-latest
    if: |-
      github.event.workflow_run.event == 'pull_request' &&
      github.event.workflow_run.conclusion == 'success'
    steps:
      - name: Comment AppImage
        uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            // Discover the origin pull request ID.
            // Since GitHub does not include any pull requests from forks as part of a WorkflowRun we need to look up the PR ourselves.
            const pullRequestsForThisBranch = await github.rest.repos.listPullRequestsAssociatedWithCommit({
              owner: context.payload.workflow_run.head_repository.owner.login,
              repo: context.payload.workflow_run.head_repository.name,
              commit_sha: context.payload.workflow_run.head_branch,
            });
            const latestPullRequest = pullRequestsForThisBranch.data.sort((a, b) => b.id - a.id)[0];
            if (!latestPullRequest) {
              console.log("Could not find recent pull request related to this workflow run");
              return;
            };
            const prId = latestPullRequest.number;
            console.log(`Discovered pull request #${prId}`);

            const workflowArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
              owner: context.repo.owner,
              repo: context.repo.repo,
              run_id: context.payload.workflow_run.id,
            });
            const artifact = workflowArtifacts.data.artifacts.filter((artifact) => artifact.name == `nextcloud-appimage-pr-${prId}`)[0];

            if (!artifact) {
              console.log("Could not find matching artifact");
              return;
            }

            // artifact.url and artifact.archive_download_url contain a URL that's supposed to be used by API clients only
            const artifactUrl = `https://github.com/nextcloud/desktop/actions/runs/${artifact.workflow_run.id}/artifacts/${artifact.id}`;

            const comment_identifier_string = "<!-- automated comment for an appimage build -->";

            const comment_body = `
              ${comment_identifier_string}

              Artifact containing the AppImage: [${artifact.name}.zip](${artifactUrl})

              Digest: \`${artifact.digest}\`

              To test this change/fix you can download the above artifact file, unzip it, and run it.

              Please make sure to quit your existing Nextcloud app and backup your data.
            `;

            console.log("fetching old comments")
            const comments = await github.rest.issues.listComments({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: prId,
            });

            comments
              .data
              .filter(comment => comment.body?.includes(comment_identifier_string))
              .forEach(comment => {
                console.log(`deleting previous AppImage comment with ID ${comment.id}`)
                github.rest.issues.deleteComment({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  comment_id: comment.id,
                })
              });

            console.log("creating new comment")
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: prId,
              body: comment_body,
            });