diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 8940a6412b8..f5bd59615e7 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -42,7 +42,7 @@ jobs: path: | .gradle/caches gradle/wrapper - rsk-core/build + rskj-core/build key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- @@ -57,43 +57,58 @@ jobs: sonarqube: needs: build runs-on: ubuntu-latest - container: - image: eclipse-temurin:17-jdk - defaults: - run: - working-directory: . steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Java JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Verify Java installation + run: java -version + + - uses: actions/cache@v4 + name: Restore Gradle cache + with: + path: | + .gradle/caches + gradle/wrapper + rskj-core/build + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Build + run: | + ./configure.sh + - name: Run SonarQube analysis run: | - echo "Installing git" - apt-get update && apt-get install -yqq git + sudo apt-get update && sudo apt-get install -yqq git extra_flags="" - echo "Get GH event type" - event_name="${{ github.event_name }}" - if [ "$event_name" = "pull_request" ]; then - echo "Setting up PR analysis" - echo "switch to master" + if [ -n "$CIRCLE_PULL_REQUEST" ]; then + # https://community.sonarsource.com/t/no-code-or-issue-found-in-pull-request-decorations-github-circleci/8496 git branch -f master origin/master - pr_number=${{ github.event.pull_request.number }} - echo "PR number: $pr_number" - extra_flags="-Dsonar.pullrequest.base=master -Dsonar.pullrequest.branch=${{ github.head_ref }} -Dsonar.pullrequest.key=$pr_number" - echo "PR analysis flags: $extra_flags" + # extract PR number, as PR URLs are in the form + # https://github.com/$user/$repo/pull/$pr_number + pr_number==${{ github.event.pull_request.number }} + extra_flags="-Dsonar.pullrequest.base=master + -Dsonar.pullrequest.branch=${{ github.head_ref }} + -Dsonar.pullrequest.key=$pr_number" else - echo "Setting up branch analysis" extra_flags="-Dsonar.branch.name=master" - echo "Branch analysis flags: $extra_flags" fi - - sonar_url=${{ secrets.SONAR_URL }} - sonar_token=${{ secrets.SONAR_TOKEN }} - echo "Event name: $event_name" - echo "Sonar URL: $sonar_url" - - echo "Running SonarQube analysis" - ./configure.sh - ./gradlew sonarqube --no-daemon -x build -x test $extra_flags \ - -Dsonar.organization=rsksmart -Dsonar.host.url="$sonar_url" -Dsonar.login="$sonar_token" + pwd + ls -al + ./gradlew sonarqube --no-daemon -x build -x test \ + $extra_flags \ + -Dsonar.organization=rsksmart \ + -Dsonar.host.url="https://sonarcloud.io" \ + -Dsonar.login="${{ secrets.SONAR_TOKEN }}" tests: needs: build @@ -152,8 +167,8 @@ jobs: - name: Check out the mining integration tests repository uses: actions/checkout@v4 with: - repository: jurajpiar/mining-integration-tests -# ref: ${{ secrets.MINING_INTEGRATION_TESTS_REF }} + repository: rsksmart/mining-integration-tests + ref: 8bbfd75328344eeff567c93ad15db1e864ba6445 token: ${{ secrets.GITHUB_TOKEN }} - name: Log in to Docker Hub @@ -164,27 +179,27 @@ jobs: - name: Build and push Docker images run: | - docker build -t jurajpiar/bitcoind1:latest -f bitcoind1.Dockerfile . - docker push jurajpiar/bitcoind1:latest - docker build -t jurajpiar/bitcoind2:latest -f bitcoind2.Dockerfile . - docker push jurajpiar/bitcoind2:latest + docker build -t rsksmart/mit_bitcoind1:latest -f bitcoind1.Dockerfile . + docker push rsksmart/mit_bitcoind1:latest + docker build -t rsksmart/mit_bitcoind2:latest -f bitcoind2.Dockerfile . + docker push rsksmart/mit_bitcoind2:latest mining-tests: needs: - - build-push-docker-images +# - build-push-docker-images // TODO: Uncomment once the we have the permission to push the images - build runs-on: ubuntu-latest services: bitcoind1: - image: jurajpiar/bitcoind1:latest + image: jurajpiar/mit_bitcoind1:latest ports: - 8331:8331 - 31591:31591 - 32591:32591 options: --name bitcoind1 bitcoind2: - image: jurajpiar/bitcoind2:latest + image: jurajpiar/mit_bitcoind2:latest ports: - 8332:8332 - 31592:31592 @@ -204,7 +219,7 @@ jobs: - name: Checkout Mining Integration Tests Repository uses: actions/checkout@v4 with: - repository: jurajpiar/mining-integration-tests + repository: rsksmart/mining-integration-tests ref: ${{ secrets.MINING_INTEGRATION_TESTS_REF }} token: ${{ secrets.GITHUB_TOKEN }} path: mining-integration-tests @@ -214,6 +229,11 @@ jobs: run: | npm ci + - name: Change mining-integration-tests bitcoind url in config.json to localhost + working-directory: mining-integration-tests + run: | + sed -i 's/bitcoind01/localhost/g' config.json + - name: Generate BTC blocks working-directory: mining-integration-tests run: | @@ -234,17 +254,16 @@ jobs: path: | .gradle/caches gradle/wrapper - rsk-core/build + rskj-core/build key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} restore-keys: | ${{ runner.os }}-gradle- - name: Build run: | - ls -al rskj-core/build - ls -al ./gradle/wrapper/gradle-wrapper.jar - ./configure.sh - + if [ ! -d rskj-core/build ]; then + ./configure.sh + fi - name: Start RSKj and Run Tests working-directory: mining-integration-tests run: | diff --git a/build.gradle b/build.gradle index e26d0acfee6..9804a84faab 100644 --- a/build.gradle +++ b/build.gradle @@ -7,3 +7,13 @@ subprojects { group = 'co.rsk' version = config.modifier?.trim() ? config.versionNumber + "-" + config.modifier : config.versionNumber } + +sonarqube { + properties { + property "sonar.java.binaries", "rskj-core/build/classes/java/main" + property "sonar.scm.provider", "git" + property "sonar.projectBaseDir", project.projectDir + property "sonar.projectKey", "rskj" + property "sonar.organization", "rsksmart" + } +} \ No newline at end of file diff --git a/mining-test/bitcoind01/Dockerfile b/mining-test/bitcoind01/Dockerfile deleted file mode 100644 index 1328d082ba2..00000000000 --- a/mining-test/bitcoind01/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM kylemanna/bitcoind:latest -COPY start-bitcoind.sh /usr/local/bin/start-bitcoind.sh -RUN chmod +x /usr/local/bin/start-bitcoind.sh -ENTRYPOINT ["/usr/local/bin/start-bitcoind.sh"] -CMD ["31591", "localhost:31592", "32591", "0.0.0.0/0", "admin", "admin"] diff --git a/mining-test/bitcoind01/bitcoind.conf b/mining-test/bitcoind01/bitcoind.conf deleted file mode 100644 index d1f687fdb27..00000000000 --- a/mining-test/bitcoind01/bitcoind.conf +++ /dev/null @@ -1,15 +0,0 @@ -testnet=0 -server=1 -debug=1 -listen=1 -regtest=1 -daemon=0 -port=31591 -rpcuser=admin -rpcpassword=admin -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -printtoconsole=1 - -peertimeout=999999 \ No newline at end of file diff --git a/mining-test/bitcoind02/bitcoind.conf b/mining-test/bitcoind02/bitcoind.conf deleted file mode 100644 index 5fdc6a4382c..00000000000 --- a/mining-test/bitcoind02/bitcoind.conf +++ /dev/null @@ -1,15 +0,0 @@ -testnet=0 -server=1 -debug=1 -listen=1 -regtest=1 -daemon=0 -port=31592 -rpcuser=admin -rpcpassword=admin -connect=localhost:31591 -rpcbind=0.0.0.0:32592 -rpcallowip=0.0.0.0/0 -printtoconsole=1 - -peertimeout=999999 diff --git a/mining-test/docker-compose.yml b/mining-test/docker-compose.yml deleted file mode 100644 index b8d36bdb2ac..00000000000 --- a/mining-test/docker-compose.yml +++ /dev/null @@ -1,48 +0,0 @@ -version: '3.8' - -services: - bitcoind1: - image: 'kylemanna/bitcoind:latest' - entrypoint: 'bitcoind' - container_name: 'bitcoind1' - ports: - - '8331:8331' - - '31591:31591' - - '32591:32591' - command: - -printtoconsole - -server - -listen - -port=31591 - -rpcport=32591 - -rpcallowip=::/0 - -rpcuser=admin - -rpcpassword=admin - -regtest - -debug - -connect=bitcoind2:31592 - -zmqpubhashblock=tcp://*:8331 - -zmqpubhashtx=tcp://*:8331 - - bitcoind2: - image: 'kylemanna/bitcoind:latest' - entrypoint: 'bitcoind' - container_name: 'bitcoind2' - ports: - - '8332:8332' - - '31592:31592' - - '32592:32592' - command: - -printtoconsole - -server - -listen - -port=31592 - -rpcport=32592 - -rpcuser=admin - -rpcpassword=admin - -rpcallowip=::/0 - -regtest - -debug - -connect=bitcoind1:31591 - -zmqpubhashblock=tcp://*:8332 - -zmqpubhashtx=tcp://*:8332 diff --git a/mining-test/run.sh b/mining-test/run.sh deleted file mode 100755 index 4bd075924c2..00000000000 --- a/mining-test/run.sh +++ /dev/null @@ -1,99 +0,0 @@ -#!/bin/bash - -version=$(tr -d "'\"" < rskj-core/src/main/resources/version.properties \ - | cut -d = -f 2- | paste -sd - -) -ls -la rskj-core/build/libs/rskj-core-"$version"-all.jar -java -Drsk.conf.file=./rsk-integration-test.conf -cp rskj-core/build/libs/rskj-core-"$version"-all.jar co.rsk.Start --regtest -rskpid=$! -echo "RSKj PID: $rskpid" -until nc -z 127.0.0.1 4444 -do - echo "Waiting for RskJ..." - sleep 1 -done - -#echo "create docker network for bitcoin nodes exposing it to host" -#sudo docker network create bitcoin-network -#docker network ls -#docker network inspect bitcoin-network -#docker network connect bitcoin-network bitcoind01 -#docker network connect bitcoin-network bitcoind02 - -#sudo docker run -d --network bitcoin-network --name bitcoind01 -p 31591:31591 -p 32591:32591 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31591 -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin -#sudo docker run -d --network bitcoin-network --name bitcoind02 -p 31592:31592 -p 32592:32592 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31592 -connect=localhost:31591 -rpcbind=0.0.0.0:32592 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin - -sudo docker run -d --name bitcoind01 -p 31591:31591 -p 32591:32591 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31591 -connect=localhost:31592 -rpcbind=0.0.0.0:32591 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin -sudo docker run -d --name bitcoind02 -p 31592:31592 -p 32592:32592 --entrypoint "/usr/local/bin/bitcoind" kylemanna/bitcoind:latest -printtoconsole -regtest -debug -server -listen -port=31592 -connect=localhost:31591 -rpcbind=0.0.0.0:32592 -rpcallowip=0.0.0.0/0 -rpcuser=admin -rpcpassword=admin - -while ! docker ps --format "{{.Names}}" | grep -wq bitcoind01; do - echo "Waiting for container bitcoind01 to start..." - sleep 5 # Wait for 5 seconds before checking again -done -echo "bitcoind01 container is running." - -while ! docker ps --format "{{.Names}}" | grep -wq bitcoind02; do - echo "Waiting for container bitcoind02 to start..." - sleep 5 # Wait for 5 seconds before checking again -done -echo "bitcoind02 container is running." - -#echo "Verify nodes are attached to the network" -#docker network ls -#docker network inspect bitcoin-network -#if ! docker network inspect bitcoin-network | grep -q "\"Name\": \"bitcoind01\""; then -# echo "bitcoind01 is not on the network" -# exit 1 -#fi -#if ! docker network inspect bitcoin-network | grep -q "\"Name\": \"bitcoind02\""; then -# echo "bitcoind02 is not on the network" -# exit 1 -#fi - -ports=(31591 32591 31592 32592) -for port in "${ports[@]}"; do - if ! sudo lsof -i:$port -sTCP:LISTEN > /dev/null; then - echo "Error: No process is listening on port $port" - exit 1 - fi -done -echo "Success: All specified ports are being listened to." - - -echo Test bitcoin node 1 -curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32591 --fail -if [ $? -ne 0 ]; then - echo "Error: Failed to connect to the Bitcoin bitcoind01 node" - exit 1 -fi -echo Test bitcoin node 2 -curl -s -u admin:admin --data-binary '{"jsonrpc":"1.0","id":"curltext","method":"getblockchaininfo","params":[]}' -H 'content-type:text/plain;' http://localhost:32592 --fail -if [ $? -ne 0 ]; then - echo "Error: Failed to connect to the Bitcoin bitcoind02 node" - exit 1 -fi -# -#echo "Linking btc nodes to localhost" -#echo "127.0.0.1 bitcoind01" | sudo tee -a /etc/host -#echo "127.0.0.1 bitcoind02" | sudo tee -a /etc/host -#echo "/etc/hosts" -#cat /etc/hosts - -echo "Modify test suite config" -# shellcheck disable=SC2046 -echo "bitcoind url before" -jq -r 'bitcoind.url' "mining-integration-tests/config.json" -jq --arg new_url "localhost" '.bitcoind.url = $new_url' "mining-integration-tests/config.json" > temp.json && mv temp.json "mining-integration-tests/config.json" -echo "bitcoind url after" -jq -r 'bitcoind.url' "mining-integration-tests/config.json" - -echo "Generate BTC blocks" - -echo "Inside mining-integration-tests" -cd mining-integration-tests || echo "mining-integration-tests does not exist in $(pwd)}" && echo "content:" && ls -al && exit 1 - -echo "Generate bitcoin blocks" -node generateBtcBlocks.js - -echo "And run tests" -npm test - diff --git a/mining-test/start-bitcoind.sh b/mining-test/start-bitcoind.sh deleted file mode 100644 index 6b99f932f8d..00000000000 --- a/mining-test/start-bitcoind.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -/usr/local/bin/bitcoind -printtoconsole -regtest -debug -server -listen -port=$1 -connect=$2 -rpcbind=$3 -rpcallowip=$4 -rpcuser=$5 -rpcpassword=$6