|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +source $(dirname $0)/inc/github-releases-api.bash || exit 1 |
| 4 | + |
| 5 | +# Exit this script immediately if a command/function exits with a non-zero status. |
| 6 | +set -e |
| 7 | + |
| 8 | +function build() { |
| 9 | + fetch_ci_scripts |
| 10 | + |
| 11 | + log_group_start "Install OpenJDK" |
| 12 | + pmd_ci_openjdk_install_adoptopenjdk 8 |
| 13 | + pmd_ci_openjdk_setdefault 8 |
| 14 | + log_group_end |
| 15 | + |
| 16 | + log_group_start "Install xvfb" |
| 17 | + #see https://github.com/GabrielBB/xvfb-action |
| 18 | + sudo apt-get install --yes xvfb |
| 19 | + log_group_end |
| 20 | + |
| 21 | + log_group_start "Determine project name + version" |
| 22 | + pmd_ci_maven_get_project_name |
| 23 | + local name="${RESULT}" |
| 24 | + pmd_ci_maven_get_project_version |
| 25 | + local version="${RESULT}" |
| 26 | + log_group_end |
| 27 | + |
| 28 | + echo |
| 29 | + echo |
| 30 | + log_info "=======================================================================" |
| 31 | + log_info "Building ${name} ${version}" |
| 32 | + log_info "=======================================================================" |
| 33 | + pmd_ci_determine_build_env pmd/pmd-eclipse-plugin |
| 34 | + echo |
| 35 | + echo |
| 36 | + |
| 37 | + if pmd_ci_is_fork_or_pull_request; then |
| 38 | + log_group_start "Build with mvnw" |
| 39 | + xvfb-run --auto-servernum ./mvnw clean verify -B -V -e |
| 40 | + log_group_end |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + |
| 44 | + # only builds on pmd/build-tools continue here |
| 45 | + log_group_start "Setup environment" |
| 46 | + # PMD_SF_USER, BINTRAY_USER, BINTRAY_APIKEY, GITHUB_OAUTH_TOKEN, GITHUB_BASE_URL |
| 47 | + pmd_ci_secrets_load_private_env |
| 48 | + pmd_ci_secrets_setup_ssh |
| 49 | + pmd_ci_maven_setup_settings |
| 50 | + log_group_end |
| 51 | + |
| 52 | + if [[ "${version}" == *-SNAPSHOT && "${PMD_CI_BRANCH}" != "" ]]; then |
| 53 | + log_group_start "Snapshot Build: ${version}" |
| 54 | + log_info "This is a snapshot build on branch ${PMD_CI_BRANCH} (version: ${version})" |
| 55 | + |
| 56 | + # Uploading the update site to Bintray |
| 57 | + xvfb-run --auto-servernum ./mvnw verify -DskipTests -Psnapshot-properties -Prelease-composite |
| 58 | + |
| 59 | + # Cleanup old snapshots |
| 60 | + ( |
| 61 | + cd net.sourceforge.pmd.eclipse.p2updatesite |
| 62 | + ./cleanup-bintray-snapshots.sh |
| 63 | + ) |
| 64 | + log_group_end |
| 65 | + |
| 66 | + elif [[ "${version}" != *-SNAPSHOT && "${PMD_CI_TAG}" != "" ]]; then |
| 67 | + log_group_start "Release Build: ${version}" |
| 68 | + log_info "This is a release build for tag ${PMD_CI_TAG} (version: ${version})" |
| 69 | + |
| 70 | + # create a draft github release |
| 71 | + gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 ${PMD_CI_TAG})" |
| 72 | + GH_RELEASE="$RESULT" |
| 73 | + |
| 74 | + # Deploy the update site to bintray |
| 75 | + xvfb-run --auto-servernum ./mvnw clean verify -Prelease-composite |
| 76 | + |
| 77 | + # Deploy to github releases |
| 78 | + gh_release_uploadAsset "$GH_RELEASE" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${version}.zip" |
| 79 | + |
| 80 | + # extract the release notes |
| 81 | + RELEASE_NAME="PMD For Eclipse ${version} ($(date -u +%d-%B-%Y))" |
| 82 | + BEGIN_LINE=$(grep -n "^## " ReleaseNotes.md|head -1|cut -d ":" -f 1) |
| 83 | + END_LINE=$(grep -n "^## " ReleaseNotes.md|head -2|tail -1|cut -d ":" -f 1) |
| 84 | + END_LINE=$((END_LINE - 1)) |
| 85 | + |
| 86 | + RELEASE_BODY="A new PMD for Eclipse plugin version has been released. |
| 87 | +It is available via the update site: https://dl.bintray.com/pmd/pmd-eclipse-plugin/updates/ |
| 88 | +
|
| 89 | +$(cat ReleaseNotes.md|head -$END_LINE|tail -$((END_LINE - BEGIN_LINE))) |
| 90 | +" |
| 91 | + |
| 92 | + gh_release_updateRelease "$GH_RELEASE" "$RELEASE_NAME" "$RELEASE_BODY" |
| 93 | + |
| 94 | + # Publish release |
| 95 | + gh_release_publishRelease "$GH_RELEASE" |
| 96 | + |
| 97 | + log_group_end |
| 98 | + |
| 99 | + else |
| 100 | + log_error "Invalid combination: version=${version} branch=${PMD_CI_BRANCH} tag=${PMD_CI_TAG}" |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | +} |
| 104 | + |
| 105 | +function fetch_ci_scripts() { |
| 106 | + mkdir -p .ci/inc |
| 107 | + |
| 108 | + for f in \ |
| 109 | + logger.bash \ |
| 110 | + utils.bash \ |
| 111 | + openjdk.bash \ |
| 112 | + secrets.bash \ |
| 113 | + maven.bash \ |
| 114 | + ; do |
| 115 | + if [ ! -e .ci/inc/$f ]; then |
| 116 | + curl -sSL https://raw.githubusercontent.com/pmd/build-tools/master/.ci/inc/$f > .ci/inc/$f |
| 117 | + fi |
| 118 | + source .ci/inc/$f || exit 1 |
| 119 | + done |
| 120 | +} |
| 121 | + |
| 122 | +build |
0 commit comments