-
Notifications
You must be signed in to change notification settings - Fork 5k
162 lines (145 loc) · 6.5 KB
/
component-pr.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Component Check
on:
pull_request_target:
types:
- opened
- reopened
paths:
- 'parent/**'
- 'core/**'
- 'components/**'
workflow_run:
workflows: [ "PR Build (Camel 3.x)" ]
types:
- completed
permissions: {}
jobs:
process:
if: github.repository == 'apache/camel'
permissions:
pull-requests: write # to comment on a pull request
actions: read # to download artifact
name: Process
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
if: |
github.event_name == 'pull_request_target' &&
(github.event.action == 'opened' ||
github.event.action == 'reopened')
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:star2: Thank you for your contribution to the Apache Camel project! :star2:
:camel: Maintainers, please note that first-time contributors *require manual approval* for the GitHub Actions to run.
:warning: Please note that the changes on this PR may be **tested automatically** if they change components.
:robot: Use the command \`/component-test (camel-)component-name1 (camel-)component-name2..\` to request a test from the test bot.
If necessary Apache Camel Committers may access logs and test results in the job summaries!`
})
- name: 'Download artifact'
uses: actions/github-script@v6
if: |
github.event_name == 'workflow_run'
with:
# Secure download based on:
# - https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# - https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "test-logs"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/test-logs.zip', Buffer.from(download.data));
- run: unzip test-logs.zip
if: |
github.event_name == 'workflow_run'
- uses: actions/github-script@v6
if: |
github.event_name == 'workflow_run'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./pr_number'));
let componentsTotal = Number(fs.readFileSync('./components-total'));
let componentsTested = Number(fs.readFileSync('./components-tested'));
let componentsFailures = Number(fs.readFileSync('./components-failures'));
let componentsSuccesses = Number(fs.readFileSync('./components-successes'));
var message = ""
if (componentsTested === 0) {
if (componentsTotal === 0) {
message = ":no_entry_sign: There are (likely) no components to be tested in this PR"
} else {
if (componentsTotal > 20) {
message = `:leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (${componentsTotal} components likely to be affected)`
}
}
} else {
message = `### Components test results:
| Total | Tested | Failed :x: | Passed :white_check_mark: |
| --- | --- | --- | --- |
| ${componentsTotal} | ${componentsTested} | ${componentsFailures} | ${componentsSuccesses} |`
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});
- uses: actions/github-script@v6
if: |
github.event_name == 'workflow_run'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let issue_number = Number(fs.readFileSync('./pr_number'));
let coreTested = Number(fs.readFileSync('./core-tested'));
let coreFailures = Number(fs.readFileSync('./core-failures'));
let coreSuccesses = Number(fs.readFileSync('./core-successes'));
var message = ""
if (coreTested === 0) {
message = ":no_entry_sign: There are (likely) no changes in core core to be tested in this PR"
} else {
message = `### Core test results:
| Tested | Failed :x: | Passed :white_check_mark: |
| --- | --- | --- |
| ${coreTested} | ${coreFailures} | ${coreSuccesses} |`
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});