From e2514c546c8e894ab1f151501d4b9c1066540a03 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 Nov 2020 20:34:37 +0100 Subject: [PATCH] Implement release builds --- .ci/build-pr.sh | 16 +- .ci/build.sh | 251 ++++++++++++++++++++++-------- .ci/docker_ubuntu18.04/Dockerfile | 2 +- .ci/inc/github-releases-api.inc | 214 +++++++++++++++++++++++++ .ci/inc/install-openjdk.inc | 3 - .ci/inc/maven-dependencies.inc | 9 +- .ci/inc/pmd-doc.inc | 2 +- .ci/inc/regression-tester.inc | 2 +- .ci/render_release_notes.rb | 44 ++++++ .github/workflows/pushes.yml | 5 +- .github/workflows/releases.yml | 11 +- docs/sitemap_generator.sh | 56 +++++++ 12 files changed, 528 insertions(+), 87 deletions(-) create mode 100644 .ci/inc/github-releases-api.inc create mode 100755 .ci/render_release_notes.rb create mode 100755 docs/sitemap_generator.sh diff --git a/.ci/build-pr.sh b/.ci/build-pr.sh index 38ea0c6f41..dad6e7ae95 100755 --- a/.ci/build-pr.sh +++ b/.ci/build-pr.sh @@ -6,13 +6,17 @@ source $(dirname $0)/inc/regression-tester.inc source $(dirname $0)/inc/maven-dependencies.inc set -e -#set -x -install_openjdk_setdefault 11 -maven_dependencies_resolve +log_group_start "Installing OpenJDK 11" + install_openjdk_setdefault 11 +log_group_end + +log_group_start "Downloading maven dependencies" + maven_dependencies_resolve +log_group_end log_group_start "Building with maven" -./mvnw -e -V clean verify + ./mvnw -e -V clean verify -Pgenerate-rule-docs log_group_end @@ -20,8 +24,8 @@ log_group_end case "$(uname)" in Linux*) log_group_start "Executing danger" - regression_tester_setup_ci - regression_tester_executeDanger + regression_tester_setup_ci + regression_tester_executeDanger log_group_end ;; esac diff --git a/.ci/build.sh b/.ci/build.sh index 6b68291bc1..715afb02f7 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -6,99 +6,226 @@ 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/maven-dependencies.inc set -e -#set -x function pmd_ci_build_main() { - pmd_ci_setup_private_env - pmd_ci_setup_gpg_key - pmd_ci_setup_ssh + log_group_start "Setting up private secrets" + pmd_ci_setup_private_env + pmd_ci_setup_gpg_key + pmd_ci_setup_ssh + log_group_end - install_openjdk_setdefault 11 - pmd_ci_build_setup_maven - pmd_ci_build_setup_oraclejdk7 - pmd_ci_build_setup_bundler + log_group_start "Prepare Java 11, Maven, Bundler" + install_openjdk_setdefault 11 + pmd_ci_build_setup_maven + pmd_ci_build_setup_oraclejdk7 + pmd_ci_build_setup_bundler + pmd_ci_build_setup_env + log_group_end - VERSION=$(pmd_ci_build_get_pom_version) - log_info "Building PMD ${VERSION}..." + log_group_start "Downloading maven dependencies" + maven_dependencies_resolve + log_group_end - pmd_ci_build_run + log_group_start "Build and Deploy" + pmd_ci_build_run + pmd_ci_deploy_build_artifacts + log_group_end - # Deploy to sourceforge files - sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-bin-${VERSION}.zip" - sourceforge_uploadFile "${VERSION}" "pmd-dist/target/pmd-src-${VERSION}.zip" + log_group_start "Build and Upload documentation" + pmd_ci_build_and_upload_doc + log_group_end - pmd_ci_build_and_upload_doc + if pmd_ci_build_isRelease; then + log_group_start "Publishing Release" + gh_release_publishRelease "$GH_RELEASE" + sourceforge_selectDefault "${VERSION}" + log_group_end + fi - regression_tester_setup_ci - regression_tester_uploadBaseline + log_group_start "Creating new baseline for regression tester" + regression_tester_setup_ci + regression_tester_uploadBaseline + log_group_end exit 0 } + +# +# 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 jdk7 for integration test +# +function pmd_ci_build_setup_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" +} + +# +# Installs bundler, which is needed for doc generation and regression tester +# +function pmd_ci_build_setup_bundler() { + log_info "Installing 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" + + if pmd_ci_build_isRelease; then + log_info "This is a release build" + mvn_profiles="${mvn_profiles},pmd-release" + else + log_info "This is a snapshot build" + fi + + ./mvnw clean deploy -P${mvn_profiles} -e -V -Djava7.home=${HOME}/oraclejdk7 +} + +# +# Deploys the binary distribution +# +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" + + if pmd_ci_build_isRelease; then + # create a draft github release + 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" + fi +} + +# +# Builds and uploads the documentation site +# 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" + 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)" - pmd_code_createSymlink "${VERSION}" "snapshot" + if [[ "${VERSION}" == *-SNAPSHOT && "${PMD_CI_BRANCH}" == "master" ]]; then + # only for snapshot builds from branch master + pmd_code_createSymlink "${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" + # 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" + fi + + if pmd_ci_build_isRelease; then + # documentation is already uploaded to https://docs.pmd-code.org/pmd-doc-${VERSION} + # we only need to setup symlinks for the released version + pmd_code_createSymlink "${VERSION}" "latest" + # remove old doc and point to the new version + pmd_code_removeDocumentation "${VERSION}-SNAPSHOT" + pmd_code_createSymlink "${VERSION}" "${VERSION}-SNAPSHOT" + # remove old javadoc + pmd_code_removeJavadoc "${VERSION}-SNAPSHOT" + + # updating github release text + # 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}" + + publish_release_documentation_github + sourceforge_rsyncSnapshotDocumentation "${VERSION}" "pmd-${VERSION}" + fi +} + + +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) } -function pmd_ci_build_setup_maven() { - # configure maven - mkdir -p ${HOME}/.m2 - cp .ci/files/maven-settings.xml ${HOME}/.m2/settings.xml -} - -function pmd_ci_build_setup_oraclejdk7() { - # install jdk7 for integration test - - LOCAL_DIR="${HOME}/.cache/jdk7" - TARGET_DIR="${HOME}/oraclejdk7" - DOWNLOAD_URL="https://pmd-code.org/oraclejdk/jdk-7u80-linux-x64.tar.gz" - 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" -} - -function pmd_ci_build_run() { - log_info "This is a snapshot build" - #export MAVEN_OPTS="-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3" - #export MAVEN_OPTS="-Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false" - ./mvnw deploy -Possrh,sign,generate-rule-docs -e -V -Djava7.home=${HOME}/oraclejdk7 -} - -# Needed for doc generation and regression tester -function pmd_ci_build_setup_bundler() { - log_info "Installing bundler..." - gem install bundler -} pmd_ci_build_main diff --git a/.ci/docker_ubuntu18.04/Dockerfile b/.ci/docker_ubuntu18.04/Dockerfile index 6999125846..ff76744c38 100644 --- a/.ci/docker_ubuntu18.04/Dockerfile +++ b/.ci/docker_ubuntu18.04/Dockerfile @@ -23,7 +23,7 @@ ENV GITHUB_EVENT_PATH=/workspaces/event.json ENV GITHUB_REPOSITORY=pmd/pmd ENV GITHUB_ACTION=run1 ENV GITHUB_EVENT_NAME=pull_request -ENV PMD_CI_BRANCH=refs/heads/master +ENV PMD_CI_BRANCH=master ENV PMD_CI_PULL_REQUEST_NUMBER=2913 COPY create-gh-pull-request-event.sh . COPY install-ruby.sh . diff --git a/.ci/inc/github-releases-api.inc b/.ci/inc/github-releases-api.inc new file mode 100644 index 0000000000..e71e67f941 --- /dev/null +++ b/.ci/inc/github-releases-api.inc @@ -0,0 +1,214 @@ +# +# 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 index 2a69ba6382..f84ff32540 100644 --- a/.ci/inc/install-openjdk.inc +++ b/.ci/inc/install-openjdk.inc @@ -9,7 +9,6 @@ function install_openjdk() { OPENJDK_VERSION=$1 - log_group_start "Installing OpenJDK ${OPENJDK_VERSION}" case "$(uname)" in Linux*) @@ -65,8 +64,6 @@ function install_openjdk() { exit 1 ;; esac - - log_group_end } function install_openjdk_setdefault() { diff --git a/.ci/inc/maven-dependencies.inc b/.ci/inc/maven-dependencies.inc index 64afe8b95c..711e0144b9 100644 --- a/.ci/inc/maven-dependencies.inc +++ b/.ci/inc/maven-dependencies.inc @@ -17,9 +17,8 @@ # execpt for dokka-maven-plugin, as it does not play well with dependency-plugin. # function maven_dependencies_resolve() { - log_group_start "Downloading maven dependencies" - - dokka_version=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${dokka.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:3.0.0:exec) + dokka_version=$(./mvnw -q -Dexec.executable="echo" -Dexec.args='${dokka.version}' + --non-recursive org.codehaus.mojo:exec-maven-plugin:3.0.0:exec) ./mvnw dependency:resolve ./mvnw dependency:get -DgroupId=org.jetbrains.dokka \ @@ -27,7 +26,5 @@ function maven_dependencies_resolve() { -Dversion=${dokka_version} \ -Dpackaging=jar \ -DremoteRepositories=jcenter::default::https://jcenter.bintray.com/ - ./mvnw dependency:resolve-plugins -DexcludeGroupIds=org.jetbrains.dokka - - log_group_end + ./mvnw dependency:resolve-plugins -DexcludeGroupIds=org.jetbrains.dokka -Psign } diff --git a/.ci/inc/pmd-doc.inc b/.ci/inc/pmd-doc.inc index c55f18fd92..6054baca46 100644 --- a/.ci/inc/pmd-doc.inc +++ b/.ci/inc/pmd-doc.inc @@ -72,7 +72,7 @@ function publish_release_documentation_github() { git commit -q -m "Copying pmd-${VERSION} to latest" log_info "Generating sitemap.xml" - ../.travis/sitemap_generator.sh > sitemap.xml + ../docs/sitemap_generator.sh > sitemap.xml echo "Executing: git add sitemap.xml" git add sitemap.xml echo "Executing: git commit..." diff --git a/.ci/inc/regression-tester.inc b/.ci/inc/regression-tester.inc index abbd15586f..1083c81e39 100644 --- a/.ci/inc/regression-tester.inc +++ b/.ci/inc/regression-tester.inc @@ -11,7 +11,7 @@ # PMD_CI_CHUNK_TOKEN function regression_tester_setup_ci() { - # install openjdk8 for pmd-regression-tests + log_info "Install openjdk8 for pmd-regression-tests" install_openjdk 8 gpg --batch --yes --decrypt --passphrase="GnxdjywUEPveyCD1RLiTd7t8CImnefYr" \ diff --git a/.ci/render_release_notes.rb b/.ci/render_release_notes.rb new file mode 100755 index 0000000000..c7d0542cd7 --- /dev/null +++ b/.ci/render_release_notes.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +# Renders the release notes for Github releases, +# and prints them to standard output + +# Doesn't trim the header, which is done in shell + +# Args: +# ARGV[0] : location of the file to render + +require "liquid" +require "safe_yaml" + +# include some custom liquid extensions +require_relative "../docs/_plugins/all_extensions" + +# explicitly setting safe mode to get rid of the warning +SafeYAML::OPTIONS[:default_mode] = :safe + +# START OF THE SCRIPT + +unless ARGV.length == 1 && File.exists?(ARGV[0]) + print "\e[31m[ERROR] In #{$0}: The first arg must be a valid file name\e[0m\n" + exit 1 +end + +release_notes_file = ARGV[0] + +# Make the script execute wherever we are +travis_dir = File.expand_path File.dirname(__FILE__) + +liquid_env = { + # wrap the config under a "site." namespace because that's how jekyll does it + 'site' => YAML.load_file(travis_dir + "/../docs/_config.yml"), + # This signals the links in {% rule %} tags that they should be rendered as absolute + 'is_release_notes_processor' => true +} + + +to_render = File.read(release_notes_file) +rendered = Liquid::Template.parse(to_render).render(liquid_env) + + +print(rendered) diff --git a/.github/workflows/pushes.yml b/.github/workflows/pushes.yml index 6dc8d81b0d..df2c2d3849 100644 --- a/.github/workflows/pushes.yml +++ b/.github/workflows/pushes.yml @@ -28,14 +28,15 @@ jobs: - name: Check Environment run: .ci/check-environment.sh shell: bash - - name: build + - name: Build run: .ci/build.sh shell: bash env: + MAVEN_OPTS: -Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }} PMD_CI_JOB_URL: "https://github.com/pmd/pmd/runs/${{ github.run_id }}" PMD_CI_PUSH_COMMIT_COMPARE: ${{ github.event.compare }} - PMD_CI_BRANCH: ${{ github.ref }} + PMD_CI_GIT_REF: ${{ github.ref }} windows: runs-on: windows-latest diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index cc031398c6..2948cb6653 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -13,11 +13,12 @@ jobs: - name: Check Environment run: .ci/check-environment.sh shell: bash - - name: Install OpenJDK 11 - run: .ci/install-openjdk.sh 11 - shell: bash - - name: Run Release Script - run: .ci/release.sh + - name: Build + run: .ci/build.sh shell: bash env: + MAVEN_OPTS: -Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 PMD_CI_SECRET_PASSPHRASE: ${{ secrets.PMD_CI_SECRET_PASSPHRASE }} + PMD_CI_JOB_URL: "https://github.com/pmd/pmd/runs/${{ github.run_id }}" + PMD_CI_PUSH_COMMIT_COMPARE: ${{ github.event.compare }} + PMD_CI_GIT_REF: ${{ github.ref }} diff --git a/docs/sitemap_generator.sh b/docs/sitemap_generator.sh new file mode 100755 index 0000000000..03e25a0bcf --- /dev/null +++ b/docs/sitemap_generator.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# Sitemap generator for pmd.github.io main landing page. +# Assumes we have the latest version of the site under "latest" +# https://www.sitemaps.org/protocol.html + +WEBSITE_PREFIX="https://pmd.github.io/" +DOC_PREFIX="latest/" +DATE=`date +%Y-%m-%d` +# Priority is relative to the website, can be chosen in {0.1, 0.2, ..., 1} +# Default priority is 0.5 +LATEST_PRIORITY=0.8 + + +# Writes to standard output + +cat << HEADER_END + + + + + ${WEBSITE_PREFIX}index.html + 1 + monthly + $DATE + + + + ${WEBSITE_PREFIX}${DOC_PREFIX}index.html + 0.9 + monthly + $DATE + + + + +HEADER_END + + +for page in ${DOC_PREFIX}pmd_*.html +do + + cat << ENTRY_END + + ${WEBSITE_PREFIX}$page + $LATEST_PRIORITY + monthly + $DATE + + +ENTRY_END + +done + +echo "" +