Skip to content

Commit

Permalink
Merge pull request #94 from Tribler/fix/build-issues
Browse files Browse the repository at this point in the history
Fix/build issues
  • Loading branch information
InvictusRMC authored Feb 7, 2025
2 parents 2c5fab9 + ec77150 commit d195403
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 51 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
name: build

on:
pull_request_target:
pull_request_target: # Runs on PRs from forks, safely (no secrets)
push:
branches: master
branches: master # Runs on direct pushes to master

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
- name: Checkout PR Code Securely
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Debug - Print GitHub Event
run: echo "Triggered by ${{ github.event_name }}"

- name: Setup Java
uses: actions/setup-java@v2
Expand All @@ -22,19 +28,32 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run Check
- name: Run Check (No Secrets)
run: ./gradlew check

- name: Run Jacoco
- name: Run Jacoco (No Secrets)
run: ./gradlew jacocoTestReport

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

- name: Add coverage to PR
secure-tasks:
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork == false # Runs only if merged or trusted contributor
steps:
- name: Checkout Latest Code
uses: actions/checkout@v3

- name: Upload Coverage to Codecov (Requires Secrets)
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Add Coverage to PR (Requires Secrets)
id: jacoco
uses: madrapps/[email protected]
with:
Expand All @@ -43,12 +62,7 @@ jobs:
min-coverage-overall: 60
min-coverage-changed-files: 80

- name: Get the Coverage info
- name: Get Coverage Info
run: |
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:8.8.0'
classpath 'com.android.tools.build:gradle:8.8.0-alpha05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_gradle_version"
classpath "app.cash.sqldelight:gradle-plugin:$sqldelight_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.mattskala.itemadapter.ItemAdapter
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.trustchain.demo.DemoCommunity
import nl.tudelft.trustchain.demo.R
Expand Down Expand Up @@ -41,51 +43,54 @@ class DemoActivity : AppCompatActivity() {
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))

loadNetworkInfo()
lifecycleScope.launch {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
while (true) {
loadNetworkInfo()
delay(1000)
}
}
}
}

private fun loadNetworkInfo() {
lifecycleScope.launchWhenStarted {
while (isActive) {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)
val discoveredAddresses = demoCommunity.network.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses =
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }
val discoveredBluetoothAddresses =
demoCommunity.network.getNewBluetoothPeerCandidates().map { it.address }

val peerItems = peers.map {
PeerItem(
it
)
}
val peerItems = peers.map {
PeerItem(
it
)
}

val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address, null, contacted
)
}
val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address, null, contacted
)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address, null, null
)
}
val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address, null, null
)
}

val items = peerItems + bluetoothAddressItems + addressItems
val items = peerItems + bluetoothAddressItems + addressItems

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

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

delay(1000)
}
}
}
}
2 changes: 1 addition & 1 deletion ipv8/src/main/java/nl/tudelft/ipv8/Community.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract class Community : Overlay {
network.blacklist.addAll(DEFAULT_ADDRESSES)

job = SupervisorJob()
scope = CoroutineScope(Dispatchers.Default + job)
scope = CoroutineScope(Dispatchers.Main + job)

if (evaProtocolEnabled)
evaProtocol = EVAProtocol(this, scope)
Expand Down

0 comments on commit d195403

Please sign in to comment.