-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (57 loc) · 2.13 KB
/
comment-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
name: comment action
on:
issue_comment:
types:
- created
jobs:
trigger:
name: Trigger helm-install action
if: ${{ github.event.issue.pull_request && github.event.comment.author_association == 'OWNER' }}
runs-on: ubuntu-latest
permissions:
actions: write
issues: write
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
let createComment = function (message) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
}
const parsed = context.payload.comment.body.match(/\/(?<command>[^\s]+) (?<deployment>[^\s]+)/);
if (parsed == null) return;
if (parsed.groups.command == 'deploy') {
try {
const pull_request = await github.rest.pulls.get({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
pull_number: context.payload.issue.number
});
const dispatch = await github.rest.actions.createWorkflowDispatch({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
workflow_id: "helm-install.yaml",
ref: pull_request.data.head.ref,
inputs: { deployment: parsed.groups.deployment }
});
console.log(dispatch)
createComment("✅ Created new [helm-install](https://github.com/klausmeyer/k8s-pi-cluster/actions/workflows/helm-install.yaml) workflow run");
}
catch (error) {
if (error.status) {
createComment(`💥 ${error.message}`);
}
else {
throw error;
}
}
}
else {
createComment(`🙃 Unknown command: ${parsed.groups.command}`);
}