forked from apache/camel
-
Notifications
You must be signed in to change notification settings - Fork 0
126 lines (116 loc) · 4.81 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
#
# 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:
- 'core/**'
- 'components/**'
workflow_run:
workflows: [ "PR Build (Camel 3.x)", "PR Build (Camel 4)" ]
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:
:warning: Please note that the changes on this PR may be **tested automatically**.
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 total = Number(fs.readFileSync('./total'));
let tested = Number(fs.readFileSync('./tested'));
let failures = Number(fs.readFileSync('./failures'));
let successes = Number(fs.readFileSync('./successes'));
var message = ""
if (tested === 0) {
if (total === 0) {
message = ":no_entry_sign: There are (likely) no components to be tested in this PR"
} else {
if (total > 20) {
message = `:leftwards_arrow_with_hook: There are either **too many** changes to be tested in this PR or the code **needs be rebased**: (${total} components likely to be affected)`
}
}
} else {
message = `### Components tested:
| Total | Tested | Failed :x: | Passed :white_check_mark: |
| --- | --- | --- | --- |
| ${total} | ${tested} | ${failures} | ${successes} |`
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message
});