-
Notifications
You must be signed in to change notification settings - Fork 20
99 lines (93 loc) · 3.85 KB
/
pr_test.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: pr-test
on:
issue_comment:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: khan/pull-request-comment-trigger@master
id: check
with:
trigger: 'ci'
reaction: rocket
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: send comment
if: steps.check.outputs.triggered == 'true'
env:
URL: ${{ github.event.issue.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-X POST \
$URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data '{ "body": ":test_tube: [starting unit testing]( https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"')" }'
- name: Github API Request
if: steps.check.outputs.triggered == 'true'
id: request
uses: octokit/request-action@v2.0.0
with:
route: ${{ github.event.issue.pull_request.url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get PR informations
if: steps.check.outputs.triggered == 'true'
id: pr_data
run: |
echo "::set-output name=branch::${{ fromJson(steps.request.outputs.data).head.ref }}"
echo "::set-output name=repo_name::${{ fromJson(steps.request.outputs.data).head.repo.full_name }}"
echo "::set-output name=repo_clone_url::${{ fromJson(steps.request.outputs.data).head.repo.clone_url }}"
echo "::set-output name=repo_ssh_url::${{ fromJson(steps.request.outputs.data).head.repo.ssh_url }}"
- name: Checkout PR Branch
if: steps.check.outputs.triggered == 'true'
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ fromJson(steps.request.outputs.data).head.repo.full_name }}
ref: ${{ steps.pr_data.outputs.branch }}
- name: debug
if: steps.check.outputs.triggered == 'true'
id: debug
run: |
echo ::set-output name=sha::$( curl -u "u:${{github.token}}" https://api.github.com/repos/${{steps.pr_data.outputs.repo_name}}/git/ref/heads/${{steps.pr_data.outputs.branch}} | jq .object.sha | tr -d '"' )
- name: Set up JDK 1.8
if: steps.check.outputs.triggered == 'true'
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Test with Maven
if: steps.check.outputs.triggered == 'true'
run: mvn --batch-mode --update-snapshots test
- name: Create success comment
if: steps.check.outputs.triggered == 'true' && success()
env:
URL: ${{ github.event.issue.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-X POST \
$URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data '{ "body": ":v: [finish ci integration job successfully]( https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"')" }'
- name: Create fail comment
if: steps.check.outputs.triggered == 'true' && failure()
env:
URL: ${{ github.event.issue.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl \
-X POST \
$URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data '{ "body": ":facepalm: [ci integration job failed]( https://github.com/'"$GITHUB_REPOSITORY"'/actions/runs/'"$GITHUB_RUN_ID"')" }'