|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -source $(dirname $0)/inc/github-releases-api.bash || exit 1 |
4 | | - |
5 | 3 | # Exit this script immediately if a command/function exits with a non-zero status. |
6 | 4 | set -e |
7 | 5 |
|
8 | | -function build() { |
9 | | - fetch_ci_scripts |
| 6 | +SCRIPT_INCLUDES="log.bash utils.bash setup-secrets.bash openjdk.bash maven.bash sourceforge-api.bash github-releases-api.bash" |
| 7 | +# shellcheck source=inc/fetch_ci_scripts.bash |
| 8 | +source "$(dirname "$0")/inc/fetch_ci_scripts.bash" && fetch_ci_scripts |
10 | 9 |
|
11 | | - log_group_start "Install OpenJDK" |
| 10 | +function build() { |
| 11 | + pmd_ci_log_group_start "Install OpenJDK" |
12 | 12 | pmd_ci_openjdk_install_adoptopenjdk 8 |
13 | 13 | pmd_ci_openjdk_setdefault 8 |
14 | | - log_group_end |
| 14 | + pmd_ci_log_group_end |
15 | 15 |
|
16 | | - log_group_start "Install xvfb" |
| 16 | + pmd_ci_log_group_start "Install xvfb" |
17 | 17 | #see https://github.com/GabrielBB/xvfb-action |
18 | 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 |
| 19 | + sudo apt-get install --yes libgtk2.0-0 |
| 20 | + pmd_ci_log_group_end |
27 | 21 |
|
28 | 22 | 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 |
| 23 | + pmd_ci_maven_display_info_banner |
| 24 | + pmd_ci_utils_determine_build_env pmd/pmd-eclipse-plugin |
35 | 25 | echo |
36 | 26 |
|
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 |
| 27 | + if pmd_ci_utils_is_fork_or_pull_request; then |
| 28 | + pmd_ci_log_group_start "Build with mvnw" |
| 29 | + xvfb-run --auto-servernum ./mvnw clean verify --show-version --errors --batch-mode --no-transfer-progress |
| 30 | + pmd_ci_log_group_end |
41 | 31 | exit 0 |
42 | 32 | fi |
43 | 33 |
|
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 |
| 34 | + # stop early for invalid maven version and branch/tag combination |
| 35 | + pmd_ci_maven_verify_version || exit 0 |
| 36 | + |
| 37 | + # only builds on pmd/pmd-eclipse-plugin continue here |
| 38 | + pmd_ci_log_group_start "Setup environment" |
| 39 | + pmd_ci_setup_secrets_private_env |
| 40 | + pmd_ci_setup_secrets_ssh |
49 | 41 | pmd_ci_maven_setup_settings |
50 | | - log_group_end |
| 42 | + pmd_ci_log_group_end |
| 43 | + |
| 44 | + if pmd_ci_maven_isSnapshotBuild; then |
| 45 | + snapshot_build |
| 46 | + elif pmd_ci_maven_isReleaseBuild; then |
| 47 | + release_build |
| 48 | + else |
| 49 | + pmd_ci_log_error "Invalid combination: version=${PMD_CI_MAVEN_PROJECT_VERSION} branch=${PMD_CI_BRANCH} tag=${PMD_CI_TAG}" |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +} |
| 53 | + |
| 54 | +function snapshot_build() { |
| 55 | + pmd_ci_log_group_start "Snapshot Build: ${PMD_CI_MAVEN_PROJECT_VERSION}" |
| 56 | + pmd_ci_log_info "This is a snapshot build on branch ${PMD_CI_BRANCH} (version: ${PMD_CI_MAVEN_PROJECT_VERSION})" |
51 | 57 |
|
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})" |
| 58 | + # Build and upload the update site to Bintray |
| 59 | + xvfb-run --auto-servernum ./mvnw clean verify --show-version --errors --batch-mode \ |
| 60 | + --no-transfer-progress \ |
| 61 | + --activate-profiles snapshot-properties,release-composite |
55 | 62 |
|
56 | | - # Uploading the update site to Bintray |
57 | | - xvfb-run --auto-servernum ./mvnw clean verify -B -V -e -Psnapshot-properties -Prelease-composite |
| 63 | + local qualifiedVersion |
| 64 | + qualifiedVersion="$(basename net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-*.zip)" |
| 65 | + qualifiedVersion="${qualifiedVersion%.zip}" |
| 66 | + qualifiedVersion="${qualifiedVersion#net.sourceforge.pmd.eclipse.p2updatesite-}" |
| 67 | + mv "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${qualifiedVersion}.zip" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-SNAPSHOT.zip" |
| 68 | + pmd_ci_sourceforge_uploadFile "pmd-eclipse/zipped" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-SNAPSHOT.zip" |
58 | 69 |
|
59 | 70 | # Cleanup old snapshots |
60 | 71 | ( |
61 | 72 | cd net.sourceforge.pmd.eclipse.p2updatesite |
62 | 73 | ./cleanup-bintray-snapshots.sh |
63 | 74 | ) |
64 | | - log_group_end |
| 75 | + pmd_ci_log_group_end |
65 | 76 |
|
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})" |
| 77 | + pmd_ci_log_group_start "Add snapshot to update site" |
| 78 | + pmd_ci_log_info "Updating pmd-eclipse-plugin-p2-site..." |
| 79 | + prepare_local_p2_site |
| 80 | + ( |
| 81 | + cd current-p2-site |
| 82 | + |
| 83 | + rm -rf snapshot |
| 84 | + unzip -q -d snapshot "../net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-SNAPSHOT.zip" |
| 85 | + echo "This is a Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/) ${PMD_CI_MAVEN_PROJECT_VERSION}. |
| 86 | +
|
| 87 | +Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/snapshot/> to install the plugin with the Eclipse Update Manager. |
| 88 | +
|
| 89 | +<dl> |
| 90 | + <dt>Feature ID</dt> |
| 91 | + <dd>net.sourceforge.pmd.eclipse</dd> |
| 92 | + <dt>Version</dt> |
| 93 | + <dd>${qualifiedVersion}</dd> |
| 94 | +</dl> |
| 95 | +
|
| 96 | +" > snapshot/index.md |
| 97 | + git add snapshot |
| 98 | + |
| 99 | + # create a new single commit |
| 100 | + git checkout --orphan=gh-pages-2 |
| 101 | + git commit -a -m "Update pmd/pmd-eclipse-plugin-p2-site" |
| 102 | + git push --force origin gh-pages-2:gh-pages |
| 103 | + pmd_ci_log_success "Successfully updated https://pmd.github.io/pmd-eclipse-plugin-p2-site/" |
| 104 | + ) |
69 | 105 |
|
| 106 | + pmd_ci_log_group_end |
| 107 | +} |
| 108 | + |
| 109 | +function release_build() { |
| 110 | + pmd_ci_log_group_start "Release Build: ${PMD_CI_MAVEN_PROJECT_VERSION}" |
| 111 | + pmd_ci_log_info "This is a release build for tag ${PMD_CI_TAG} (version: ${PMD_CI_MAVEN_PROJECT_VERSION})" |
| 112 | + |
| 113 | + # Build and deploy the update site to bintray |
| 114 | + xvfb-run --auto-servernum ./mvnw clean verify --show-version --errors --batch-mode \ |
| 115 | + --no-transfer-progress \ |
| 116 | + --activate-profiles release-composite |
| 117 | + pmd_ci_log_group_end |
| 118 | + |
| 119 | + pmd_ci_log_group_start "Update Github Releases" |
70 | 120 | # create a draft github release |
71 | | - gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 ${PMD_CI_TAG})" |
| 121 | + pmd_ci_gh_releases_createDraftRelease "${PMD_CI_TAG}" "$(git rev-list -n 1 "${PMD_CI_TAG}")" |
72 | 122 | GH_RELEASE="$RESULT" |
73 | 123 |
|
74 | | - # Deploy the update site to bintray |
75 | | - xvfb-run --auto-servernum ./mvnw clean verify -B -V -e -Prelease-composite |
76 | | - |
77 | 124 | # Deploy to github releases |
78 | | - gh_release_uploadAsset "$GH_RELEASE" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${version}.zip" |
| 125 | + pmd_ci_gh_releases_uploadAsset "$GH_RELEASE" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" |
79 | 126 |
|
80 | 127 | # extract the release notes |
81 | | - RELEASE_NAME="PMD For Eclipse ${version} ($(date -u +%d-%B-%Y))" |
| 128 | + RELEASE_NAME="PMD For Eclipse ${PMD_CI_MAVEN_PROJECT_VERSION}" |
82 | 129 | BEGIN_LINE=$(grep -n "^## " ReleaseNotes.md|head -1|cut -d ":" -f 1) |
83 | 130 | END_LINE=$(grep -n "^## " ReleaseNotes.md|head -2|tail -1|cut -d ":" -f 1) |
84 | 131 | END_LINE=$((END_LINE - 1)) |
85 | 132 |
|
86 | 133 | 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/ |
| 134 | +It is available via the update site: https://pmd.github.io/pmd-eclipse-plugin-p2-site/ |
88 | 135 |
|
89 | | -$(cat ReleaseNotes.md|head -$END_LINE|tail -$((END_LINE - BEGIN_LINE))) |
| 136 | +$(head -$END_LINE ReleaseNotes.md | tail -$((END_LINE - BEGIN_LINE))) |
90 | 137 | " |
91 | 138 |
|
92 | | - gh_release_updateRelease "$GH_RELEASE" "$RELEASE_NAME" "$RELEASE_BODY" |
| 139 | + pmd_ci_gh_releases_updateRelease "$GH_RELEASE" "$RELEASE_NAME" "$RELEASE_BODY" |
93 | 140 |
|
94 | | - # Publish release |
95 | | - gh_release_publishRelease "$GH_RELEASE" |
| 141 | + # Upload it to sourceforge |
| 142 | + pmd_ci_sourceforge_uploadFile "pmd-eclipse/zipped" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" |
96 | 143 |
|
97 | | - log_group_end |
| 144 | + # Create sourceforge blog entry |
| 145 | + pmd_ci_sourceforge_createDraftBlogPost "$RELEASE_NAME released" "$RELEASE_BODY" "pmd-eclipse-plugin,release" |
| 146 | + local sf_blog_url="${RESULT}" |
| 147 | + pmd_ci_log_group_end |
98 | 148 |
|
99 | | - else |
100 | | - log_error "Invalid combination: version=${version} branch=${PMD_CI_BRANCH} tag=${PMD_CI_TAG}" |
101 | | - exit 1 |
102 | | - fi |
| 149 | + pmd_ci_log_group_start "Add new release to update site" |
| 150 | + pmd_ci_log_info "Updating pmd-eclipse-plugin-p2-site..." |
| 151 | + prepare_local_p2_site |
| 152 | + ( |
| 153 | + cd current-p2-site |
| 154 | + |
| 155 | + unzip -q -d "${PMD_CI_MAVEN_PROJECT_VERSION}" "net.sourceforge.pmd.eclipse.p2updatesite/target/net.sourceforge.pmd.eclipse.p2updatesite-${PMD_CI_MAVEN_PROJECT_VERSION}.zip" |
| 156 | + git add "${PMD_CI_MAVEN_PROJECT_VERSION}" |
| 157 | + regenerate_metadata |
| 158 | + |
| 159 | + # create a new single commit |
| 160 | + git checkout --orphan=gh-pages-2 |
| 161 | + git commit -a -m "Update pmd/pmd-eclipse-plugin-p2-site" |
| 162 | + git push --force origin gh-pages-2:gh-pages |
| 163 | + pmd_ci_log_success "Successfully updated https://pmd.github.io/pmd-eclipse-plugin-p2-site/" |
| 164 | + ) |
| 165 | + pmd_ci_log_group_end |
| 166 | + |
| 167 | + # Publish release - this sends out notifications on github |
| 168 | + pmd_ci_gh_releases_publishRelease "$GH_RELEASE" |
| 169 | + # Publish sourceforge blog entry |
| 170 | + pmd_ci_sourceforge_publishBlogPost "${sf_blog_url}" |
103 | 171 | } |
104 | 172 |
|
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 |
| 173 | + |
| 174 | +function prepare_local_p2_site() { |
| 175 | + pmd_ci_log_info "Preparing local copy of p2-site..." |
| 176 | + rm -rf current-p2-site |
| 177 | + mkdir current-p2-site |
| 178 | + ( |
| 179 | + cd current-p2-site |
| 180 | + git init -q --initial-branch=gh-pages |
| 181 | + git config user.name "PMD CI (pmd-bot)" |
| 182 | + git config user.email "[email protected]" |
| 183 | + git remote add origin [email protected]:pmd/pmd-eclipse-plugin-p2-site.git |
| 184 | + git pull --rebase origin gh-pages |
| 185 | + ) |
| 186 | +} |
| 187 | + |
| 188 | +function regenerate_metadata() { |
| 189 | + pmd_ci_log_info "Regenerating metadata for p2-site..." |
| 190 | + local releases=($(find . -maxdepth 1 -type d -regex "\./[0-9]+\.[0-9]+\.[0-9]+\..*" -printf '%f\n'| tr '.' '\0' | sort -t '\0' -k1,1nr -k2,2nr -k3,3nr -k4dr |awk -F '\0' '{printf "%s.%s.%s.%s\n", $1, $2, $3, $4}')) |
| 191 | + # remove old releases |
| 192 | + for i in "${releases[@]:5}"; do |
| 193 | + pmd_ci_log_info "Removing old release $i..." |
| 194 | + rm -rf "$i" |
| 195 | + done |
| 196 | + releases=("${releases[@]:0:5}") |
| 197 | + |
| 198 | + # regenerate metadata |
| 199 | + local now |
| 200 | + now=$(date +%s000) |
| 201 | + local children="" |
| 202 | + local children_index="" |
| 203 | + for i in "${releases[@]}"; do |
| 204 | + children="${children} <child location=\"$i\"/>\n" |
| 205 | + children_index="${children_index} * [$i]($i/)\n" |
| 206 | + echo "This is a Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/) ${i}. |
| 207 | +
|
| 208 | +Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/${i}/> to install the plugin with the Eclipse Update Manager. |
| 209 | +
|
| 210 | +<dl> |
| 211 | + <dt>Feature ID</dt> |
| 212 | + <dd>net.sourceforge.pmd.eclipse</dd> |
| 213 | + <dt>Version</dt> |
| 214 | + <dd>${i}</dd> |
| 215 | +</dl> |
| 216 | +
|
| 217 | +" > "$i"/index.md |
| 218 | + |
| 219 | + git add "$i"/index.md |
119 | 220 | done |
| 221 | + |
| 222 | + local site_name="PMD for Eclipse - Update Site" |
| 223 | + local artifactsTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
| 224 | +<?compositeArtifactRepository version=\"1.0.0\"?> |
| 225 | +<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository\" version=\"1.0.0\"> |
| 226 | + <properties size=\"2\"> |
| 227 | + <property name=\"p2.timestamp\" value=\"${now}\"/> |
| 228 | + <property name=\"p2.atomic.composite.loading\" value=\"true\"/> |
| 229 | + </properties> |
| 230 | + <children size=\"${#releases[@]}\"> |
| 231 | +${children} </children> |
| 232 | +</repository>" |
| 233 | + echo -e "${artifactsTemplate}" > compositeArtifacts.xml |
| 234 | + |
| 235 | + local contentTemplate="<?xml version=\"1.0\" encoding=\"UTF-8\"?> |
| 236 | +<?compositeMetadataRepository version=\"1.0.0\"?> |
| 237 | +<repository name=\"${site_name}\" type=\"org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository\" version=\"1.0.0\"> |
| 238 | + <properties size=\"2\"> |
| 239 | + <property name=\"p2.timestamp\" value=\"${now}\"/> |
| 240 | + <property name=\"p2.atomic.composite.loading\" value=\"true\"/> |
| 241 | + </properties> |
| 242 | + <children size=\"${#releases[@]}\"> |
| 243 | +${children} </children> |
| 244 | +</repository>" |
| 245 | + echo -e "${contentTemplate}" > compositeContent.xml |
| 246 | + |
| 247 | + # p2.index |
| 248 | + local p2_index="version = 1 |
| 249 | +metadata.repository.factory.order = compositeContent.xml,\! |
| 250 | +artifact.repository.factory.order = compositeArtifacts.xml,\!" |
| 251 | + echo -e "${p2_index}" > p2.index |
| 252 | + |
| 253 | + # regenerate index.md |
| 254 | + echo -e "This is a composite Eclipse Update Site for the [PMD Eclipse Plugin](https://github.com/pmd/pmd-eclipse-plugin/). |
| 255 | +
|
| 256 | +Use <https://pmd.github.io/pmd-eclipse-plugin-p2-site/> to install the plugin with the Eclipse Update Manager. |
| 257 | +
|
| 258 | +---- |
| 259 | +
|
| 260 | +Versions available at <https://pmd.github.io/pmd-eclipse-plugin-p2-site/>: |
| 261 | +
|
| 262 | +${children_index} |
| 263 | +
|
| 264 | +For older versions, see <https://sourceforge.net/projects/pmd/files/pmd-eclipse/zipped/> |
| 265 | +
|
| 266 | +" > index.md |
120 | 267 | } |
121 | 268 |
|
122 | 269 | build |
0 commit comments