-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yaml
77 lines (69 loc) · 2.38 KB
/
action.yaml
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
name: Helm Action Comment
description: Post a comment message with a Helm output on a pull request associated with the corresponding Helm action.
inputs:
helm-output:
description: The Helm action output
required: true
environment-name:
description: Name of the environment
required: true
helm-action:
description: The name of the helm action that produces the output
required: true
outputs: {}
runs:
using: composite
steps:
- name: Create comment message
shell: bash
id: create-comment-message
run: |
cat <<EOF >> "${GITHUB_OUTPUT}"
message<<EOM
## Environment: ${{ inputs.environment-name }}
<details>
<summary>
Helm ${{ inputs.helm-action }} output
</summary>
\`\`\`diff
${{ inputs.helm-output }}
\`\`\`
</details>
EOM
EOF
- name: Get pull request number
if: github.ref_name == github.event.repository.default_branch
uses: actions/github-script@v7
id: get-pr-number
continue-on-error: true
with:
result-encoding: string
retries: 3
script: |
const response = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: "${{ github.repository_owner }}",
repo: "${{ github.repository }}".split("/").pop(),
commit_sha: "${{ github.sha }}",
});
if (response.data.length != 0) {
let prNumber = response.data.pop().number;
return prNumber;
}
else {
throw new Error(
"Could not find pull request associated with the latest commit. Someone must have committed directly to the default branch ;("
);
}
- name: Comment pull request using PR number
if: steps.get-pr-number.outcome == 'success' && github.ref_name == github.event.repository.default_branch
uses: thollander/actions-comment-pull-request@v2
with:
message: |
${{ steps.create-comment-message.outputs.message }}
pr_number: ${{ steps.get-pr-number.outputs.result }}
- name: Comment pull request
if: github.ref_name != github.event.repository.default_branch
uses: thollander/actions-comment-pull-request@v2
with:
message: |
${{ steps.create-comment-message.outputs.message }}