Skip to content

Commit d195403

Browse files
authored
Merge pull request #94 from Tribler/fix/build-issues
Fix/build issues
2 parents 2c5fab9 + ec77150 commit d195403

File tree

4 files changed

+70
-51
lines changed

4 files changed

+70
-51
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +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
15+
with:
16+
ref: ${{ github.event.pull_request.head.sha }}
17+
18+
- name: Debug - Print GitHub Event
19+
run: echo "Triggered by ${{ github.event_name }}"
1420

1521
- name: Setup Java
1622
uses: actions/setup-java@v2
@@ -22,19 +28,32 @@ jobs:
2228
- name: Grant execute permission for gradlew
2329
run: chmod +x gradlew
2430

25-
- name: Run Check
31+
- name: Run Check (No Secrets)
2632
run: ./gradlew check
2733

28-
- name: Run Jacoco
34+
- name: Run Jacoco (No Secrets)
2935
run: ./gradlew jacocoTestReport
3036

31-
- name: Upload Report
37+
- name: Upload Test Report (No Secrets)
3238
uses: 'actions/upload-artifact@v4'
3339
with:
3440
name: report.xml
3541
path: ${{ github.workspace }}/ipv8/build/reports/jacoco/test/jacocoTestReport.xml
3642

37-
- 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)
3857
id: jacoco
3958
uses: madrapps/jacoco-report@v1.7.1
4059
with:
@@ -43,12 +62,7 @@ jobs:
4362
min-coverage-overall: 60
4463
min-coverage-changed-files: 80
4564

46-
- name: Get the Coverage info
65+
- name: Get Coverage Info
4766
run: |
4867
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
4968
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
50-
51-
- name: Upload coverage to Codecov
52-
uses: codecov/codecov-action@v1
53-
with:
54-
token: ${{ secrets.CODECOV_TOKEN }}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ buildscript {
1818
maven { url 'https://jitpack.io' }
1919
}
2020
dependencies {
21-
classpath 'com.android.tools.build:gradle:8.8.0'
21+
classpath 'com.android.tools.build:gradle:8.8.0-alpha05'
2222
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2323
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_gradle_version"
2424
classpath "app.cash.sqldelight:gradle-plugin:$sqldelight_version"

demo-android/src/main/java/nl/tudelft/trustchain/demo/ui/DemoActivity.kt

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import android.widget.LinearLayout
55
import androidx.appcompat.app.AppCompatActivity
66
import androidx.core.content.res.ResourcesCompat
77
import androidx.core.view.isVisible
8+
import androidx.lifecycle.Lifecycle
89
import androidx.lifecycle.lifecycleScope
10+
import androidx.lifecycle.repeatOnLifecycle
911
import androidx.recyclerview.widget.DividerItemDecoration
1012
import androidx.recyclerview.widget.LinearLayoutManager
1113
import com.mattskala.itemadapter.ItemAdapter
1214
import kotlinx.coroutines.delay
13-
import kotlinx.coroutines.isActive
15+
import kotlinx.coroutines.launch
1416
import nl.tudelft.ipv8.android.IPv8Android
1517
import nl.tudelft.trustchain.demo.DemoCommunity
1618
import nl.tudelft.trustchain.demo.R
@@ -41,51 +43,54 @@ class DemoActivity : AppCompatActivity() {
4143
binding.recyclerView.layoutManager = LinearLayoutManager(this)
4244
binding.recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))
4345

44-
loadNetworkInfo()
46+
lifecycleScope.launch {
47+
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
48+
while (true) {
49+
loadNetworkInfo()
50+
delay(1000)
51+
}
52+
}
53+
}
4554
}
4655

4756
private fun loadNetworkInfo() {
48-
lifecycleScope.launchWhenStarted {
49-
while (isActive) {
50-
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
51-
val peers = demoCommunity.getPeers()
57+
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
58+
val peers = demoCommunity.getPeers()
5259

53-
val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)
60+
val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)
5461

55-
val discoveredBluetoothAddresses =
56-
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }
62+
val discoveredBluetoothAddresses =
63+
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }
5764

58-
val peerItems = peers.map {
59-
PeerItem(
60-
it
61-
)
62-
}
65+
val peerItems = peers.map {
66+
PeerItem(
67+
it
68+
)
69+
}
6370

64-
val addressItems = discoveredAddresses.map { address ->
65-
val contacted = demoCommunity.discoveredAddressesContacted[address]
66-
AddressItem(
67-
address, null, contacted
68-
)
69-
}
71+
val addressItems = discoveredAddresses.map { address ->
72+
val contacted = demoCommunity.discoveredAddressesContacted[address]
73+
AddressItem(
74+
address, null, contacted
75+
)
76+
}
7077

71-
val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
72-
AddressItem(
73-
address, null, null
74-
)
75-
}
78+
val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
79+
AddressItem(
80+
address, null, null
81+
)
82+
}
7683

77-
val items = peerItems + bluetoothAddressItems + addressItems
84+
val items = peerItems + bluetoothAddressItems + addressItems
85+
86+
adapter.updateItems(items)
87+
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
88+
binding.txtPeerCount.text = "${peers.size} peers"
89+
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
90+
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
91+
binding.txtPeerCount.setTextColor(textColor)
92+
binding.imgEmpty.isVisible = items.isEmpty()
7893

79-
adapter.updateItems(items)
80-
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
81-
binding.txtPeerCount.text = "${peers.size} peers"
82-
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
83-
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
84-
binding.txtPeerCount.setTextColor(textColor)
85-
binding.imgEmpty.isVisible = items.isEmpty()
8694

87-
delay(1000)
88-
}
89-
}
9095
}
9196
}

ipv8/src/main/java/nl/tudelft/ipv8/Community.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract class Community : Overlay {
7373
network.blacklist.addAll(DEFAULT_ADDRESSES)
7474

7575
job = SupervisorJob()
76-
scope = CoroutineScope(Dispatchers.Default + job)
76+
scope = CoroutineScope(Dispatchers.Main + job)
7777

7878
if (evaProtocolEnabled)
7979
evaProtocol = EVAProtocol(this, scope)

0 commit comments

Comments
 (0)