diff --git a/.ci/build.sh b/.ci/build.sh index 08ff81ddf1..fd073f04c3 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -1,66 +1,88 @@ #!/usr/bin/env bash -source $(dirname $0)/inc/logger.inc -source $(dirname $0)/inc/setup-secrets.inc -source $(dirname $0)/inc/sourceforge-api.inc -source $(dirname $0)/inc/pmd-doc.inc -source $(dirname $0)/inc/pmd-code-api.inc -source $(dirname $0)/inc/regression-tester.inc -source $(dirname $0)/inc/github-releases-api.inc -source $(dirname $0)/inc/install-openjdk.inc - +# Exit this script immediately if a command/function exits with a non-zero status. set -e -function pmd_ci_build_main() { - log_group_start "Setting up private secrets" - pmd_ci_setup_private_env - pmd_ci_setup_gpg_key - pmd_ci_setup_ssh - log_group_end +SCRIPT_INCLUDES="log.bash utils.bash setup-secrets.bash openjdk.bash maven.bash github-releases-api.bash + sourceforge-api.bash pmd-doc.inc pmd-code-api.inc regression-tester.inc" +# shellcheck source=inc/fetch_ci_scripts.bash +source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts - log_group_start "Prepare Java 7+11, Maven, Bundler" - install_openjdk_setdefault 11 - install_oraclejdk7 - pmd_ci_build_setup_maven +function build() { + pmd_ci_log_group_start "Prepare Java 7+11, Bundler" + pmd_ci_openjdk_install_adoptopenjdk 11 + pmd_ci_openjdk_setdefault 11 + PMD_MAVEN_EXTRA_OPTS="" + if [ "$(pmd_ci_utils_get_os)" = "linux" ]; then + log_info "Install openjdk7 for integration tests" + pmd_ci_openjdk_install_zuluopenjdk 7 + PMD_MAVEN_EXTRA_OPTS="-Djava7.home=${HOME}/oraclejdk7" + fi pmd_ci_build_setup_bundler - pmd_ci_build_setup_env - log_group_end + pmd_ci_log_group_end - log_group_start "Build and Deploy" - pmd_ci_build_run - pmd_ci_deploy_build_artifacts - log_group_end + echo + pmd_ci_maven_display_info_banner + pmd_ci_utils_determine_build_env pmd/pmd + echo - log_group_start "Build and Upload documentation" - pmd_ci_build_and_upload_doc - log_group_end + if pmd_ci_utils_is_fork_or_pull_request; then + pmd_ci_log_group_start "Build with mvnw" + ./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS} + pmd_ci_log_group_end - if pmd_ci_build_isRelease; then - log_group_start "Publishing Release" - gh_release_publishRelease "$GH_RELEASE" - sourceforge_selectDefault "${VERSION}" - log_group_end + # Danger is executed only on the linux runner + if [ "$(pmd_ci_utils_get_os)" = "linux" ]; then + pmd_ci_log_group_start "Executing danger" + regression_tester_setup_ci + regression_tester_executeDanger + pmd_ci_log_group_end + fi + + exit 0 fi - log_group_start "Creating new baseline for regression tester" + + if [ "$(pmd_ci_utils_get_os)" != "linux" ]; then + pmd_ci_log_group_start "Build with mvnw" + ./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS} + pmd_ci_log_group_end + + pmd_ci_log_info "Stopping build here, because os is not linux" + exit 0 + fi + + # only builds on pmd/pmd continue here + pmd_ci_log_group_start "Setup environment" + pmd_ci_setup_secrets_private_env + pmd_ci_setup_secrets_gpg_key + pmd_ci_setup_secrets_ssh + pmd_ci_maven_setup_settings + pmd_ci_log_group_end + + pmd_ci_log_group_start "Build and Deploy" + pmd_ci_build_run + pmd_ci_deploy_build_artifacts + pmd_ci_log_group_end + + pmd_ci_log_group_start "Build and Upload documentation" + pmd_ci_build_and_upload_doc + pmd_ci_log_group_end + + if pmd_ci_maven_isReleaseBuild; then + pmd_ci_log_group_start "Publishing Release" + pmd_ci_gh_releases_publishRelease "$GH_RELEASE" + pmd_ci_sourceforge_selectDefault "${PMD_CI_MAVEN_PROJECT_VERSION}" + pmd_ci_log_group_end + fi + + pmd_ci_log_group_start "Creating new baseline for regression tester" regression_tester_setup_ci regression_tester_uploadBaseline - log_group_end - - exit 0 + pmd_ci_log_group_end } -# -# Configures maven. -# Needed for deploy to central (both snapshots and releases) -# and for signing the artifacts. -# -function pmd_ci_build_setup_maven() { - mkdir -p ${HOME}/.m2 - cp .ci/files/maven-settings.xml ${HOME}/.m2/settings.xml -} - # # Installs bundler, which is needed for doc generation and regression tester # @@ -69,54 +91,22 @@ function pmd_ci_build_setup_bundler() { gem install bundler } -# -# Setups common build parameters: -# * Determines the VERSION of PMD, that is being built -# * Determines the PMD_CI_BRANCH or PMD_CI_TAG, that is being built -# -function pmd_ci_build_setup_env() { - VERSION=$(pmd_ci_build_get_pom_version) - - if [[ "${PMD_CI_GIT_REF}" == refs/heads/* ]]; then - PMD_CI_BRANCH=${PMD_CI_GIT_REF##refs/heads/} - unset PMD_CI_TAG - log_info "Building PMD ${VERSION} on branch ${PMD_CI_BRANCH}" - elif [[ "${PMD_CI_GIT_REF}" == refs/tags/* ]]; then - unset PMD_CI_BRANCH - PMD_CI_TAG=${PMD_CI_GIT_REF##refs/tags/} - log_info "Building PMD ${VERSION} on tag ${PMD_CI_TAG}" - else - log_error "Unknown branch/tag: PMD_CI_GIT_REF=${PMD_CI_GIT_REF}" - exit 1 - fi - - if [[ "${VERSION}" == *-SNAPSHOT && -z "$PMD_CI_BRANCH" ]]; then - log_error "Invalid combination: snapshot version ${VERSION} but no branch in PMD_CI_GIT_REF=${PMD_CI_GIT_REF}" - exit 1 - fi - - if [[ "${VERSION}" != *-SNAPSHOT && -z "$PMD_CI_TAG" ]]; then - log_error "Invalid combination: non-snapshot version ${VERSION} but no tag in PMD_CI_GIT_REF=${PMD_CI_GIT_REF}" - exit 1 - fi -} - # # Performs the actual build. # Deploys the artifacts to maven central. # Also generates rule documentation. # function pmd_ci_build_run() { - local mvn_profiles="ossrh,sign,generate-rule-docs" + local mvn_profiles="sign,generate-rule-docs" - if pmd_ci_build_isRelease; then - log_info "This is a release build" + if pmd_ci_maven_isReleaseBuild; then + pmd_ci_log_info "This is a release build" mvn_profiles="${mvn_profiles},pmd-release" else - log_info "This is a snapshot build" + pmd_ci_log_info "This is a snapshot build" fi - ./mvnw clean deploy -P${mvn_profiles} -e -B -V -Djava7.home=${HOME}/oraclejdk7 + ./mvnw clean deploy -P${mvn_profiles} --show-version --errors --batch-mode --no-transfer-progress ${PMD_MAVEN_EXTRA_OPTS} } # @@ -124,17 +114,17 @@ function pmd_ci_build_run() { # function pmd_ci_deploy_build_artifacts() { # Deploy to sourceforge files - sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-bin-${VERSION}.zip" - sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-src-${VERSION}.zip" + pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" + pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" - if pmd_ci_build_isRelease; then + if pmd_ci_maven_isReleaseBuild; then # create a draft github release - gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 ${PMD_CI_TAG})" + pmd_ci_gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 ${PMD_CI_TAG})" GH_RELEASE="$RESULT" # Deploy to github releases - gh_release_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-bin-${VERSION}.zip" - gh_release_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-src-${VERSION}.zip" + pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-bin-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" + pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "pmd-dist/target/pmd-src-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" fi } @@ -145,35 +135,35 @@ function pmd_ci_build_and_upload_doc() { pmd_doc_generate_jekyll_site pmd_doc_create_archive - sourceforge_uploadFile "${VERSION}" "docs/pmd-doc-${VERSION}.zip" - if pmd_ci_build_isRelease; then - gh_release_uploadAsset "$GH_RELEASE" "docs/pmd-doc-${VERSION}.zip" + pmd_ci_sourceforge_uploadFile "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" + if pmd_ci_maven_isReleaseBuild; then + pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" fi - # Deploy doc to https://docs.pmd-code.org/pmd-doc-${VERSION}/ - pmd_code_uploadDocumentation "${VERSION}" "docs/pmd-doc-${VERSION}.zip" - # Deploy javadoc to https://docs.pmd-code.org/apidocs/*/${VERSION}/ - pmd_code_uploadJavadoc "${VERSION}" "$(pwd)" + # Deploy doc to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/ + pmd_code_uploadDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" + # Deploy javadoc to https://docs.pmd-code.org/apidocs/*/${PMD_CI_MAVEN_PROJECT_VERSION}/ + pmd_code_uploadJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}" "$(pwd)" - if [[ "${VERSION}" == *-SNAPSHOT && "${PMD_CI_BRANCH}" == "master" ]]; then + if [ pmd_ci_maven_isSnapshotBuild && "${PMD_CI_BRANCH}" = "master" ]; then # only for snapshot builds from branch master - pmd_code_createSymlink "${VERSION}" "snapshot" + pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "snapshot" # update github pages https://pmd.github.io/pmd/ pmd_doc_publish_to_github_pages # rsync site to https://pmd.sourceforge.io/snapshot - sourceforge_rsyncSnapshotDocumentation "${VERSION}" "snapshot" + pmd_ci_sourceforge_rsyncSnapshotDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "snapshot" fi - if pmd_ci_build_isRelease; then - # documentation is already uploaded to https://docs.pmd-code.org/pmd-doc-${VERSION} + if pmd_ci_maven_isReleaseBuild; then + # documentation is already uploaded to https://docs.pmd-code.org/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION} # we only need to setup symlinks for the released version - pmd_code_createSymlink "${VERSION}" "latest" + pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "latest" # remove old doc and point to the new version - pmd_code_removeDocumentation "${VERSION}-SNAPSHOT" - pmd_code_createSymlink "${VERSION}" "${VERSION}-SNAPSHOT" + pmd_code_removeDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT" + pmd_code_createSymlink "${PMD_CI_MAVEN_PROJECT_VERSION}" "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT" # remove old javadoc - pmd_code_removeJavadoc "${VERSION}-SNAPSHOT" + pmd_code_removeJavadoc "${PMD_CI_MAVEN_PROJECT_VERSION}-SNAPSHOT" # updating github release text rm -f .bundle/config @@ -182,28 +172,16 @@ function pmd_ci_build_and_upload_doc() { bundle install # renders, and skips the first 6 lines - the Jekyll front-matter local rendered_release_notes=$(bundle exec .ci/render_release_notes.rb docs/pages/release_notes.md | tail -n +6) - local release_name="PMD ${VERSION} ($(date -u +%d-%B-%Y))" - gh_release_updateRelease "$GH_RELEASE" "$release_name" "$rendered_release_notes" - sourceforge_uploadReleaseNotes "${VERSION}" "${rendered_release_notes}" + local release_name="PMD ${PMD_CI_MAVEN_PROJECT_VERSION} ($(date -u +%d-%B-%Y))" + pmd_ci_gh_releases_updateRelease "$GH_RELEASE" "$release_name" "$rendered_release_notes" + pmd_ci_sourceforge_uploadReleaseNotes "${PMD_CI_MAVEN_PROJECT_VERSION}" "${rendered_release_notes}" - # updates https://pmd.github.io/latest/ and https://pmd.github.io/pmd-${VERSION} + # updates https://pmd.github.io/latest/ and https://pmd.github.io/pmd-${PMD_CI_MAVEN_PROJECT_VERSION} publish_release_documentation_github - sourceforge_rsyncSnapshotDocumentation "${VERSION}" "pmd-${VERSION}" + pmd_ci_sourceforge_rsyncSnapshotDocumentation "${PMD_CI_MAVEN_PROJECT_VERSION}" "pmd-${PMD_CI_MAVEN_PROJECT_VERSION}" fi } +build -function pmd_ci_build_isRelease() { - if [[ "${VERSION}" != *-SNAPSHOT && -n "${PMD_CI_TAG}" && -z "${PMD_CI_BRANCH}" ]]; then - return 0 - else - return 1 - fi -} - -function pmd_ci_build_get_pom_version() { - echo $(./mvnw -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:3.0.0:exec) -} - - -pmd_ci_build_main +exit 0 diff --git a/.ci/check-environment.sh b/.ci/check-environment.sh deleted file mode 100755 index d164569a19..0000000000 --- a/.ci/check-environment.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -# -# This script should check, that all needed commands are available -# and are in the correct version. -# - -source $(dirname $0)/inc/logger.inc - -set -e - -function check() { - local CMD=$1 - local VERSION_CMD=$2 - local VERSION_STRING=$3 - - echo -n "Checking ${CMD}..." - - if hash "$CMD" 2>/dev/null; then - local VERSION_FULL=$(${VERSION_CMD} 2>&1) - local VERSION=$(echo "${VERSION_FULL}" | grep "${VERSION_STRING}" 2>&1) - if [ -n "${VERSION}" ]; then - echo -e "${COL_GREEN}OK${COL_RESET}" - echo " ${VERSION}" - else - echo -e "${COL_RED}wrong version${COL_RESET}. Expected: ${VERSION_STRING}" - echo " ${VERSION_FULL}" - fi - else - echo -e "${COL_RED}not found!${COL_RESET}" - fi -} - -# every OS: -check "curl" "curl --version" "curl" -check "jq" "jq --version" "jq" - -case "$(uname)" in - Linux*) - check "ruby" "ruby --version" "ruby 2.7" - check "gpg" "gpg --version" "gpg (GnuPG) 2." - check "printenv" "printenv --version" "printenv (GNU coreutils)" - check "rsync" "rsync --version" "version" - check "ssh" "ssh -V" "OpenSSH" - check "git" "git --version" "git version" - check "mvn" "mvn --version" "Apache Maven" - check "unzip" "unzip --version" "UnZip" - check "zip" "zip --version" "This is Zip" - #check "7z" "7z -version" "7-Zip" - ;; - Darwin*) - ;; - CYGWIN*|MINGW*) - check "7z" "7z -version" "7-Zip" - ;; - *) - log_error "Unknown OS: $(uname)" - exit 1 - ;; -esac diff --git a/.ci/files/id_rsa.gpg b/.ci/files/id_rsa.gpg deleted file mode 100644 index 8e68ae0f10..0000000000 Binary files a/.ci/files/id_rsa.gpg and /dev/null differ diff --git a/.ci/files/id_rsa.pub b/.ci/files/id_rsa.pub deleted file mode 100644 index 7e1b51e198..0000000000 --- a/.ci/files/id_rsa.pub +++ /dev/null @@ -1 +0,0 @@ -ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC8yHVLHYDsKui8tYg/sFvkDqcs97pEZz0BzK9HtBF4O+/It1drRYRdUAFfjoImfprpKSxkJCTglHixGRp24eNaZ6woWVJ4/bmiMkEqEZAjr1NZ3qw7zIruMJMSkCV+YTtmL4cYcZlvMRPzzOZOnFbV05oi79oy41MUFHYjolK9QxMFNsVNN5iyzFxM3HqSFozz+ylKbFBtDk6ZHZQNRL/Xl2V9DJ69fVzjG4OZfcWNGmmKHHARmsnJyUOMeeKpLjDOe1M6ZdI8HkXWac8yCr9JTETNZZwemZAcS/RKoKCDqfIUOzkZfIPmyaznfVetTGsMi7yQrJhAyjznuNGF4+3lfgTcmRF8wz5FCeUkdYTmy2wNSFi5HiLPfC5OgRtjKzC6yb8rbRjDx6XQ2ph15PKOaXwzk49TaMc0xJvoiGDMZaTU0iTm3Y1/QUtfLvo3/jGMbtUdV3soWpuBAV2JUI4aB5xdLX9iNmcrVzoUe3y9DWuuTX46eoCvpUNXv/DXKhQw1D7xd7J67db5qUck/Akiqi0JR+e0SoBJvZFtYwVNLGC2bIJ/s8SR8X5Zp+1+ypf3WYjIylxQTkO1r4NfI0Cd9qXg7nmUrHAU7Z6xtJmUK8ZWzSST4wul8WkRJURtODLxt5firtlKhyZ93t9Mjuk6mATIPxr/b3x20T+IH463kw== ssh key for pmd. used for travis accessing sourceforge and github. diff --git a/.ci/files/maven-settings.xml b/.ci/files/maven-settings.xml deleted file mode 100644 index a8d61b8f1a..0000000000 --- a/.ci/files/maven-settings.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - org.sonarsource.scanner.maven - - - - ossrh - ${env.CI_DEPLOY_USER} - ${env.CI_DEPLOY_PASSWORD} - - - - - - - ossrh - - ${env.CI_SIGN_KEY} - ${env.CI_SIGN_PASSPHRASE} - - - - - diff --git a/.ci/files/private-env.gpg b/.ci/files/private-env.gpg deleted file mode 100644 index af292ee8b5..0000000000 Binary files a/.ci/files/private-env.gpg and /dev/null differ diff --git a/.ci/files/release-signing-key-D0BF1D737C9A1C22.gpg.gpg b/.ci/files/release-signing-key-D0BF1D737C9A1C22.gpg.gpg deleted file mode 100644 index d0b2babc1c..0000000000 Binary files a/.ci/files/release-signing-key-D0BF1D737C9A1C22.gpg.gpg and /dev/null differ diff --git a/.ci/inc/fetch_ci_scripts.bash b/.ci/inc/fetch_ci_scripts.bash new file mode 100644 index 0000000000..d608e40531 --- /dev/null +++ b/.ci/inc/fetch_ci_scripts.bash @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +function fetch_ci_scripts() { + local inc_dir + local inc_url + inc_dir="$(dirname "$0")/inc" + inc_url="${PMD_CI_SCRIPTS_URL:-https://raw.githubusercontent.com/pmd/build-tools/master/scripts}/inc" + + mkdir -p "${inc_dir}" + + for f in ${SCRIPT_INCLUDES}; do + if [ ! -e "${inc_dir}/$f" ]; then + curl -sSL "${inc_url}/$f" > "${inc_dir}/$f" + fi + [ "$PMD_CI_DEBUG" = "true" ] && echo "loading ${inc_dir}/$f in ${MODULE:-$0}" + # shellcheck source=/dev/null + source "${inc_dir}/$f" || exit 1 + done +} diff --git a/.ci/inc/github-releases-api.inc b/.ci/inc/github-releases-api.inc deleted file mode 100644 index e71e67f941..0000000000 --- a/.ci/inc/github-releases-api.inc +++ /dev/null @@ -1,214 +0,0 @@ -# -# The functions here require the following scripts: -# logger.inc -# -# The functions here require the following environment variables: -# GITHUB_OAUTH_TOKEN -# GITHUB_BASE_URL -# - -# -# Creates a new release on github with the given tag and target_commit. -# The release is draft and not published. -# -# $RESULT = release json string -# -# See: https://developer.github.com/v3/repos/releases/#create-a-release -# -function gh_releases_createDraftRelease() { - local tagName="$1" - local targetCommitish="$2" - - log_debug "$FUNCNAME: Creating new draft release for tag=$tagName and commit=$targetCommitish" - - local request=$(cat <<-EOF - { - "tag_name": "${tagName}", - "target_commitish": "${targetCommitish}", - "name": "${tagName}", - "draft": true - } - EOF - ) - - log_debug "POST $GITHUB_BASE_URL/releases" - log_info "Creating github draft release" - RESULT=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - -H "Content-Type: application/json" \ - -X POST \ - --data "${request}" \ - "$GITHUB_BASE_URL/releases") - log_debug " -> response: $RESULT" - - log_success "Created draft release with id $(echo $RESULT | jq --raw-output ".url")" -} - -# -# Gets the latest release, if it is a draft and returns with 0. -# Returns with 1, if the latest release is not a draft - meaning, there is no -# draft release (yet?). -# -# RESULT = release json string -# -# See: https://developer.github.com/v3/repos/releases/#list-releases-for-a-repository -# -function gh_releases_getLatestDraftRelease() { - log_debug "$FUNCNAME" - log_debug "GET $GITHUB_BASE_URL/releases?per_page=1" - RESULT=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - "$GITHUB_BASE_URL/releases?per_page=1" | jq ".[0]") - log_debug " -> response: $RESULT" - local draft=$(echo $RESULT | jq ".draft") - if [ "$draft" != "true" ]; then - RESULT="" - log_error "Could not find draft release!" - return 1 - fi - log_info "Found draft release: $(echo $RESULT | jq --raw-output ".url")" -} - -# -# Deletes a release. -# -# See: https://developer.github.com/v3/repos/releases/#delete-a-release -# -function gh_release_deleteRelease() { - local release="$1" - - gh_release_getIdFromData "$release" - local releaseId="$RESULT" - log_debug "$FUNCNAME id=$releaseId" - log_debug "DELETE $GITHUB_BASE_URL/releases/$releaseId" - log_info "Deleting github release $releaseId" - local response - response=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - -X DELETE \ - "$GITHUB_BASE_URL/releases/$releaseId") - log_debug " -> response: $response" - log_success "Deleted release with id $releaseId" -} - -# -# Determines the release id from the given JSON release data. -# -# RESULT = "the release id" -# -function gh_release_getIdFromData() { - local release="$1" - - RESULT=$(echo $release | jq --raw-output ".id") -} - -# -# Determines the tag_name from the given JSON release data. -# -# RESULT = "the tag name" -# -function gh_release_getTagNameFromData() { - local release="$1" - - RESULT=$(echo $release | jq --raw-output ".tag_name") -} - -# -# Uploads a asset to an existing release. -# -# See: https://developer.github.com/v3/repos/releases/#upload-a-release-asset -# -function gh_release_uploadAsset() { - local release="$1" - local filename="$2" - local name=$(basename $filename) - - gh_release_getIdFromData "$release" - local releaseId="$RESULT" - log_debug "$FUNCNAME: releaseId=$releaseId file=$filename name=$name" - - local uploadUrl=$(echo "$release" | jq --raw-output ".upload_url") - uploadUrl="${uploadUrl%%\{\?name,label\}}" - uploadUrl="${uploadUrl}?name=${name}" - log_debug "POST $uploadUrl" - log_info "Uploading $filename to github release $releaseId" - local response - response=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - -H "Content-Type: application/zip" \ - --data-binary "@$filename" \ - -X POST \ - "${uploadUrl}") - log_debug " -> response: $response" - log_success "Uploaded release asset $filename for release $releaseId" -} - -# -# Updates the release info: name and body. -# The body is escaped to fit into JSON, so it is allowed for the body to be -# a multi-line string. -# -# See: https://developer.github.com/v3/repos/releases/#edit-a-release -# -function gh_release_updateRelease() { - local release="$1" - local name="$2" - local body="$3" - - gh_release_getIdFromData "$release" - local releaseId="$RESULT" - gh_release_getTagNameFromData "$release" - local tagName="$RESULT" - log_debug "$FUNCNAME releaseId=$releaseId name=$name tag_name=$tagName" - - body="${body//'\'/\\\\}" - body="${body//$'\r'/}" - body="${body//$'\n'/\\r\\n}" - body="${body//'"'/\\\"}" - - local request=$(cat <<-EOF - { - "tag_name": "${tagName}", - "name": "${name}", - "body": "${body}" - } - EOF - ) - - log_debug "PATCH $GITHUB_BASE_URL/releases/${releaseId}" - log_debug " -> request: $request" - log_info "Updating github release $releaseId" - local response - response=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "${request}" \ - -X PATCH \ - "$GITHUB_BASE_URL/releases/${releaseId}") - log_debug " -> response: $response" - log_success "Updated release with id=$releaseId" -} - -# -# Publish a release by setting draft="false". -# Note: This will send out the notification emails if somebody -# watched the releases. -# -# See: https://developer.github.com/v3/repos/releases/#edit-a-release -# -function gh_release_publishRelease() { - local release="$1" - - gh_release_getIdFromData "$release" - local releaseId="$RESULT" - log_debug "$FUNCNAME releaseId=$releaseId" - - local request='{"draft":false}' - log_debug "PATCH $GITHUB_BASE_URL/releases/${releaseId}" - log_debug " -> request: $request" - log_info "Publishing github release $releaseId" - local response - response=$(curl --fail -s -H "Authorization: token ${GITHUB_OAUTH_TOKEN}" \ - -H "Content-Type: application/json" \ - --data "${request}" \ - -X PATCH \ - "$GITHUB_BASE_URL/releases/${releaseId}") - log_debug " -> response: $response" - local htmlUrl=$(echo "$response" | jq --raw-output ".html_url") - log_success "Published release with id=$releaseId at $htmlUrl" -} diff --git a/.ci/inc/install-openjdk.inc b/.ci/inc/install-openjdk.inc deleted file mode 100644 index c9a963242b..0000000000 --- a/.ci/inc/install-openjdk.inc +++ /dev/null @@ -1,103 +0,0 @@ - -# needs: -# inc/logger - -# -# Downloads openjdk from AdoptOpenJDK by accessing the API. -# The API is documented at https://api.adoptopenjdk.net/swagger-ui/ -# - -function install_openjdk() { - OPENJDK_VERSION=$1 - - case "$(uname)" in - Linux*) - JDK_OS=linux - COMPONENTS_TO_STRIP=1 # e.g. openjdk-11.0.3+7/bin/java - ;; - Darwin*) - JDK_OS=mac - COMPONENTS_TO_STRIP=3 # e.g. jdk-11.0.3+7/Contents/Home/bin/java - ;; - CYGWIN*|MINGW*) - JDK_OS=windows - ;; - *) - log_error "Unknown OS: $(uname)" - exit 1 - ;; - esac - - - DOWNLOAD_URL=$(curl --silent -X GET "https://api.adoptopenjdk.net/v3/assets/feature_releases/${OPENJDK_VERSION}/ga?architecture=x64&heap_size=normal&image_type=jdk&jvm_impl=hotspot&os=${JDK_OS}&page=0&page_size=1&project=jdk&sort_method=DEFAULT&sort_order=DESC&vendor=adoptopenjdk" \ - -H "accept: application/json" \ - | jq -r ".[0].binaries[0].package.link") - - OPENJDK_ARCHIVE=$(basename ${DOWNLOAD_URL}) - log_debug "Archive name: ${OPENJDK_ARCHIVE}" - - CACHE_DIR=${HOME}/.cache/openjdk - TARGET_DIR=${HOME}/openjdk${OPENJDK_VERSION} - - mkdir -p ${CACHE_DIR} - mkdir -p ${TARGET_DIR} - - if [ ! -e ${CACHE_DIR}/${OPENJDK_ARCHIVE} ]; then - log_info "Downloading from ${DOWNLOAD_URL} to ${CACHE_DIR}" - curl --location --output ${CACHE_DIR}/${OPENJDK_ARCHIVE} "${DOWNLOAD_URL}" - else - log_info "Skipped download, file ${CACHE_DIR}/${OPENJDK_ARCHIVE} already exists" - fi - - log_info "Extracting to ${TARGET_DIR}" - - case "$OPENJDK_ARCHIVE" in - *.zip) - 7z x ${CACHE_DIR}/${OPENJDK_ARCHIVE} -o${TARGET_DIR} - mv ${TARGET_DIR}/*/* ${TARGET_DIR}/ - ;; - *.tar.gz) - tar --extract --file ${CACHE_DIR}/${OPENJDK_ARCHIVE} -C ${TARGET_DIR} --strip-components=${COMPONENTS_TO_STRIP} - ;; - *) - log_error "Unknown filetype: ${OPENJDK_ARCHIVE}" - exit 1 - ;; - esac -} - -function install_openjdk_setdefault() { - OPENJDK_VERSION=$1 - - install_openjdk $OPENJDK_VERSION - - log_info "Using OpenJDK ${OPENJDK_VERSION} as default" - TARGET_DIR=${HOME}/openjdk${OPENJDK_VERSION} - export JAVA_HOME="${TARGET_DIR}" - export PATH="${TARGET_DIR}/bin:${PATH}" - - java -version -} - -# -# Installs jdk7 for integration test -# -function install_oraclejdk7() { - local local_dir="${HOME}/.cache/jdk7" - local target_dir="${HOME}/oraclejdk7" - local download_url="https://pmd-code.org/oraclejdk/jdk-7u80-linux-x64.tar.gz" - local archive=$(basename $download_url) - - mkdir -p ${local_dir} - mkdir -p ${target_dir} - if [ ! -e ${local_dir}/${archive} ]; then - log_info "Downloading from ${download_url} to ${local_dir}" - curl --location --output ${local_dir}/${archive} ${download_url} - else - log_info "Skipped download, file ${local_dir}/${archive} already exists" - fi - log_info "Extracting to ${target_dir}" - tar --extract --file ${local_dir}/${archive} -C ${target_dir} --strip-components=1 - - log_info "OracleJDK7 can be used via -Djava7.home=${HOME}/oraclejdk7" -} diff --git a/.ci/inc/logger.inc b/.ci/inc/logger.inc deleted file mode 100644 index cf002de9a1..0000000000 --- a/.ci/inc/logger.inc +++ /dev/null @@ -1,30 +0,0 @@ -COL_GREEN="\e[32m" -COL_RED="\e[31m" -COL_RESET="\e[0m" -COL_YELLOW="\e[33;1m" - -function log_error() { - echo -e "${COL_RED}[ERROR ] $*${COL_RESET}" -} - -function log_info() { - echo -e "${COL_YELLOW}[INFO ] $*${COL_RESET}" -} - -function log_success() { - echo -e "${COL_GREEN}[SUCCESS] $*${COL_RESET}" -} - -function log_debug() { - true - #echo -e "[DEBUG ] $*" -} - -function log_group_start() { - echo "::group::$*" - log_info $* -} - -function log_group_end() { - echo "::endgroup::" -} \ No newline at end of file diff --git a/.ci/inc/pmd-code-api.inc b/.ci/inc/pmd-code-api.inc index d9e75beb7c..122f7be59b 100644 --- a/.ci/inc/pmd-code-api.inc +++ b/.ci/inc/pmd-code-api.inc @@ -1,7 +1,9 @@ -# -# The functions here require the following scripts: -# inc/logger.inc -# +#!/usr/bin/env bash + +MODULE="pmd-code-api" +SCRIPT_INCLUDES="log.bash" +# shellcheck source=inc/fetch_ci_scripts.bash +source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts PMD_CODE_SSH_USER=pmd PMD_CODE_DOCS_PATH=/docs.pmd-code.org/ @@ -11,53 +13,51 @@ function pmd_code_uploadDocumentation() { local filename="$2" local basefilename="$(basename $filename)" - log_debug "$FUNCNAME pmdVersion=$pmdVersion filename=$filename" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion filename=$filename" scp "${filename}" ${PMD_CODE_SSH_USER}@pmd-code.org:${PMD_CODE_DOCS_PATH} ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH} && \ unzip -qo ${basefilename} && \ rm ${basefilename}" - log_info "Docs updated: https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" + pmd_ci_log_info "Docs updated: https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" } function pmd_code_removeDocumentation() { local pmdVersion="$1" - log_debug "$FUNCNAME pmdVersion=$pmdVersion" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion" ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH} && \ rm -rf pmd-doc-${pmdVersion}/" - log_info "Removed docs: https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" + pmd_ci_log_info "Removed docs: https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" } function pmd_code_createSymlink() { local pmdVersion="$1" local name="$2" - log_debug "$FUNCNAME pmdVersion=$pmdVersion name=$name" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion name=$name" ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH} && \ rm -f $name && \ ln -s pmd-doc-${pmdVersion} $name" - log_info "Symlink created: https://docs.pmd-code.org/$name/ -> https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" + pmd_ci_log_info "Symlink created: https://docs.pmd-code.org/$name/ -> https://docs.pmd-code.org/pmd-doc-${pmdVersion}/" } function pmd_code_uploadJavadoc() { local pmdVersion="$1" local basePath="$2" - log_debug "$FUNCNAME pmdVersion=$pmdVersion basePath=$basePath" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion basePath=$basePath" for i in ${basePath}/*/target/*-javadoc.jar */*/target/*-javadoc.jar; do pmd_code_uploadJavadocModule "$pmdVersion" "$i" done - pmd_code_fixPmdLangTestStyle "${basePath}" - # make sure https://docs.pmd-code.org/apidocs/ shows directory index ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH}/apidocs && \ echo 'Options +Indexes' > .htaccess" - log_info "Directory index enabled for https://docs.pmd-code.org/apidocs/" + pmd_ci_log_info "Directory index enabled for https://docs.pmd-code.org/apidocs/" } function pmd_code_uploadJavadocModule() { @@ -66,29 +66,21 @@ function pmd_code_uploadJavadocModule() { local moduleJavadocJarBasename="$(basename $moduleJavadocJar)" local module=${moduleJavadocJarBasename%%-${pmdVersion}-javadoc.jar} - log_debug "$FUNCNAME pmdVersion=$pmdVersion moduleJavadocJar=$moduleJavadocJar module=$module" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion moduleJavadocJar=$moduleJavadocJar module=$module" scp "$moduleJavadocJar" ${PMD_CODE_SSH_USER}@pmd-code.org:${PMD_CODE_DOCS_PATH} ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH} && \ mkdir -p apidocs/${module}/${pmdVersion} && \ unzip -qo -d apidocs/${module}/${pmdVersion} ${moduleJavadocJarBasename} && \ rm ${moduleJavadocJarBasename}" - log_info "JavaDoc for $module uploaded: https://docs.pmd-code.org/apidocs/${module}/${pmdVersion}/" -} - -function pmd_code_fixPmdLangTestStyle { - local basePath="$1" - - log_debug "$FUNCNAME basePath=$basePath" - scp "${basePath}/pmd-lang-test/target/dokka/style.css" ${PMD_CODE_SSH_USER}@pmd-code.org:${PMD_CODE_DOCS_PATH}/apidocs/pmd-lang-test/ - log_info "Fixed style for https://docs.pmd-code.org/apidocs/pmd-lang-test/*/" + pmd_ci_log_info "JavaDoc for $module uploaded: https://docs.pmd-code.org/apidocs/${module}/${pmdVersion}/" } function pmd_code_removeJavadoc() { local pmdVersion="$1" - log_debug "$FUNCNAME pmdVersion=$pmdVersion" + pmd_ci_log_debug "$FUNCNAME pmdVersion=$pmdVersion" ssh ${PMD_CODE_SSH_USER}@pmd-code.org "cd ${PMD_CODE_DOCS_PATH} && \ rm -rf apidocs/*/${pmdVersion}" - log_info "Removed Javadoc: https://docs.pmd-code.org/apidocs/*/${pmdVersion}/ is gone" + pmd_ci_log_info "Removed Javadoc: https://docs.pmd-code.org/apidocs/*/${pmdVersion}/ is gone" } diff --git a/.ci/inc/pmd-doc.inc b/.ci/inc/pmd-doc.inc index 6054baca46..370b22d3fe 100644 --- a/.ci/inc/pmd-doc.inc +++ b/.ci/inc/pmd-doc.inc @@ -1,3 +1,9 @@ +#!/usr/bin/env bash + +MODULE="pmd-doc" +SCRIPT_INCLUDES="log.bash" +# shellcheck source=inc/fetch_ci_scripts.bash +source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts # Used env vars: # PMD_CI_JOB_URL @@ -12,7 +18,7 @@ function pmd_doc_generate_jekyll_site() { pushd docs echo -e "\n\n" - log_info "Building documentation using jekyll..." + pmd_ci_log_info "Building documentation using jekyll..." bundle config set --local path vendor/bundle bundle install bundle exec jekyll build @@ -27,21 +33,21 @@ function pmd_doc_create_archive() { pushd docs echo -e "\n\n" - log_info "Creating pmd-doc archive..." - mv _site pmd-doc-${VERSION} - zip -qr pmd-doc-${VERSION}.zip pmd-doc-${VERSION}/ - log_success "Successfully created pmd-doc-${VERSION}.zip" + pmd_ci_log_info "Creating pmd-doc archive..." + mv _site pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION} + zip -qr pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/ + pmd_ci_log_success "Successfully created pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" popd } # -# Publishes the site to https://pmd.github.io/pmd-${VERSION} and +# Publishes the site to https://pmd.github.io/pmd-${PMD_CI_MAVEN_PROJECT_VERSION} and # https://pmd.github.io/latest/ # function publish_release_documentation_github() { echo -e "\n\n" - log_info "Adding the new doc to pmd.github.io..." + pmd_ci_log_info "Adding the new doc to pmd.github.io..." # clone pmd.github.io. Note: This uses the ssh key setup earlier # In order to speed things up, we use a sparse checkout - no need to checkout all directories here mkdir pmd.github.io @@ -55,30 +61,30 @@ function publish_release_documentation_github() { echo "/latest/" > .git/info/sparse-checkout echo "/sitemap.xml" >> .git/info/sparse-checkout git pull --depth=1 origin master - log_info "Copying documentation from ../docs/pmd-doc-${VERSION}/ to pmd-${VERSION}/ ..." - rsync -ah --stats ../docs/pmd-doc-${VERSION}/ pmd-${VERSION}/ + pmd_ci_log_info "Copying documentation from ../docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/ to pmd-${PMD_CI_MAVEN_PROJECT_VERSION}/ ..." + rsync -ah --stats ../docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/ pmd-${PMD_CI_MAVEN_PROJECT_VERSION}/ git status - echo "Executing: git add pmd-${VERSION}" - git add pmd-${VERSION} - echo "Executing: git commit..." - git commit -q -m "Added pmd-${VERSION}" + pmd_ci_log_debug "Executing: git add pmd-${PMD_CI_MAVEN_PROJECT_VERSION}" + git add pmd-${PMD_CI_MAVEN_PROJECT_VERSION} + pmd_ci_log_debug "Executing: git commit..." + git commit -q -m "Added pmd-${PMD_CI_MAVEN_PROJECT_VERSION}" - log_info "Copying pmd-${VERSION} to latest ..." + pmd_ci_log_info "Copying pmd-${PMD_CI_MAVEN_PROJECT_VERSION} to latest ..." git rm -qr latest - cp -a pmd-${VERSION} latest - echo "Executing: git add latest" + cp -a pmd-${PMD_CI_MAVEN_PROJECT_VERSION} latest + pmd_ci_log_debug "Executing: git add latest" git add latest - echo "Executing: git commit..." - git commit -q -m "Copying pmd-${VERSION} to latest" + pmd_ci_log_debug "Executing: git commit..." + git commit -q -m "Copying pmd-${PMD_CI_MAVEN_PROJECT_VERSION} to latest" - log_info "Generating sitemap.xml" + pmd_ci_log_info "Generating sitemap.xml" ../docs/sitemap_generator.sh > sitemap.xml - echo "Executing: git add sitemap.xml" + pmd_ci_log_debug "Executing: git add sitemap.xml" git add sitemap.xml - echo "Executing: git commit..." + pmd_ci_log_debug "Executing: git commit..." git commit -q -m "Generated sitemap.xml" - echo "Executing: git push origin master" + pmd_ci_log_info "Executing: git push origin master" git push origin master ) } @@ -89,12 +95,12 @@ function publish_release_documentation_github() { # function pmd_doc_publish_to_github_pages() { echo -e "\n\n" - log_info "Pushing the new site to github pages..." + pmd_ci_log_info "Pushing the new site to github pages..." git clone --branch gh-pages --depth 1 git@github.com:pmd/pmd.git pmd-gh-pages # clear the files first rm -rf pmd-gh-pages/* # copy the new site - cp -a docs/pmd-doc-${VERSION}/* pmd-gh-pages/ + cp -a docs/pmd-doc-${PMD_CI_MAVEN_PROJECT_VERSION}/* pmd-gh-pages/ ( cd pmd-gh-pages git config user.name "PMD CI (pmd-bot)" @@ -106,6 +112,6 @@ ${PMD_CI_JOB_URL} ${PMD_CI_PUSH_COMMIT_COMPARE}" git commit -q -m "$MSG" git push git@github.com:pmd/pmd.git HEAD:gh-pages - log_success "Successfully pushed site to https://pmd.github.io/pmd/" + pmd_ci_log_success "Successfully pushed site to https://pmd.github.io/pmd/" ) } diff --git a/.ci/inc/regression-tester.inc b/.ci/inc/regression-tester.inc index 3bc72ccd81..65d6e1e6b2 100644 --- a/.ci/inc/regression-tester.inc +++ b/.ci/inc/regression-tester.inc @@ -1,7 +1,10 @@ -# -# The functions here require the following scripts: -# inc/logger.inc -# inc/install-openjdk.inc +#!/usr/bin/env bash + +MODULE="pmd-doc" +SCRIPT_INCLUDES="log.bash openjdk.bash" +# shellcheck source=inc/fetch_ci_scripts.bash +source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts + # # The functions here require the following environment variables: # PMD_SF_USER @@ -11,8 +14,8 @@ # PMD_CI_CHUNK_TOKEN function regression_tester_setup_ci() { - log_info "Install openjdk8 for pmd-regression-tests" - install_openjdk 8 + pmd_ci_log_info "Install openjdk8 for pmd-regression-tests" + pmd_ci_openjdk_install_adoptopenjdk 8 gpg --batch --yes --decrypt --passphrase="GnxdjywUEPveyCD1RLiTd7t8CImnefYr" \ --output .ci/files/public-env .ci/files/public-env.gpg @@ -20,9 +23,9 @@ function regression_tester_setup_ci() { rm .ci/files/public-env if hash "bundler" 2>/dev/null; then - log_debug "Bundler is already installed" + pmd_ci_log_debug "Bundler is already installed" else - log_info "Installing bundler..." + pmd_ci_log_info "Installing bundler..." gem install bundler fi @@ -38,9 +41,9 @@ function regression_tester_setup_ci() { function regression_tester_uploadBaseline() { local pmdcodeUrl="https://pmd-code.org/pmd-regression-tester/" local baseline_branch="${PMD_CI_BRANCH:-$PMD_CI_TAG}" - log_debug "$FUNCNAME branch=${baseline_branch}" + pmd_ci_log_debug "$FUNCNAME branch=${baseline_branch}" - log_info "Generating and uploading baseline for pmdtester (${baseline_branch})..." + pmd_ci_log_info "Generating and uploading baseline for pmdtester (${baseline_branch})..." pushd .. rm -f .bundle/config bundle config set --local gemfile pmd/Gemfile @@ -54,9 +57,9 @@ function regression_tester_uploadBaseline() { pushd target/reports BRANCH_FILENAME="${baseline_branch/\//_}" zip -q -r ${BRANCH_FILENAME}-baseline.zip ${BRANCH_FILENAME}/ - # ssh-key for pmd-code.org is setup already by pmd_ci_setup_ssh + # ssh-key for pmd-code.org is setup already by pmd_ci_setup_secrets_ssh scp ${BRANCH_FILENAME}-baseline.zip pmd@pmd-code.org:/httpdocs/pmd-regression-tester/ - log_success "Successfully uploaded ${BRANCH_FILENAME}-baseline.zip to ${pmdcodeUrl}" + pmd_ci_log_success "Successfully uploaded ${BRANCH_FILENAME}-baseline.zip to ${pmdcodeUrl}" popd popd } @@ -65,7 +68,7 @@ function regression_tester_uploadBaseline() { # Execute danger, which executes pmd-regression-tester (via Dangerfile). # function regression_tester_executeDanger() { - log_debug "$FUNCNAME" + pmd_ci_log_debug "$FUNCNAME" # Create a corresponding remote branch locally if ! git show-ref --verify --quiet refs/heads/${PMD_CI_BRANCH}; then @@ -81,7 +84,7 @@ function regression_tester_executeDanger() { git branch master origin/master fi - log_info "Running danger on branch ${PMD_CI_BRANCH}" + pmd_ci_log_info "Running danger on branch ${PMD_CI_BRANCH}" bundle exec danger --verbose - log_success "Executed danger successfully" + pmd_ci_log_success "Executed danger successfully" } diff --git a/.ci/inc/setup-secrets.inc b/.ci/inc/setup-secrets.inc deleted file mode 100644 index 6cd3ba953b..0000000000 --- a/.ci/inc/setup-secrets.inc +++ /dev/null @@ -1,62 +0,0 @@ -function pmd_ci_setup_private_env() { - log_info "Setting up secrets as environment variables..." - local -r ENV_FILE=.ci/files/private-env - - printenv PMD_CI_SECRET_PASSPHRASE | gpg --batch --yes --decrypt \ - --passphrase-fd 0 \ - --output ${ENV_FILE} ${ENV_FILE}.gpg - - source ${ENV_FILE} >/dev/null 2>&1 - rm ${ENV_FILE} -} - -function pmd_ci_setup_gpg_key() { - log_info "Setting up GPG release signing key..." - local -r GPG_FILE=.ci/files/release-signing-key-D0BF1D737C9A1C22.gpg - - mkdir -p "${HOME}/.gpg" - printenv PMD_CI_SECRET_PASSPHRASE | gpg --batch --yes --decrypt \ - --passphrase-fd 0 \ - --output ${GPG_FILE} ${GPG_FILE}.gpg - gpg --batch --import ${GPG_FILE} - rm ${GPG_FILE} -} - -function pmd_ci_setup_ssh() { - log_info "Setting up .ssh/id_rsa..." - local -r SSH_KEY_FILE=.ci/files/id_rsa - - printenv PMD_CI_SECRET_PASSPHRASE | gpg --batch --yes --decrypt \ - --passphrase-fd 0 \ - --output ${SSH_KEY_FILE} ${SSH_KEY_FILE}.gpg - chmod 600 ${SSH_KEY_FILE} - - mkdir -p ${HOME}/.ssh - chmod 700 "${HOME}/.ssh" - mv ${SSH_KEY_FILE} "${HOME}/.ssh/id_rsa" - - log_info "Setting up .ssh/known_hosts..." - # - # https://sourceforge.net/p/forge/documentation/SSH%20Key%20Fingerprints/ - # - # run locally: - # ssh-keyscan web.sourceforge.net | tee -a known_hosts - # - # verify fingerprints: - # ssh-keygen -F web.sourceforge.net -l -f known_hosts - # # Host web.sourceforge.net found: line 1 - # web.sourceforge.net RSA SHA256:xB2rnn0NUjZ/E0IXQp4gyPqc7U7gjcw7G26RhkDyk90 - # # Host web.sourceforge.net found: line 2 - # web.sourceforge.net ECDSA SHA256:QAAxYkf0iI/tc9oGa0xSsVOAzJBZstcO8HqGKfjpxcY - # # Host web.sourceforge.net found: line 3 - # web.sourceforge.net ED25519 SHA256:209BDmH3jsRyO9UeGPPgLWPSegKmYCBIya0nR/AWWCY - # - # then add output of `ssh-keygen -F web.sourceforge.net -f known_hosts` - # - echo 'web.sourceforge.net ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA2uifHZbNexw6cXbyg1JnzDitL5VhYs0E65Hk/tLAPmcmm5GuiGeUoI/B0eUSNFsbqzwgwrttjnzKMKiGLN5CWVmlN1IXGGAfLYsQwK6wAu7kYFzkqP4jcwc5Jr9UPRpJdYIK733tSEmzab4qc5Oq8izKQKIaxXNe7FgmL15HjSpatFt9w/ot/CHS78FUAr3j3RwekHCm/jhPeqhlMAgC+jUgNJbFt3DlhDaRMa0NYamVzmX8D47rtmBbEDU3ld6AezWBPUR5Lh7ODOwlfVI58NAf/aYNlmvl2TZiauBCTa7OPYSyXJnIPbQXg6YQlDknNCr0K769EjeIlAfY87Z4tw==' >> "$HOME/.ssh/known_hosts" - echo 'web.sourceforge.net ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCwsY6sZT4MTTkHfpRzYjxG7mnXrGL74RCT2cO/NFvRrZVNB5XNwKNn7G5fHbYLdJ6UzpURDRae1eMg92JG0+yo=' >> "$HOME/.ssh/known_hosts" - echo 'web.sourceforge.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOQD35Ujalhh+JJkPvMckDlhu4dS7WH6NsOJ15iGCJLC' >> "$HOME/.ssh/known_hosts" - - # add pmd-code.org (ssh-keyscan pmd-code.org) - echo 'pmd-code.org ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVsIeF6xU0oPb/bMbxG1nU1NDyBpR/cBEPZcm/PuJwdI9B0ydPHA6FysqAnt32fNFznC2SWisnWyY3iNsP3pa8RQJVwmnnv9OboGFlW2/61o3iRyydcpPbgl+ADdt8iU9fmMI7dC04UqgHGBoqOwVNna9VylTjp5709cK2qHnwU450F6YcOEiOKeZfJvV4PmpJCz/JcsUVqft6StviR31jKnqbnkZdP8qNoTbds6WmGKyXkhHdLSZE7X1CFQH28tk8XFqditX93ezeCiThFL7EleDexV/3+2+cs5878sDMUMzHS5KShTjkxzhHaodhtIEdNesinq/hOPbxAGkQ0FbD' >> $HOME/.ssh/known_hosts -} diff --git a/.ci/inc/sourceforge-api.inc b/.ci/inc/sourceforge-api.inc deleted file mode 100644 index 24f165cf6f..0000000000 --- a/.ci/inc/sourceforge-api.inc +++ /dev/null @@ -1,166 +0,0 @@ -# -# The functions here require the following scripts: -# logger.inc -# -# The functions here require the following environment variables: -# PMD_SF_USER -# PMD_SF_APIKEY -# - -# -# Uploads the release notes to sourceforge files as "ReadMe.md". -# -# Note: this function always succeeds, even if the upload fails. -# In that case, just a error logging is provided. -# -function sourceforge_uploadReleaseNotes() { - local pmdVersion="$1" - local releaseNotes="$2" - - log_debug "$FUNCNAME pmdVersion=$pmdVersion" - local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" - - local errexitstate="$(shopt -po errexit)" - set +e # disable errexit - ( - # This handler is called if any command fails - function release_notes_fail() { - log_error "Error while uploading release notes as ReadMe.md to sourceforge!" - log_error "Please upload manually: ${targetUrl}" - cleanup_temp_dir - } - - function cleanup_temp_dir() { - log_debug "Cleanup tempdir $releaseNotesTempDir" - rm "${releaseNotesTempDir}/${pmdVersion}/ReadMe.md" || true - rmdir "${releaseNotesTempDir}/${pmdVersion}" || true - rmdir "${releaseNotesTempDir}" || true - } - - # exit subshell after trap - set -e - trap release_notes_fail ERR - - local releaseNotesTempDir=$(mktemp -d) - log_debug "Tempdir: $releaseNotesTempDir" - mkdir -p "${releaseNotesTempDir}/${pmdVersion}" - echo "$releaseNotes" > "${releaseNotesTempDir}/${pmdVersion}/ReadMe.md" - - log_info "Uploading release notes to sourceforge for version $pmdVersion" - rsync -avz \ - "${releaseNotesTempDir}/" \ - "${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/" - - log_success "Successfully uploaded release notes as ReadMe.md to sourceforge: ${targetUrl}" - - cleanup_temp_dir - ) - # restore errexit state - eval "$errexitstate" -} - -# -# Uploads the given file to sourceforge. -# -# Note: This function always succeeds, even if the upload fails. -# In that case, just a error logging is provided. -# -function sourceforge_uploadFile() { - local pmdVersion="$1" - local filename="$2" - - log_debug "$FUNCNAME pmdVersion=$pmdVersion filename=$filename" - local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" - - local errexitstate="$(shopt -po errexit)" - set +e # disable errexit - ( - # This handler is called if any command fails - function upload_failed() { - log_error "Error while uploading ${filename} to sourceforge!" - log_error "Please upload manually: ${targetUrl}" - } - - # exit subshell after trap - set -e - trap upload_failed ERR - - log_info "Uploading $filename to sourceforge..." - .ci/travis_wait "rsync -avh ${filename} ${PMD_SF_USER}@web.sourceforge.net:/home/frs/project/pmd/pmd/${pmdVersion}/" - log_success "Successfully uploaded ${filename} to sourceforge: ${targetUrl}" - ) - # restore errexit state - eval "$errexitstate" -} - -# -# Select the given version as the new default download. -# -# Note: This function always succeeds, even if the request fails. -# In that case, just a error logging is provided. -# -function sourceforge_selectDefault() { - local pmdVersion="$1" - - log_debug "$FUNCNAME pmdVersion=$pmdVersion" - local targetUrl="https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}" - - local errexitstate="$(shopt -po errexit)" - set +e # disable errexit - ( - # This handler is called if any command fails - function request_failed() { - log_error "Error while selecting ${pmdVersion} as new default download on sourceforge!" - log_error "Please do it manually: ${targetUrl}" - } - - # exit subshell after trap - set -e - trap request_failed ERR - - log_info "Selecting $pmdVersion as new default on sourceforge..." - local response - response=$(curl --fail -s -H "Accept: application/json" \ - -X PUT \ - -d "api_key=${PMD_SF_APIKEY}" \ - -d "default=windows&default=mac&default=linux&default=bsd&default=solaris&default=others" \ - "https://sourceforge.net/projects/pmd/files/pmd/${pmdVersion}/pmd-bin-${pmdVersion}.zip") - log_debug " -> response: $response" - log_success "Successfully selected $pmdVersion as new default on sourceforge: ${targetUrl}" - ) - # restore errexit state - eval "$errexitstate" -} - -# -# Rsyncs the complete documentation to sourceforge. -# -# Note: This function always succeeds, even if the upload fails. -# In that case, just a error logging is provided. -# -function sourceforge_rsyncSnapshotDocumentation() { - local pmdVersion="$1" - local targetPath="$2" - - log_debug "$FUNCNAME pmdVersion=$pmdVersion targetPath=$targetPath" - local targetUrl="https://pmd.sourceforge.io/${targetPath}/" - - local errexitstate="$(shopt -po errexit)" - set +e # disable errexit - ( - # This handler is called if any command fails - function upload_failed() { - log_error "Couldn't upload the documentation. It won't be current on ${targetUrl}" - } - - # exit subshell after trap - set -e - trap upload_failed ERR - - log_info "Uploading documentation to ${targetUrl}..." - .ci/travis_wait "rsync -ah --stats --delete docs/pmd-doc-${VERSION}/ ${PMD_SF_USER}@web.sourceforge.net:/home/project-web/pmd/htdocs/snapshot/" - log_success "Successfully uploaded documentation: ${targetUrl}" - ) - # restore errexit state - eval "$errexitstate" -} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..33a35ec101 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,55 @@ +name: build + +on: + push: + branches: + - main + - master + tags: + - '**' + pull_request: + schedule: + # build it monthly: At 04:00 on day-of-month 1. + - cron: '0 4 1 * *' + +jobs: + build: + runs-on: ${{ matrix.os }} + continue-on-error: false + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }} + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: | + ~/.m2/repository + ~/.cache + 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: Setup Environment + shell: bash + run: | + echo "LANG=en_US.UTF-8" >> $GITHUB_ENV + echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3" >> $GITHUB_ENV + echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/master/scripts" >> $GITHUB_ENV + - name: Check Environment + shell: bash + run: | + f=check-environment.sh; \ + mkdir -p .ci && \ + ( [ -e .ci/$f ] || curl -sSL "${PMD_CI_SCRIPTS_URL}/$f" > ".ci/$f" ) && \ + chmod 755 .ci/$f && \ + .ci/$f + - name: Build + run: .ci/build.sh + shell: bash + env: + PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }}