-
Notifications
You must be signed in to change notification settings - Fork 20
92 lines (86 loc) · 3.19 KB
/
test-ci-command.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
name: test-CI-on-PR-command
concurrency:
group: ci-${{ github.run_id }}
cancel-in-progress: true
on:
issue_comment:
types:
- created
jobs:
check-before-test:
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.repository_owner == 'cryostatio' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/build_test')
steps:
- name: Fail if needs-triage label applied
if: ${{ contains(github.event.issue.labels.*.name, 'needs-triage') }}
run: exit 1
- name: Show warning if permission is denied
if: |
!(github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
&& (!contains(github.event.issue.labels.*.name, 'safe-to-test') || github.event.issue.user.name != github.event.comment.user.name)
uses: thollander/actions-comment-pull-request@v2
with:
message: |-
You do not have permission to run the /build_test command. Please ask @cryostatio/reviewers
to resolve the issue.
- name: Fail if command permission is denied
if: |
!(github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
&& (!contains(github.event.issue.labels.*.name, 'safe-to-test') || github.event.issue.user.name != github.event.comment.user.name)
run: exit 1
- name: React to comment
uses: actions/github-script@v4
with:
script: |
const {owner, repo} = context.issue
github.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "+1",
});
checkout-branch:
runs-on: ubuntu-latest
needs: [check-before-test]
permissions:
pull-requests: read
outputs:
PR_head_ref: ${{ fromJSON(steps.comment-branch.outputs.result).ref }}
PR_num: ${{ fromJSON(steps.comment-branch.outputs.result).num }}
PR_repo: ${{ fromJSON(steps.comment-branch.outputs.result).repo }}
steps:
- uses: actions/github-script@v4
id: comment-branch
with:
script: |
const result = await github.pulls.get ({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
})
return { repo: result.data.head.repo.full_name, num: result.data.number, ref: result.data.head.ref }
get-test-image-tag:
runs-on: ubuntu-latest
needs: [checkout-branch]
env:
num: ${{ needs.checkout-branch.outputs.PR_num }}
outputs:
tag: ${{ steps.compute-tag.outputs.tag }}
steps:
- name: Compute test image tag
id: compute-tag
run: |
prefix="ci"
if [ -n "${{ env.num }}" ]; then
prefix="pr-${{ env.num }}"
fi
echo "tag=${prefix}-$GITHUB_SHA" >> $GITHUB_OUTPUT
run-test-jobs:
uses: ./.github/workflows/test-ci-reusable.yml
needs: [get-test-image-tag, checkout-branch]
with:
repository: ${{ needs.checkout-branch.outputs.PR_repo }}
ref: ${{ needs.checkout-branch.outputs.PR_head_ref }}
tag: ${{ needs.get-test-image-tag.outputs.tag }}