From da71bdb035e81a5d29454355d90fb1823bbc20ea Mon Sep 17 00:00:00 2001 From: MajoBerger Date: Thu, 7 Apr 2022 16:08:59 +0200 Subject: [PATCH] Separated push and pull_request actions --- .github/workflows/build.yml | 6 ++- .github/workflows/push.yml | 85 +++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 045944804520..4936720e0f5c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,12 @@ # DSpace Continuous Integration/Build via GitHub Actions # Concepts borrowed from # https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-java-with-maven -name: Build +name: Build on pull_request # Run this Build for all pushes / PRs to current branch -on: [push, pull_request] +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] jobs: tests: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 000000000000..ea09844dbed5 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,85 @@ +# DSpace Continuous Integration/Build via GitHub Actions +# Concepts borrowed from +# https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-java-with-maven +name: Build on push + +# Run this Build for all pushes / PRs to current branch +on: [push] + +jobs: + tests: + runs-on: ubuntu-latest + env: + # Give Maven 1GB of memory to work with + # Suppress all Maven "downloading" messages in logs (see https://stackoverflow.com/a/35653426) + # This also slightly speeds builds, as there is less logging + MAVEN_OPTS: "-Xmx1024M -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn" + strategy: + # Create a matrix of two separate configurations for Unit vs Integration Tests + # This will ensure those tasks are run in parallel + # Also specify version of Java to use (this can allow us to optionally run tests on multiple JDKs in future) + matrix: + include: + # NOTE: Unit Tests include deprecated REST API v6 (as it has unit tests) + # - surefire.rerunFailingTestsCount => try again for flakey tests, and keep track of/report on number of retries + - type: "Unit Tests" + java: 11 + mvnflags: "-DskipUnitTests=false -Pdspace-rest -Dsurefire.rerunFailingTestsCount=2" + resultsdir: "**/target/surefire-reports/**" + # NOTE: ITs skip all code validation checks, as they are already done by Unit Test job. + # - enforcer.skip => Skip maven-enforcer-plugin rules + # - checkstyle.skip => Skip all checkstyle checks by maven-checkstyle-plugin + # - license.skip => Skip all license header checks by license-maven-plugin + # - xml.skip => Skip all XML/XSLT validation by xml-maven-plugin + # - failsafe.rerunFailingTestsCount => try again for flakey tests, and keep track of/report on number of retries + - type: "Integration Tests" + java: 11 + mvnflags: "-DskipIntegrationTests=false -Denforcer.skip=true -Dcheckstyle.skip=true -Dlicense.skip=true -Dxml.skip=true -Dfailsafe.rerunFailingTestsCount=2" + resultsdir: "**/target/failsafe-reports/**" + # Do NOT exit immediately if one matrix job fails + # This ensures ITs continue running even if Unit Tests fail, or visa versa + fail-fast: false + name: Run ${{ matrix.type }} + # These are the actual CI steps to perform per job + steps: + # https://github.com/actions/checkout + - name: Checkout codebase + uses: actions/checkout@v2 + + # https://github.com/actions/setup-java + - name: Install JDK ${{ matrix.java }} + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + + # https://github.com/actions/cache + - name: Cache Maven dependencies + uses: actions/cache@v2 + with: + # Cache entire ~/.m2/repository + path: ~/.m2/repository + # Cache key is hash of all pom.xml files. Therefore any changes to POMs will invalidate cache + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-maven- + + # Run parallel Maven builds based on the above 'strategy.matrix' + - name: Run Maven ${{ matrix.type }} + env: + TEST_FLAGS: ${{ matrix.mvnflags }} + run: mvn install -B -V -P-assembly -Pcoverage-report $TEST_FLAGS + + # If previous step failed, save results of tests to downloadable artifact for this job + # (This artifact is downloadable at the bottom of any job's summary page) + - name: Upload Results of ${{ matrix.type }} to Artifact + if: ${{ failure() }} + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.type }} results + path: ${{ matrix.resultsdir }} + + # https://github.com/codecov/codecov-action + - name: Upload coverage to Codecov.io + uses: codecov/codecov-action@v2 + with: + token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos