-
Notifications
You must be signed in to change notification settings - Fork 47
99 lines (96 loc) · 3.35 KB
/
canary.yml
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
92
93
94
95
96
97
98
99
name: Publish canary on PR comment
on:
issue_comment:
types:
- created
jobs:
check_auth:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/canary' }}
steps:
- name: Check auth
id: check_auth
uses: actions/github-script@v6
with:
result-encoding: string
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
const { login: username } = context.payload.comment.user;
await github.rest.repos.checkCollaborator({
owner,
repo,
username,
});
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "eyes",
});
const { number: pull_number } = context.payload.issue;
const { data: { head: { ref: branch }}} = await github.rest.pulls.get({
owner,
repo,
pull_number,
});
return branch;
- name: Not a collaborator
if: ${{ failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo, number: issue_number } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "-1",
});
github.rest.issues.createComment({
owner,
repo,
issue_number,
body: 'Canary builds can only be requested by collaborators. Please tag a maintainer to request a canary build. ❌',
});
outputs:
branch: ${{ steps.check_auth.outputs.result }}
trigger_canary:
runs-on: ubuntu-latest
needs: check_auth
steps:
- name: Trigger canary build
run: |
curl --no-progress-meter --fail --request POST \
--url https://circleci.com/api/v2/project/gh/${{ github.repository }}/pipeline \
--header 'Circle-Token: ${{ secrets.CCI_TOKEN }}' \
--header 'content-type: application/json' \
--header 'x-attribution-login: ${{ github.actor }}' \
--header 'x-attribution-actor-id: ${{ github.actor }}' \
--data '{ "branch": "${{ needs.check_auth.outputs.branch }}", "parameters": { "should_release": true }}'
- name: Trigger success
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "rocket",
});
- name: Trigger failed
if: ${{ failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "confused",
});