forked from Consensys/ethsigner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
void tryAddKnownHost(String hostUrl){ | ||
// ssh-keygen -F ${hostUrl} will fail (in bash that means status code != 0) if ${hostUrl} is not yet a known host | ||
def statusCode = sh script:"ssh-keygen -F ${hostUrl}", returnStatus:true | ||
if(statusCode != 0){ | ||
sh "mkdir -p ~/.ssh" | ||
sh "ssh-keyscan ${hostUrl} >> ~/.ssh/known_hosts" | ||
} | ||
} | ||
|
||
pipeline { | ||
agent { | ||
docker { image 'openjdk:11-jdk-stretch' } | ||
} | ||
parameters { | ||
string(name: 'BRANCH_NAME', defaultValue: 'master', description: '[MANDATORY] The name of the branch to create the release from') | ||
string(name: 'RELEASE_VERSION', defaultValue: '', description: '[OPTIONAL] When empty: defaults to the current project version') | ||
string(name: 'NEXT_VERSION', defaultValue: '', description: '[OPTIONAL] When empty: defaults to next patch version after current project version') | ||
} | ||
|
||
stages { | ||
stage('Release') { | ||
steps { | ||
sshagent( | ||
credentials: ['pegasys-admin-github-ssh-private-key'] | ||
) { | ||
withCredentials([ | ||
usernamePassword( | ||
credentialsId: 'pegasys-bintray', | ||
usernameVariable: 'BINTRAY_USER', | ||
passwordVariable: 'BINTRAY_KEY' | ||
) | ||
]) { | ||
withEnv([ | ||
'GIT_COMMITTER_NAME="PegaSys Admin"', | ||
'GIT_COMMITTER_EMAIL="[email protected]"', | ||
'GIT_AUTHOR_NAME="PegaSys Admin"', | ||
'GIT_AUTHOR_EMAIL="[email protected]"' | ||
]) { | ||
tryAddKnownHost('github.com') | ||
|
||
script{ | ||
releaseVersion = '' | ||
if( params.RELEASE_VERSION?.trim() ){ | ||
releaseVersion = "-Prelease.releaseVersion=${params.RELEASE_VERSION}" | ||
} | ||
|
||
nextVersion = '' | ||
if( params.NEXT_VERSION?.trim() ){ | ||
nextVersion = "-Prelease.newVersion=${params.NEXT_VERSION}" | ||
} | ||
} | ||
|
||
|
||
sh "./gradlew release -Prelease.useAutomaticVersion=true -Prelease.branch=${params.BRANCH_NAME} ${releaseVersion} ${nextVersion}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
void tryAddKnownHost(String hostUrl){ | ||
// ssh-keygen -F ${hostUrl} will fail (in bash that means status code != 0) if ${hostUrl} is not yet a known host | ||
def statusCode = sh script:"ssh-keygen -F ${hostUrl}", returnStatus:true | ||
if(statusCode != 0){ | ||
sh "mkdir -p ~/.ssh" | ||
sh "ssh-keyscan ${hostUrl} >> ~/.ssh/known_hosts" | ||
} | ||
} | ||
|
||
pipeline { | ||
agent { | ||
docker { image 'openjdk:11-jdk-stretch' } | ||
} | ||
parameters { | ||
string(name: 'TAG_NAME', defaultValue: '', description: '[MANDATORY] Name of the Tag to create the branch from') | ||
string(name: 'BRANCH_NAME', defaultValue: '', description: '[MANDATORY] The desired name of the new branch') | ||
} | ||
stages { | ||
stage('Release') { | ||
steps { | ||
sshagent( | ||
credentials: ['pegasys-admin-github-ssh-private-key'] | ||
) { | ||
withEnv([ | ||
'GIT_COMMITTER_NAME="PegaSys Admin"', | ||
'GIT_COMMITTER_EMAIL="[email protected]"', | ||
'GIT_AUTHOR_NAME="PegaSys Admin"', | ||
'GIT_AUTHOR_EMAIL="[email protected]"' | ||
]) { | ||
tryAddKnownHost('github.com') | ||
sh "./branch-from-tag.sh ${params.TAG_NAME} ${params.BRANCH_NAME}" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/sh -e | ||
|
||
# | ||
# Creates a new branch from a release tag, updating the gradle.properties version number. | ||
# | ||
# Assumed format of the version number: major.minor.bugfix | ||
# Assumed location of the version number: gradle.properties | ||
# | ||
# NOTE: Any additional markers after the bugfix (i.e. -RC2) will be lost. | ||
|
||
if [ -z "${1}" ] | ||
then | ||
echo "[ERROR] Missing required first argument of tag name" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${2}" ] | ||
then | ||
echo "[ERROR] Missing required second argument of branch name" | ||
exit 1 | ||
fi | ||
|
||
|
||
tag_name=${1} | ||
branch_name=${2} | ||
|
||
# Locally create a branch from the tag | ||
git checkout -b ${branch_name} ${tag_name} | ||
|
||
# extract the version from gradle.properties | ||
tag_version=$(grep "^version" gradle.properties | cut -d'=' -f2) | ||
|
||
# Assuming semantic naming format of major.minor.bugfix[-RC|-SNAPSHOT|-other] | ||
major_version=$(echo ${tag_version} | cut -d'.' -f1) | ||
minor_version=$(echo ${tag_version} | cut -d'.' -f2) | ||
bugfix_version=$(echo ${tag_version} | cut -d'.' -f3 | cut -d'-' -f1) | ||
|
||
# Increment the bugfix version that goes on the new branch | ||
branch_bugfix_version=$((${bugfix_version}+1)) | ||
|
||
# Reconstruct the version number for the branch | ||
branch_version="${major_version}.${minor_version}.${branch_bugfix_version}-SNAPSHOT" | ||
|
||
# Change the local gradle.properties version to branch version | ||
sed -i "s/${tag_version}/${branch_version}/g" gradle.properties | ||
|
||
# Update the Jenkins job default branch name. Use # as seperator so that branch name can include / | ||
sed -i "s#defaultValue: 'master'#defaultValue: '${branch_name}'#g" Jenkinsfile.release | ||
|
||
git commit -am"[Release Script] Updating version to ${branch_version}" | ||
git push --set-upstream origin ${branch_name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters