Linux Flatpak Comment #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | |
| # SPDX-License-Identifier: GPL-2.0-or-later | |
| name: Linux Flatpak Comment | |
| on: | |
| workflow_run: | |
| workflows: ["Linux Flatpak Package"] | |
| types: [completed] | |
| jobs: | |
| comment-flatpak: | |
| name: Create a comment with a link to the built Flatpak | |
| runs-on: ubuntu-latest | |
| if: |- | |
| github.event.workflow_run.event == 'pull_request' && | |
| github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: Comment Flatpak | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.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 == "com.nextcloud.desktopclient.nextcloud.flatpak")[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 a flatpak build -->"; | |
| const comment_body = ` | |
| ${comment_identifier_string} | |
| Artifact containing the Flatpak bundle: [${artifact.name}.zip](${artifactUrl}) | |
| Digest: \`${artifact.digest}\` | |
| To test this change/fix you can download the above artifact file, unzip it, and install the bundle with: | |
| \`flatpak install --user ${artifact.name}\` | |
| 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 Flatpak 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, | |
| }); |