diff --git a/.ci/README.md b/.ci/README.md index 20302d08ea..96d6091bd4 100644 --- a/.ci/README.md +++ b/.ci/README.md @@ -9,10 +9,17 @@ for a ssh key, which is used to copy files to sourceforge. ## Environment variables -* `PMD_CI_SECRET_PASSPHRASE` -* `CI_DEPLOY_PASSWORD` -* `CI_SIGN_PASSPHRASE` -* ... +* PMD_CI_SECRET_PASSPHRASE +* CI_DEPLOY_USER +* CI_DEPLOY_PASSWORD +* CI_SIGN_KEY +* CI_SIGN_PASSPHRASE +* PMD_SF_USER +* PMD_SF_APIKEY +* GITHUB_OAUTH_TOKEN +* GITHUB_BASE_URL +* DANGER_GITHUB_API_TOKEN +* PMD_CI_CHUNK_TOKEN ## Encrypting diff --git a/.ci/build-pr.sh b/.ci/build-pr.sh new file mode 100755 index 0000000000..2d44e5a4f0 --- /dev/null +++ b/.ci/build-pr.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +source $(dirname $0)/inc/logger.inc +source $(dirname $0)/inc/setup-secrets.inc +source $(dirname $0)/inc/regression-tester.inc +source ${HOME}/java.env + +set -e +#set -x + +./mvnw -e -Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -V clean verify + +# Danger is executed only on the linux runner +case "$(uname)" in + Linux*) + log_info "Executing danger..." + pmd_ci_setup_env + regression_tester_setup_ci + regression_tester_executeDanger + ;; +esac diff --git a/.ci/build.sh b/.ci/build.sh index 2b4413b156..7148a73949 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -31,7 +31,7 @@ function pmd_ci_build_main() { pmd_ci_build_and_upload_doc - pmd_ci_build_setup_regression_tester + regression_tester_setup_ci regression_tester_uploadBaseline exit 0 @@ -95,15 +95,7 @@ function pmd_ci_build_run() { ./mvnw deploy -Possrh,sign,generate-rule-docs $MVN_BUILD_FLAGS } -function pmd_ci_build_setup_regression_tester() { - # install openjdk8 for pmd-regression-tests - .ci/install-openjdk.sh 8 - rm -f .bundle/config - bundle config set --local path vendor/bundle - bundle config set --local with release_notes_preprocessing - bundle install -} - +# Needed for doc generation and regression tester function pmd_ci_build_setup_bundler() { log_info "Installing bundler..." gem install bundler diff --git a/.ci/files/env.gpg b/.ci/files/env.gpg index 07dd553e73..d379ecefe2 100644 Binary files a/.ci/files/env.gpg and b/.ci/files/env.gpg differ diff --git a/.ci/inc/regression-tester.inc b/.ci/inc/regression-tester.inc index 7a509ae1d7..9b66372071 100644 --- a/.ci/inc/regression-tester.inc +++ b/.ci/inc/regression-tester.inc @@ -6,6 +6,23 @@ # PMD_SF_USER # PMD_CI_BRANCH +function regression_tester_setup_ci() { + # install openjdk8 for pmd-regression-tests + .ci/install-openjdk.sh 8 + + if hash "bundler" 2>/dev/null; then + log_debug "Bundler is already installed" + else + log_info "Installing bundler..." + gem install bundler + fi + + rm -f .bundle/config + bundle config set --local path vendor/bundle + bundle config set --local with release_notes_preprocessing + bundle install +} + # # Generate a new baseline and upload it to sourceforge # @@ -58,7 +75,6 @@ function regression_tester_uploadBaseline() { # In that case, just a error logging is provided. # function regression_tester_executeDanger() { - change_ruby_version log_debug "$FUNCNAME" local errexitstate="$(shopt -po errexit)" @@ -73,6 +89,10 @@ function regression_tester_executeDanger() { set -e trap danger_failed ERR + PMD_CI_BRANCH=${PMD_CI_BRANCH##refs/heads/} + export PMD_CI_BRANCH + log_debug "Using modified branch name: ${PMD_CI_BRANCH}" + # Create a corresponding remote branch locally if ! git show-ref --verify --quiet refs/heads/${PMD_CI_BRANCH}; then git fetch --no-tags origin +refs/heads/${PMD_CI_BRANCH}:refs/remotes/origin/${PMD_CI_BRANCH} diff --git a/.github/workflows/pull-requests.yml b/.github/workflows/pull-requests.yml index 023f1ac239..26109a0253 100644 --- a/.github/workflows/pull-requests.yml +++ b/.github/workflows/pull-requests.yml @@ -21,15 +21,17 @@ jobs: key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}- + - name: Set up Ruby 2.7 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.7 - name: Install OpenJDK 11 run: .ci/install-openjdk.sh 11 shell: bash - - name: Build with mvnw - run: | - source ${HOME}/java.env - ./mvnw -e -Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -V clean install - shell: bash - - name: Execute Danger - if: ${{ runner.os == 'Linux' }} - run: echo "TODO" + - name: Build + run: .ci/build-pr.sh shell: bash + env: + PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }} + PMD_CI_BRANCH: ${{ github.ref }} + PMD_CI_PULL_REQUEST_NUMBER: ${{ github.event.number }} diff --git a/Dangerfile b/Dangerfile index f57f762c11..f26f7a528e 100644 --- a/Dangerfile +++ b/Dangerfile @@ -7,10 +7,10 @@ require 'logger' def run_pmdtester Dir.chdir('..') do argv = ['--local-git-repo', './pmd', - '--list-of-project', './pmd/.travis/project-list.xml', - '--base-branch', "#{ENV['TRAVIS_BRANCH']}", + '--list-of-project', './pmd/.ci/files/project-list.xml', + '--base-branch', "#{ENV['PMD_CI_BRANCH']}", '--patch-branch', 'HEAD', - '--patch-config', './pmd/.travis/all-java.xml', + '--patch-config', './pmd/.ci/files/all-java.xml', '--mode', 'online', '--auto-gen-config', # '--debug', @@ -28,14 +28,14 @@ end def upload_report Dir.chdir('target/reports') do - tar_filename = "pr-#{ENV['TRAVIS_PULL_REQUEST']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar" + tar_filename = "pr-#{ENV['PMD_CI_PULL_REQUEST_NUMBER']}-diff-report-#{Time.now.strftime("%Y-%m-%dT%H-%M-%SZ")}.tar" unless Dir.exist?('diff/') message("No java rules are changed!", sticky: true) return end `tar -cf #{tar_filename} diff/` - report_url = `curl -u #{ENV['CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io` + report_url = `curl -u #{ENV['PMD_CI_CHUNK_TOKEN']} -T #{tar_filename} https://chunk.io` if $?.success? @logger.info "Successfully uploaded #{tar_filename} to chunk.io" @@ -53,11 +53,6 @@ def upload_report end # Perform regression testing -can_merge = github.pr_json['mergeable'] -if can_merge - run_pmdtester -else - warn("This PR cannot be merged yet.", sticky: false) -end +run_pmdtester # vim: syntax=ruby