Skip to content

Commit ec77150

Browse files
committed
Update build.yml
1 parent 41fdb07 commit ec77150

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
name: build
22

33
on:
4-
pull_request_target:
4+
pull_request_target: # Runs on PRs from forks, safely (no secrets)
55
push:
6-
branches: master
6+
branches: master # Runs on direct pushes to master
77

88
jobs:
99
test:
1010
runs-on: ubuntu-latest
11+
1112
steps:
12-
- name: Checkout
13+
- name: Checkout PR Code Securely
1314
uses: actions/checkout@v3
1415
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 }}
1917

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 }}"
2220

2321
- name: Setup Java
2422
uses: actions/setup-java@v2
@@ -30,22 +28,32 @@ jobs:
3028
- name: Grant execute permission for gradlew
3129
run: chmod +x gradlew
3230

33-
- name: Clear Gradle Cache
34-
run: ./gradlew clean
35-
36-
- name: Run Check
31+
- name: Run Check (No Secrets)
3732
run: ./gradlew check
3833

39-
- name: Run Jacoco
34+
- name: Run Jacoco (No Secrets)
4035
run: ./gradlew jacocoTestReport
4136

42-
- name: Upload Report
37+
- name: Upload Test Report (No Secrets)
4338
uses: 'actions/upload-artifact@v4'
4439
with:
4540
name: report.xml
4641
path: ${{ github.workspace }}/ipv8/build/reports/jacoco/test/jacocoTestReport.xml
4742

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)
4957
id: jacoco
5058
uses: madrapps/[email protected]
5159
with:
@@ -54,12 +62,7 @@ jobs:
5462
min-coverage-overall: 60
5563
min-coverage-changed-files: 80
5664

57-
- name: Get the Coverage info
65+
- name: Get Coverage Info
5866
run: |
5967
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
6068
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

Comments
 (0)