From af8685131090f93ff6df166bd8d24b85162f0ce4 Mon Sep 17 00:00:00 2001 From: Juraj Piar Date: Mon, 17 Jun 2024 12:09:17 +0100 Subject: [PATCH] feat(ci): uses github actions --- .circleci/config.yml | 166 ------------------- .github/workflows/build_and_test.yml | 232 +++++++++++++++++++++++++++ build.gradle | 11 ++ 3 files changed, 243 insertions(+), 166 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/build_and_test.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index e99b948a6..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,166 +0,0 @@ -version: 2.1 - -executors: - fed-executor: - docker: - - image: openjdk:8-jdk - environment: - _JAVA_OPTIONS: "-Xmx3G -Xms2G" - working_directory: /app - resource_class: medium+ - - sonarqube-executor: - docker: - - image: eclipse-temurin:17-jdk - working_directory: /app - resource_class: medium+ - -jobs: - clone_rskj_repo: - executor: fed-executor - steps: - - checkout - - run: - name: Setup - command: apt update -y && apt install -y gnupg2 - - - run: - name: Verify files - command: | - curl -sSL https://secchannel.rsk.co/SUPPORT.asc | gpg2 --import - - gpg2 --verify SHA256SUMS.asc && sha256sum --check SHA256SUMS.asc - - run: - name: Clone rskj repo - command: | - git clone https://github.com/rsksmart/rskj.git - - run: - name: Checkout rskj repo - command: | - apt-get update && apt-get -y install jq - cd rskj - BRANCH_GET=`git ls-remote --heads origin ${CIRCLE_BRANCH}` - BRANCH_PR_GET=`echo https://api.github.com/repos/${CIRCLE_PULL_REQUEST:19} | sed "s/\/pull\//\/pulls\//" | xargs curl -s | jq -r '.base.ref' | xargs git ls-remote --heads origin | awk -F\/ '{ print $NF }'` - echo "Branch found on rskj repo to build (if empty none)=${BRANCH_GET}" - echo "Branch found on rskj repo to build matching PR on powpeg (if null none)=${BRANCH_PR_GET}" - if test -n "${BRANCH_GET}"; then - echo "Building ${CIRCLE_BRANCH} branch from rskj" - git checkout ${CIRCLE_BRANCH} - else - if [ -n "${BRANCH_PR_GET}" ] && [ "${BRANCH_PR_GET}" != "null" ]; then - echo "Building ${BRANCH_PR_GET} PR branch from rskj" - git checkout ${BRANCH_PR_GET} - else - echo "Building master branch from rskj" - fi - fi - - persist_to_workspace: - root: . - paths: - - . - - build_federator_node: - executor: fed-executor - steps: - - attach_workspace: - at: /app - - - run: - name: Build federator-node jar - command: | - echo "includeBuild('./rskj') {" > DONT-COMMIT-settings.gradle - echo " dependencySubstitution {" >> DONT-COMMIT-settings.gradle - echo " all { DependencySubstitution dependency ->" >> DONT-COMMIT-settings.gradle - echo " if (dependency.requested instanceof ModuleComponentSelector" >> DONT-COMMIT-settings.gradle - echo " && dependency.requested.group == 'co.rsk'" >> DONT-COMMIT-settings.gradle - echo " && dependency.requested.module == 'rskj-core'" >> DONT-COMMIT-settings.gradle - echo " && (dependency.requested.version.endsWith('SNAPSHOT') || dependency.requested.version.endsWith('RC'))) {" >> DONT-COMMIT-settings.gradle - echo " def targetProject = project(\":\${dependency.requested.module}\")" >> DONT-COMMIT-settings.gradle - echo " if (targetProject != null) {" >> DONT-COMMIT-settings.gradle - echo " println('---- USING LOCAL ' + dependency.requested.displayName +' PROJECT ----')" >> DONT-COMMIT-settings.gradle - echo " dependency.useTarget targetProject" >> DONT-COMMIT-settings.gradle - echo " }" >> DONT-COMMIT-settings.gradle - echo " }" >> DONT-COMMIT-settings.gradle - echo " }" >> DONT-COMMIT-settings.gradle - echo " }" >> DONT-COMMIT-settings.gradle - echo "}" >> DONT-COMMIT-settings.gradle - rm -rfv .gradle - ./configure.sh - ./gradlew --no-daemon dependencies - ./gradlew --no-daemon --stacktrace clean build -x test - - persist_to_workspace: - root: . - paths: - - . - - federator-tests: - executor: fed-executor - steps: - - attach_workspace: - at: /app - - run: - name: Perform federator tests - command: ./gradlew --no-daemon --stacktrace test - - run: - name: Save test results - command: | - mkdir -p junit/ - find build/test-results -type f -name "*.xml" \ - -exec cp {} junit/ \; - when: always - - store_test_results: - path: junit - - - store_artifacts: - path: junit - - - persist_to_workspace: - root: . - paths: - - . - - sonarqube: - executor: sonarqube-executor - steps: - - attach_workspace: - at: /app - - run: - name: Run SonarQube analysis - command: | - apt-get update && apt-get install -yqq git - extra_flags="" - 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 - # extract PR number, as PR URLs are in the form - # https://github.com/$user/$repo/pull/$pr_number - pr_number=${CIRCLE_PULL_REQUEST##*/} - extra_flags="-Dsonar.pullrequest.base=master - -Dsonar.pullrequest.branch=$CIRCLE_BRANCH - -Dsonar.pullrequest.key=$pr_number" - else - extra_flags="-Dsonar.branch.name=$CIRCLE_BRANCH" - fi - ./gradlew sonarqube --warning-mode all --no-daemon --stacktrace --info -x build -x test \ - $extra_flags \ - -Dsonar.organization=$SONAR_ORG \ - -Dsonar.projectKey=$SONAR_PROJECT_KEY \ - -Dsonar.host.url="$SONAR_URL" \ - -Dsonar.login="$SONAR_TOKEN" - -workflows: - version: 2 - build-and-test: - jobs: - - clone_rskj_repo - - - build_federator_node: - requires: - - clone_rskj_repo - - - federator-tests: - requires: - - build_federator_node - - - sonarqube: - requires: - - federator-tests diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 000000000..3be1bd519 --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,232 @@ +name: Build and test + +on: + push: + branches: + - master + - "*-rc" + pull_request: + types: + - opened + - synchronize + - reopened + branches: + - "**" + +jobs: + verify_files: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup + run: | + sudo apt-get update -y && sudo apt-get install -y gnupg2 + + - name: Verify files + run: | + curl -sSL https://secchannel.rsk.co/SUPPORT.asc | gpg --import - + gpg --verify SHA256SUMS.asc && sha256sum --check SHA256SUMS.asc + + clone_rskj_repo: + needs: verify_files + runs-on: ubuntu-latest + steps: + - name: Checkout RSKj repo + uses: actions/checkout@v4 + with: + repository: rsksmart/rskj + token: ${{ secrets.GITHUB_TOKEN }} + path: rskj + + - name: Determine branch to checkout for PR + if: github.event_name == 'pull_request' + working-directory: rskj + run: | + PR_BRANCH="${{ github.head_ref }}" + IS_RSKJ_BRANCH=`git ls-remote --heads origin $PR_BRANCH` + if test -n "${IS_RSKJ_BRANCH}"; then + echo "Found matching branch name in RSKj repo" + CHECKOUT_REF="$PR_BRANCH" + else + echo "Using master for RSKj" + CHECKOUT_REF="master" + fi + echo "CHECKOUT_REF=$CHECKOUT_REF" >> $GITHUB_ENV + + - name: Determine branch to checkout for push + if: github.event_name != 'pull_request' + working-directory: rskj + run: | + POW_REF="${{ github.ref }}" + IS_RSKJ_REF=`git ls-remote --refs $POW_REF` + if test -n "${IS_RSKJ_REF}"; then + echo "Found matching ref in RSKj" + CHECKOUT_REF="$POW_REF" + else + echo "Using master for RSKj" + CHECKOUT_REF="master" + fi + echo "CHECKOUT_REF=$CHECKOUT_REF" >> $GITHUB_ENV + + - name: Check out appropriate rskj reference + working-directory: rskj + run: | + git switch "${{ env.CHECKOUT_REF }}" + + - name: Persist RSKJ + uses: actions/upload-artifact@v4 + with: + name: rskj + path: rskj + + build_federator_node: + runs-on: ubuntu-latest + container: openjdk:8-jdk + needs: clone_rskj_repo + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download rskj + uses: actions/download-artifact@v4 + with: + name: rskj + path: rskj + + - uses: actions/cache@v4 + name: Cache Gradle + id: cache-gradle + with: + path: | + .gradle/caches + gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Get gradle wrapper and build dependencies + if: steps.cache-gradle.outputs.cache-hit != 'true' + run: | + echo "includeBuild('./rskj') {" > DONT-COMMIT-settings.gradle + echo " dependencySubstitution {" >> DONT-COMMIT-settings.gradle + echo " all { DependencySubstitution dependency ->" >> DONT-COMMIT-settings.gradle + echo " if (dependency.requested instanceof ModuleComponentSelector" >> DONT-COMMIT-settings.gradle + echo " && dependency.requested.group == 'co.rsk'" >> DONT-COMMIT-settings.gradle + echo " && dependency.requested.module == 'rskj-core'" >> DONT-COMMIT-settings.gradle + echo " && (dependency.requested.version.endsWith('SNAPSHOT') || dependency.requested.version.endsWith('RC'))) {" >> DONT-COMMIT-settings.gradle + echo " def targetProject = project(\":\${dependency.requested.module}\")" >> DONT-COMMIT-settings.gradle + echo " if (targetProject != null) {" >> DONT-COMMIT-settings.gradle + echo " println('---- USING LOCAL ' + dependency.requested.displayName +' PROJECT ----')" >> DONT-COMMIT-settings.gradle + echo " dependency.useTarget targetProject" >> DONT-COMMIT-settings.gradle + echo " }" >> DONT-COMMIT-settings.gradle + echo " }" >> DONT-COMMIT-settings.gradle + echo " }" >> DONT-COMMIT-settings.gradle + echo " }" >> DONT-COMMIT-settings.gradle + echo "}" >> DONT-COMMIT-settings.gradle + rm -rfv .gradle + ./configure.sh + ./gradlew --no-daemon dependencies + + - name: Build node + run: | + ./gradlew --no-daemon --stacktrace clean build -x test + + - name: Persist Build files + uses: actions/upload-artifact@v4 + with: + name: build_files + path: | + ./ + !rskj + + federator-tests: + runs-on: ubuntu-latest + container: openjdk:8-jdk + needs: build_federator_node + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Download Build files + uses: actions/download-artifact@v4 + with: + name: build_files + path: ./ + + + - name: Download rskj + uses: actions/download-artifact@v4 + with: + name: rskj + path: rskj + + - name: Perform federator tests + run: | + ./gradlew --no-daemon --stacktrace test + + sonarqube: + runs-on: ubuntu-latest + needs: build_federator_node + steps: + - name: Setup Java JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Download Build files + uses: actions/download-artifact@v4 + with: + name: build_files + path: ./ + + - name: Unpack build files + run: | + tar -xvf build_files.tar + + - name: Run SonarQube analysis for PRs + if: github.event_name == 'pull_request' + run: | + EXTRA_FLAGS="-Dsonar.pullrequest.base=master + -Dsonar.pullrequest.branch=${{ github.head_ref }} + -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}" + echo EXTRA_FLAGS="$EXTRA_FLAGS" >> $GITHUB_ENV + + - name: Run SonarQube analysis for push + if: github.event_name == 'push' + run: | + echo EXTRA_FLAGS="-Dsonar.branch.name=${{ github.ref }}" + + - name: Run SonarQube analysis + run: | + extra_flags="{{ env.EXTRA_FLAGS }}" + echo "Running sonarqube with $extra_flags" + ./gradlew sonarqube --warning-mode all --no-daemon --stacktrace --info -x build -x test \ + $extra_flags + -Dsonar.organization=rsksmart \ + -Dsonar.projectKey="powpeg-node" \ + -Dsonar.host.url="https://sonarcloud.io" \ + -Dsonar.login="$SONAR_TOKEN" + + # - name: Sonarquebe for PRs + # if: github.event_name == 'pull_request' + # run: | + # ./gradlew sonarqube --warning-mode all --no-daemon --stacktrace --info -x build -x test \ + # -Dsonar.pullrequest.base="${{ github.base_ref }}" \ + # -Dsonar.pullrequest.branch="${{ github.head_ref }}" \ + # -Dsonar.pullrequest.key="${{ github.event.pull_request.number }}" + # -Dsonar.organization=rsksmart \ + # -Dsonar.host.url="https://sonarcloud.io" \ + # -Dsonar.token="${{ secrets.SONAR_TOKEN }}" + # + # - name: Sonarquebe for master and rc branches + # if: github.event_name != 'pull_request' + # run: | + # ./gradlew sonarqube --warning-mode all --no-daemon --stacktrace --info -x build -x test \ + # -Dsonar.branch.name="${{ github.ref }}" \ + # -Dsonar.organization=rsksmart \ + # -Dsonar.host.url="https://sonarcloud.io" \ + # -Dsonar.token="${{ secrets.SONAR_TOKEN }}" + # diff --git a/build.gradle b/build.gradle index ea6536468..b686ad9f0 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,16 @@ repositories { } } +sonarqube { + properties { + property "sonar.java.binaries", "build/classes/java/main" + property "sonar.scm.provider", "git" + property "sonar.projectBaseDir", project.projectDir + property "sonar.projectKey", "powpeg-node" + property "sonar.organization", "rsksmart" + } +} + sourceCompatibility = 1.8 mainClassName = 'co.rsk.federate.FederateRunner' @@ -189,3 +199,4 @@ static def amendPathIfNeeded(details) { details.path = newPath } } +