1
1
name : build
2
2
3
3
on :
4
- pull_request_target :
4
+ pull_request_target : # Runs on PRs from forks, safely (no secrets)
5
5
push :
6
- branches : master
6
+ branches : master # Runs on direct pushes to master
7
7
8
8
jobs :
9
9
test :
10
10
runs-on : ubuntu-latest
11
+
11
12
steps :
12
- - name : Checkout
13
+ - name : Checkout PR Code Securely
13
14
uses : actions/checkout@v3
14
15
with :
15
- fetch-depth : 0
16
-
17
- - name : Debug - Print Last Commit
18
- run : git log -1
16
+ ref : ${{ github.event.pull_request.head.sha }}
19
17
20
- - name : Debug - Check File Changes
21
- run : git diff --name-only HEAD~1 HEAD
18
+ - name : Debug - Print GitHub Event
19
+ run : echo "Triggered by ${{ github.event_name }}"
22
20
23
21
- name : Setup Java
24
22
uses : actions/setup-java@v2
@@ -30,22 +28,32 @@ jobs:
30
28
- name : Grant execute permission for gradlew
31
29
run : chmod +x gradlew
32
30
33
- - name : Clear Gradle Cache
34
- run : ./gradlew clean
35
-
36
- - name : Run Check
31
+ - name : Run Check (No Secrets)
37
32
run : ./gradlew check
38
33
39
- - name : Run Jacoco
34
+ - name : Run Jacoco (No Secrets)
40
35
run : ./gradlew jacocoTestReport
41
36
42
- - name : Upload Report
37
+ - name : Upload Test Report (No Secrets)
43
38
uses : ' actions/upload-artifact@v4'
44
39
with :
45
40
name : report.xml
46
41
path : ${{ github.workspace }}/ipv8/build/reports/jacoco/test/jacocoTestReport.xml
47
42
48
- - name : Add coverage to PR
43
+ secure-tasks :
44
+ needs : test
45
+ runs-on : ubuntu-latest
46
+ if : github.event_name == 'push' || github.event.pull_request.head.repo.fork == false # Runs only if merged or trusted contributor
47
+ steps :
48
+ - name : Checkout Latest Code
49
+ uses : actions/checkout@v3
50
+
51
+ - name : Upload Coverage to Codecov (Requires Secrets)
52
+ uses : codecov/codecov-action@v1
53
+ with :
54
+ token : ${{ secrets.CODECOV_TOKEN }}
55
+
56
+ - name : Add Coverage to PR (Requires Secrets)
49
57
id : jacoco
50
58
51
59
with :
54
62
min-coverage-overall : 60
55
63
min-coverage-changed-files : 80
56
64
57
- - name : Get the Coverage info
65
+ - name : Get Coverage Info
58
66
run : |
59
67
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
60
68
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
61
-
62
- - name : Upload coverage to Codecov
63
- uses : codecov/codecov-action@v1
64
- with :
65
- token : ${{ secrets.CODECOV_TOKEN }}
0 commit comments