From daf94ed7b9984f55df03034ababccaba4547a953 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Fri, 15 Feb 2019 08:41:46 -0600 Subject: [PATCH] #815 - Make releases from Concourse. Related to #814. --- ci/README.adoc | 20 +++- ci/create-release.sh | 21 +++++ ci/pipeline-template.yml | 178 ++++++++++++++++++++++++++++++++++- ci/promote-to-bintray.sh | 46 +++++++++ ci/promote-to-bintray.yml | 19 ++++ ci/sync-to-maven-central.sh | 24 +++++ ci/sync-to-maven-central.yml | 21 +++++ 7 files changed, 323 insertions(+), 6 deletions(-) create mode 100755 ci/create-release.sh create mode 100755 ci/promote-to-bintray.sh create mode 100644 ci/promote-to-bintray.yml create mode 100755 ci/sync-to-maven-central.sh create mode 100644 ci/sync-to-maven-central.yml diff --git a/ci/README.adoc b/ci/README.adoc index a8d9d2b8..acacb860 100644 --- a/ci/README.adoc +++ b/ci/README.adoc @@ -27,7 +27,7 @@ WARNING: Do NOT check this file into source control! If you'll check, `credentia With this in place, run the following `fly` commands to create pipelines: ---- -% fly -t spring-data sp -p spring-hateoas -c ci/pipeline-template.yml -l credentials.yml -v branch=master +% fly -t spring-data sp -p spring-hateoas -c ci/pipeline-template.yml -l credentials.yml -v branch=master -v release-branch=release ---- With this pipeline in place, you can now activate and expose it: @@ -35,4 +35,20 @@ With this pipeline in place, you can now activate and expose it: ---- % fly -t spring-data unpause-pipeline -p spring-hateoas % fly -t spring-data expose-pipeline -p spring-hateoas ----- \ No newline at end of file +---- + +=== Making a release + +1. Create a new release (on the main branch). +---- +% ci/create-release.sh +---- + +2. With the release tagged, push the tagged version to the release branch. +---- +% git checkout -b release +% git reset --hard +% git push -f origin release +---- + +NOTE: You can chain the previous set of commands together using `&&`. \ No newline at end of file diff --git a/ci/create-release.sh b/ci/create-release.sh new file mode 100755 index 00000000..bca253d2 --- /dev/null +++ b/ci/create-release.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail + +RELEASE=$1 +SNAPSHOT=$2 + +# Bump up the version in pom.xml to the desired version and commit the change +./mvnw versions:set -DnewVersion=$RELEASE -DgenerateBackupPoms=false +git add . +git commit --message "Releasing Spring HATEOAS v$RELEASE" + +# Tag the release +git tag -s v$RELEASE -m "v$RELEASE" + +# Bump up the version in pom.xml to the next snapshot +./mvnw versions:set -DnewVersion=$SNAPSHOT -DgenerateBackupPoms=false +git add . +git commit --message "Continue development on v$SNAPSHOT" + + diff --git a/ci/pipeline-template.yml b/ci/pipeline-template.yml index a7017734..587ca8ff 100644 --- a/ci/pipeline-template.yml +++ b/ci/pipeline-template.yml @@ -63,6 +63,12 @@ resources: repo: spring-projects/spring-hateoas base: ((branch)) +- name: spring-hateoas-release + type: git + source: + uri: https://github.com/spring-projects/spring-hateoas.git + branch: ((release-branch)) + - name: spring-hateoas-status type: github-status source: @@ -85,6 +91,11 @@ groups: - name: pull-requests jobs: - spring-hateoas-pull-requests +- name: release + jobs: + - release-to-artifactory +# - promote-to-bintray +# - sync-to-maven-central jobs: - name: Test - JDK 8 @@ -98,7 +109,7 @@ jobs: - task: test file: spring-hateoas-github/ci/test.yml params: { PROFILE: "non-existent" } - <<: *slack-failure + <<: *slack-test-failure - name: Test - JDK 11 serial: true @@ -112,7 +123,7 @@ jobs: image: openjdk:11-jdk file: spring-hateoas-github/ci/test.yml params: { PROFILE: "non-existant" } - <<: *slack-failure + <<: *slack-test-failure - name: Test - JDK 13 serial: true @@ -126,7 +137,7 @@ jobs: image: openjdk:13-jdk file: spring-hateoas-github/ci/test.yml params: { PROFILE: "non-existant" } - <<: *slack-failure + <<: *slack-test-failure - name: Build serial: true @@ -242,7 +253,166 @@ jobs: title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME -slack-failure: &slack-failure +- name: release-to-artifactory + serial: true + public: true + plan: + - get: spring-hateoas-github + resource: spring-hateoas-release + trigger: true + - put: spring-hateoas-status + params: + commit: spring-hateoas-release + state: pending + - task: build + file: spring-hateoas-github/ci/build.yml + - put: spring-hateoas-artifactory + params: + build_number: ${BUILD_NAME} + build_uri: ${ATC_EXTERNAL_URL}/teams/${BUILD_TEAM_NAME}/pipelines/${BUILD_PIPELINE_NAME}/jobs/${BUILD_JOB_NAME}/builds/${BUILD_NAME} + repo: libs-milestone-local + folder: spring-hateoas-artifactory + artifact_set: + - include: + - "/**" + properties: + zip.deployed: false + zip.displayname: "Spring HATEOAS" + zip.name: "spring-hateoas" + zip.type: "docs" + on_failure: + aggregate: + - put: spring-hateoas-status + params: + commit: spring-hateoas-github + state: failure + - put: slack + params: + attachments: + - color: danger + fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " + text: "Releasing to artifactory has failed" + title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" + title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME + on_success: + aggregate: + - put: spring-hateoas-status + params: + commit: spring-hateoas-github + state: success + - put: slack + params: + attachments: + - color: good + fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " + text: "Releasing to artifactory has succeeded!" + title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" + title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME + +#- name: promote-to-bintray +# serial: true +# plan: +# - get: spring-hateoas-github +# resource: spring-hateoas-release +# - get: spring-hateoas-artifactory +# trigger: true +# passed: [release-to-artifactory] +# params: +# save_build_info: true +# - task: promote-to-bintray +# file: spring-hateoas-github/ci/promote-to-bintray.yml +# params: +# ARTIFACTORY_USERNAME: ((artifactory-username)) +# ARTIFACTORY_PASSWORD: ((artifactory-password)) +# on_failure: +# aggregate: +# - put: spring-hateoas-status +# params: +# commit: spring-hateoas-github +# state: failure +# - put: slack +# params: +# attachments: +# - color: danger +# fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " +# text: "Promoting to bintray has failed" +# title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" +# title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME +# on_success: +# aggregate: +# - put: spring-hateoas-status +# params: +# commit: spring-hateoas-github +# state: success +# - put: slack +# params: +# attachments: +# - color: good +# fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " +# text: "Promoting to bintray has succeeded!" +# title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" +# title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME + +#- name: sync-to-maven-central +# serial: true +# plan: +# - get: spring-hateoas-github +# resource: spring-hateoas-release +# - get: spring-hateoas-artifactory +# trigger: true +# passed: [promote-to-bintray] +# params: +# save_build_info: true +# - task: sync-to-maven-central +# file: spring-hateoas-github/ci/sync-to-maven-central.yml +# params: +# BINTRAY_USERNAME: ((bintray-username)) +# BINTRAY_API_KEY: ((bintray-api-key)) +# SONATYPE_USER_TOKEN: ((sonatype-user-token)) +# SONATYPE_PASSWORD_TOKEN: ((sonatype-user-token-password)) +# ARTIFACTORY_USERNAME: ((artifactory-username)) +# ARTIFACTORY_PASSWORD: ((artifactory-password)) +# on_failure: +# aggregate: +# - put: spring-hateoas-status +# params: +# commit: spring-hateoas-github +# state: failure +# - put: slack +# params: +# attachments: +# - color: danger +# fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " +# text: "Syncing to maven central has failed" +# title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" +# title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME +# on_success: +# aggregate: +# - put: spring-hateoas-status +# params: +# commit: spring-hateoas-github +# state: success +# - put: slack +# params: +# attachments: +# - color: good +# fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " +# text: "Syncing to maven central has succeeded!" +# title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" +# title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME +# +slack-test-success: &slack-test-success + on_success: + put: slack + params: + attachments: + - color: good + fallback: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME " + text: "Test has succeeded" + title: "$BUILD_PIPELINE_NAME/$BUILD_JOB_NAME #$BUILD_NAME" + title_link: $ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME + +slack-test-failure: &slack-test-failure on_failure: put: slack params: diff --git a/ci/promote-to-bintray.sh b/ci/promote-to-bintray.sh new file mode 100755 index 00000000..e7af261b --- /dev/null +++ b/ci/promote-to-bintray.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -e -u + +apt-get update +apt-get install -y jq + +buildName=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.name' ) +buildNumber=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.number' ) +groupId=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/\(.*\):.*:.*/\1/' ) +version=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/.*:.*:\(.*\)/\1/' ) +targetRepo="libs-release-local" + +echo "Promoting ${buildName}/${buildNumber} to ${targetRepo}" + +curl \ + -s \ + --connect-timeout 240 \ + --max-time 2700 \ + -u ${ARTIFACTORY_USERNAME}:${ARTIFACTORY_PASSWORD} \ + -H "Content-type:application/json" \ + -d "{\"sourceRepos\": [\"libs-release-local\"], \"targetRepo\" : \"spring-distributions\", \"async\":\"true\"}" \ + -f \ + -X \ + POST "https://repo.spring.io/api/build/distribute/${buildName}/${buildNumber}" > /dev/null || { echo "Failed to distribute" >&2; exit 1; } + +echo "Waiting for artifacts to be published" + +ARTIFACTS_PUBLISHED=false +WAIT_TIME=10 +COUNTER=0 + +while [ $ARTIFACTS_PUBLISHED == "false" ] && [ $COUNTER -lt 120 ]; do + + result=$( curl -s https://api.bintray.com/packages/spring/jars/"${groupId}" ) + versions=$( echo "$result" | jq -r '.versions' ) + exists=$( echo "$versions" | grep "$version" -o || true ) + + if [ "$exists" = "$version" ]; then + ARTIFACTS_PUBLISHED=true + fi + + COUNTER=$(( COUNTER + 1 )) + sleep $WAIT_TIME + +done diff --git a/ci/promote-to-bintray.yml b/ci/promote-to-bintray.yml new file mode 100644 index 00000000..ed41c054 --- /dev/null +++ b/ci/promote-to-bintray.yml @@ -0,0 +1,19 @@ +--- +platform: linux + +image_resource: + type: docker-image + source: + repository: openjdk + tag: 8-jdk + +inputs: +- name: spring-hateoas-artifactory +- name: spring-hateoas-github + +run: + path: spring-hateoas-github/ci/promote-to-bintray.sh + +params: + ARTIFACTORY_USERNAME: + ARTIFACTORY_PASSWORD: diff --git a/ci/sync-to-maven-central.sh b/ci/sync-to-maven-central.sh new file mode 100755 index 00000000..2d5a5c16 --- /dev/null +++ b/ci/sync-to-maven-central.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e -u + +apt-get update +apt-get install -y jq + +buildName=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.name' ) +buildNumber=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.number' ) +groupId=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/\(.*\):.*:.*/\1/' ) +version=$( cat spring-hateoas-artifactory/build-info.json | jq -r '.buildInfo.modules[0].id' | sed 's/.*:.*:\(.*\)/\1/' ) + +echo "Syncing ${buildName}/${buildNumber} to Maven Central" + curl \ + -s \ + --connect-timeout 240 \ + --max-time 2700 \ + -u ${BINTRAY_USERNAME}:${BINTRAY_API_KEY} \ + -H "Content-Type: application/json" -d "{ \"username\": \"${SONATYPE_USER_TOKEN}\", \"password\": \"${SONATYPE_PASSWORD_TOKEN}\"}" \ + -f \ + -X \ + POST "https://api.bintray.com/maven_central_sync/spring/jars/${groupId}/versions/${version}" > /dev/null || { echo "Failed to sync" >&2; exit 1; } + +echo "Sync complete" diff --git a/ci/sync-to-maven-central.yml b/ci/sync-to-maven-central.yml new file mode 100644 index 00000000..d72b2227 --- /dev/null +++ b/ci/sync-to-maven-central.yml @@ -0,0 +1,21 @@ +--- +platform: linux + +image_resource: + type: docker-image + source: + repository: openjdk + tag: 8-jdk + +inputs: +- name: spring-hateoas-artifactory +- name: spring-hateoas-github + +run: + path: spring-hateoas-github/ci/sync-to-maven-central.sh + +params: + BINTRAY_USERNAME: + BINTRAY_API_KEY: + SONATYPE_USER_TOKEN: + SONATYPE_PASSWORD_TOKEN: