diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml new file mode 100644 index 00000000000..c4ed9a772be --- /dev/null +++ b/.github/workflows/build_and_test.yml @@ -0,0 +1,120 @@ +name: Build and Test + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + container: + image: eclipse-temurin:17-jdk + env: + _JAVA_OPTIONS: "-Xmx3G -Xms2G" + steps: + - uses: actions/checkout@v2 + + - name: Install Node.js + run: | + curl -fsSL https://deb.nodesource.com/setup_21.x | bash - + apt-get install -y nodejs + - name: Check Node.js version + run: node --version + + - name: Cache Gradle packages + uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - name: Setup + run: | + apt update -y && apt install -y gnupg2 + + - name: Verify files + run: | + curl -sSL https://secchannel.rsk.co/SUPPORT.asc | gpg2 --import - + gpg2 --verify SHA256SUMS.asc && sha256sum --check SHA256SUMS.asc + + - name: Build + run: | + ./configure.sh + ./gradlew --no-daemon dependencies + ./gradlew --no-daemon --stacktrace build -x test + + - name: Persist workspace + uses: actions/upload-artifact@v3 + with: + name: workspace + path: . + + sonarqube: + needs: build + runs-on: ubuntu-latest + container: + image: eclipse-temurin:17-jdk + steps: + - uses: actions/checkout@v2 + - name: Run SonarQube analysis + env: + SONAR_URL: ${{ secrets.SONAR_URL }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + run: | + apt-get update && apt-get install -yqq git + extra_flags="" + if [ "${{ github.event_name }}" == "pull_request" ]; then + git branch -f master origin/master + 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 + extra_flags="-Dsonar.branch.name=master" + fi + ./gradlew sonarqube --no-daemon -x build -x test $extra_flags + + unit-tests: + needs: build + runs-on: ubuntu-latest + container: + image: eclipse-temurin:17-jdk + steps: + - uses: actions/checkout@v2 + + - name: Install Node.js + run: | + curl -fsSL https://deb.nodesource.com/setup_21.x | bash - + apt-get install -y nodejs + - name: Check Node.js version + run: node --version + + - uses: actions/cache@v3 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + ${{ runner.os }}-gradle- + + - uses: actions/download-artifact@v3 + with: + name: workspace + path: . + - name: Run unit tests + run: | + ./gradlew --no-daemon --stacktrace test + + - name: Save test results + run: | + mkdir -p ${{ github.workspace }}/junit/ + find rskj-core/build/test-results -type f -name "*.xml" \ + -exec cp {} ${{ github.workspace }}/junit/ \; + if: always() + + - uses: actions/upload-artifact@v3 + with: + name: junit-results + path: ${{ github.workspace }}/junit/