diff --git a/.github/build-steps/build.sh b/.github/build-steps/build.sh new file mode 100755 index 00000000..dc35247b --- /dev/null +++ b/.github/build-steps/build.sh @@ -0,0 +1,26 @@ +#!/bin/bash +set -e +CUSTOM_BUILD_SCRIPT=${CUSTOM_BUILD_SCRIPT:-.github/scripts/build} +if [ -x $CUSTOM_BUILD_SCRIPT ]; then + echo 'Detected custom build instructions' + $CUSTOM_BUILD_SCRIPT +elif [ -x 'gradlew' ]; then + echo 'Detected gradle wrapper, checking for known tasks' + if ./gradlew tasks | grep '^assemble\s'; then + echo 'Detected assemble task' + ./gradlew assemble --parallel + elif ./gradlew tasks | grep '^build\s'; then + echo 'Detected build task' + ./gradlew build --parallel + else + echo 'No known tasks, fall back to the default tasks' + ./gradlew + fi +elif [ -f 'pom.xml' ]; then + echo 'Detected Maven pom.xml, running mvn package' + mvn package -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn +else + echo 'No valid configuration detected, failing' + echo "To fix, provide an *executable* build script in $CUSTOM_BUILD_SCRIPT" + exit 1 +fi diff --git a/.github/build-steps/check.sh b/.github/build-steps/check.sh new file mode 100755 index 00000000..743683d1 --- /dev/null +++ b/.github/build-steps/check.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -e +CUSTOM_BUILD_SCRIPT=${CUSTOM_BUILD_SCRIPT:-.github/scripts/check} +if [ -x $CUSTOM_BUILD_SCRIPT ]; then + echo 'Detected custom check instructions' + $CUSTOM_BUILD_SCRIPT +elif [ -x 'gradlew' ]; then + echo 'Detected gradle wrapper, checking for known tasks' + if ./gradlew tasks | grep '^check\s'; then + echo 'Detected check task' + ./gradlew check --parallel + if ./gradlew tasks | grep '^jacocoTestReport\s'; then + ./gradlew jacocoTestReport --parallel + fi + else + echo 'No known check tasks' + fi +else + echo 'No valid configuration detected, skipping checks' + echo "To fix, provide an *executable* build script in $CUSTOM_BUILD_SCRIPT" +fi diff --git a/.github/build-steps/compatibility_check.sh b/.github/build-steps/compatibility_check.sh new file mode 100755 index 00000000..8b8e85e3 --- /dev/null +++ b/.github/build-steps/compatibility_check.sh @@ -0,0 +1,11 @@ +#!/bin/bash +if [ -x .github/scripts/compatibility_check ]; then + .github/scripts/compatibility_check +else + COMPATIBLE=true + echo "COMPATIBLE=$COMPATIBLE" + echo "COMPATIBLE=$COMPATIBLE" >> $GITHUB_ENV + REFERENCE=$([ "$OS" = 'ubuntu' ] && [ "$JAVA_VERSION" = 8 ] && echo 'true' || echo 'false') + echo "REFERENCE=$REFERENCE" + echo "REFERENCE=$REFERENCE" >> $GITHUB_ENV +fi diff --git a/.github/build-steps/deploy.sh b/.github/build-steps/deploy.sh new file mode 100755 index 00000000..7782f33e --- /dev/null +++ b/.github/build-steps/deploy.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e +CUSTOM_BUILD_SCRIPT=${CUSTOM_BUILD_SCRIPT:-.github/scripts/deploy} +if [ -x $CUSTOM_BUILD_SCRIPT ]; then + echo 'Detected custom deploy instructions' + $CUSTOM_BUILD_SCRIPT +elif [ -x 'gradlew' ]; then + echo 'Detected gradle wrapper, checking for known tasks' + if ./gradlew tasks | grep '^deploy\s'; then + echo 'Detected deploy task' + ./gradlew deploy --parallel + elif ./gradlew tasks | grep '^publish\s'; then + echo 'Detected publish task' + ./gradlew publish --parallel + else + echo 'No deploy task' + fi +elif [ -f 'pom.xml' ]; then + echo 'Detected Maven pom.xml, running mvn deploy' + mvn deploy -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn +else + echo 'No valid configuration detected, failing' + echo "To fix, provide an *executable* build script in $CUSTOM_BUILD_SCRIPT" + exit 1 +fi diff --git a/.github/scripts/compatibility_check b/.github/scripts/compatibility_check new file mode 100755 index 00000000..685b4c70 --- /dev/null +++ b/.github/scripts/compatibility_check @@ -0,0 +1,7 @@ +#!/bin/bash +COMPATIBLE=$([ "$JAVA_VERSION" -ge 11 ] && echo 'true' || echo 'false') +echo "COMPATIBLE=$COMPATIBLE" +echo "COMPATIBLE=$COMPATIBLE" >> $GITHUB_ENV +REFERENCE=$([ "$OS" = 'ubuntu' ] && [ "$JAVA_VERSION" = 11 ] && echo 'true' || echo 'false') +echo "REFERENCE=$REFERENCE" +echo "REFERENCE=$REFERENCE" >> $GITHUB_ENV diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 00000000..7fb1bab9 --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,143 @@ +name: CI +on: + push: + schedule: + - cron: '0 3 * * SUN' + +jobs: + Build: + strategy: + matrix: + os: [windows, macos, ubuntu] + jvm_version: [8, 11, 14] + runs-on: ${{ matrix.os }}-latest + env: + JAVA_VERSION: ${{ matrix.jvm_version }} + OS: ${{ matrix.os }} + TERM: dumb + steps: + # Checkout the repository + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + - name: Fetch tags + shell: bash + run: git fetch --tags -f + - name: Populate TAG and BRANCH environment variables + shell: bash + run: | + TAG=$(git describe --tags --exact-match HEAD || echo '') + echo "Current tag is: '$TAG' (setup in the TAG environment variable)" + echo "TAG=$TAG" >> $GITHUB_ENV + BRANCH=$([ -z "$TAG" ] && echo ${GITHUB_REF#refs/heads/} || echo $TAG) + echo "Current tag is: '$BRANCH' (setup in BRANCH TAG environment variable)" + echo "BRANCH=$BRANCH" >> $GITHUB_ENV + # Check if the configuration is supported + # COMPATIBLE means the build can run on this matrix combination + # REFERENCE means this is the combination that produces the reference artifacts + # (hence, artifacts from REFERENCE configuration shall be deployed) + # Only one matrix entry should be REFERENCE=true + # If REFERENCE=true, then also COMPATIBLE=true + - shell: bash + run: .github/build-steps/compatibility_check.sh + # Install the JDK + - uses: joschi/setup-jdk@v2.3.0 + if: ${{ env.COMPATIBLE == 'true' }} + with: + java-version: ${{ matrix.jvm_version }} + server-id: ossrh + server-username: MAVEN_CENTRAL_USERNAME + server-password: MAVEN_CENTRAL_PASSWORD + gpg-private-key: ${{ secrets.SIGNING_KEY }} + gpg-passphrase: SIGNING_PASSWORD + # Install additional packages + - name: Configure Linux + shell: bash + if: ${{ env.COMPATIBLE == 'true' && contains(matrix.os, 'ubuntu') }} + run: | + if [ -x .github/scripts/configure_linux ]; then + .github/scripts/configure_linux + fi + - name: Configure MacOS X + shell: bash + if: ${{ env.COMPATIBLE == 'true' && contains(matrix.os, 'macos') }} + run: | + if [ -f .github/scripts/configure_macos ]; then + .github/scripts/configure_macos + fi + - name: Configure the Windows Pagefile + if: ${{ env.COMPATIBLE == 'true' && contains(matrix.os, 'windows') }} + uses: al-cheb/configure-pagefile-action@v1.2 + - name: Configure Windows + shell: bash + if: ${{ env.COMPATIBLE == 'true' && contains(matrix.os, 'windows') }} + run: | + if [ -f .github/scripts/configure_windows ]; then + .github/scripts/configure_windows + fi + - name: Build + if: ${{ env.COMPATIBLE == 'true' }} + shell: bash + run: .github/build-steps/build.sh || .github/build-steps/build.sh + - name: Check + if: ${{ env.COMPATIBLE == 'true' }} + shell: bash + run: .github/build-steps/check.sh || .github/build-steps/check.sh + - name: CodeCov + if: ${{ env.REFERENCE == 'true' }} + uses: codecov/codecov-action@v1 + - name: Deploy + if: ${{ env.REFERENCE == 'true' }} + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + githubToken: ${{ secrets.AUTOMERGE_TOKEN }} + GRADLE_PUBLISH_SECRET: ${{ secrets.GRADLE_PUBLISH_SECRET }} + GRADLE_PUBLISH_KEY: ${{ secrets.GRADLE_PUBLISH_KEY }} + MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + MAVEN_CENTRAL_USERNAME: danysk + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SURGE_LOGIN: ${{ secrets.SURGE_LOGIN }} + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + run: .github/build-steps/deploy.sh || .github/build-steps/deploy.sh + Build-Success: + runs-on: ubuntu-latest + needs: Build + steps: + - shell: bash + run: touch ok + - uses: actions/upload-artifact@v2 + with: + name: success + path: ok + CI-Complete: + needs: Build-Success + if: always() + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v2 + with: + name: success + - shell: bash + run: '[ -f ok ]' + Automerge: + needs: CI-Complete + runs-on: ubuntu-latest + if: always() + steps: + - name: automerge + uses: "DanySK/yaagha@master" + env: + GITHUB_TOKEN: "${{ secrets.AUTOMERGE_TOKEN }}" + MERGE_FORKS: "false" + MERGE_LABELS: "version-upgrade" + BLOCK_LABELS: "blocked, wontfix, invalid" + MERGE_METHOD: "rebase" + CLOSE_ON_CONFLICT: "true" + DELETE_BRANCH_ON_CLOSE: "true" + GIT_USER_NAME: "Danilo Pianini" + GIT_USER_EMAIL: "danilo.pianini@gmail.com" diff --git a/.github/workflows/build-external-pull-requests.yml b/.github/workflows/build-external-pull-requests.yml new file mode 100644 index 00000000..2ca429a2 --- /dev/null +++ b/.github/workflows/build-external-pull-requests.yml @@ -0,0 +1,83 @@ +name: Pull Request CI +on: + pull_request: + +jobs: + Build-Foreign-Pull-Request: + if: ${{ github.event.pull_request.head.repo.full_name != github.repository }} + strategy: + matrix: + os: [windows, macos, ubuntu] + jvm_version: [8, 11, 14] + runs-on: ${{ matrix.os }}-latest + env: + JAVA_VERSION: ${{ matrix.jvm_version }} + OS: ${{ matrix.os }} + TERM: dumb + steps: + # Checkout the repository + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + submodules: recursive + - name: Fetch tags + shell: bash + run: git fetch --tags -f + - name: Populate TAG and BRANCH environment variables + shell: bash + run: | + TAG=$(git describe --tags --exact-match HEAD || echo '') + echo "Current tag is: '$TAG' (setup in the TAG environment variable)" + echo "TAG=$TAG" >> $GITHUB_ENV + BRANCH=$([ -z "$TAG" ] && echo ${GITHUB_REF#refs/heads/} || echo $TAG) + echo "Current tag is: '$BRANCH' (setup in BRANCH TAG environment variable)" + echo "BRANCH=$BRANCH" >> $GITHUB_ENV + # Check if the configuration is supported + # COMPATIBLE means the build can run on this matrix combination + # REFERENCE means this is the combination that produces the reference artifacts + # (hence, artifacts from REFERENCE configuration shall be deployed) + # Only one matrix entry should be REFERENCE=true + # If REFERENCE=true, then also COMPATIBLE=true + - shell: bash + run: .github/build-steps/compatibility_check.sh + # Install the JDK + - uses: joschi/setup-jdk@v2.3.0 + if: ${{ env.COMPATIBLE }} + with: + java-version: ${{ matrix.jvm_version }} + # Install additional packages + - name: Configure Linux + shell: bash + if: ${{ env.COMPATIBLE && contains(matrix.os, 'ubuntu') }} + run: | + if [ -x .github/scripts/configure_linux ]; then + .github/scripts/configure_linux + fi + - name: Configure MacOS X + shell: bash + if: ${{ env.COMPATIBLE && contains(matrix.os, 'macos') }} + run: | + if [ -f .github/scripts/configure_macos ]; then + .github/scripts/configure_macos + fi + - name: Configure the Windows Pagefile + if: ${{ env.COMPATIBLE == 'true' && contains(matrix.os, 'windows') }} + uses: al-cheb/configure-pagefile-action@v1.2 + - name: Configure Windows + shell: bash + if: ${{ env.COMPATIBLE && contains(matrix.os, 'windows') }} + run: | + if [ -f .github/scripts/configure_windows ]; then + .github/scripts/configure_windows + fi + - name: Build + if: ${{ env.COMPATIBLE == 'true' }} + shell: bash + run: .github/build-steps/build.sh + - name: Check + if: ${{ env.COMPATIBLE == 'true' }} + shell: bash + run: .github/build-steps/check.sh + - name: CodeCov + if: ${{ env.REFERENCE == 'true' }} + uses: codecov/codecov-action@v1