Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Validates that the local environment is ready to commence release process. |
| 4 | # ----------------------------------------------------------------------------- |
| 5 | |
| 6 | [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 |
| 7 | |
Ray Milkey | 13d3ae3 | 2017-01-03 15:00:04 -0800 | [diff] [blame] | 8 | dryRun=0 |
| 9 | if [ "${1}" == "--dry-run" ]; then |
| 10 | dryRun=1 |
| 11 | fi |
| 12 | |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 13 | GERRIT_USER=${GERRIT_USER:-$USER} |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 14 | WIKI_USER=${WIKI_USER:-$USER} |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 15 | |
| 16 | set -e |
| 17 | |
Thomas Vachuska | 6891884 | 2016-03-04 10:38:55 -0800 | [diff] [blame] | 18 | # Tests availability of the specified tools |
| 19 | function testTool { |
| 20 | trap "echo 'FAILED'" ERR |
| 21 | printf "Checking $1 availability... " |
| 22 | which -s $1 |
| 23 | echo "OK" |
| 24 | } |
| 25 | |
| 26 | # Tests availability of gerrit |
| 27 | function testGerritTool { |
| 28 | trap "echo 'FAILED'" ERR |
| 29 | printf "Checking gerrit... " |
| 30 | git review --version 2>/dev/null |
| 31 | echo "OK" |
| 32 | } |
| 33 | |
| 34 | # Tests availability of GPG or GPG2 |
| 35 | function testGpgTool { |
| 36 | trap "echo 'FAILED'" ERR |
| 37 | printf "Checking gpg or gpg2... " |
| 38 | which -s gpg || which -s gpg2 |
| 39 | echo "OK" |
| 40 | } |
| 41 | |
| 42 | # Tests Java version |
| 43 | function testJavaVersion { |
| 44 | trap "echo 'FAILED'" ERR |
| 45 | printf "Checking Java version... " |
| 46 | v=$(javac -version 2>&1 | grep 1.8.0_ | sed -e 's/.*1.8.0_\([0-9]*\).*/\1/g') |
Brian O'Connor | a317872 | 2016-03-10 15:44:27 -0800 | [diff] [blame] | 47 | test "$v" -ge 73 |
Thomas Vachuska | 6891884 | 2016-03-04 10:38:55 -0800 | [diff] [blame] | 48 | echo "OK" |
| 49 | } |
| 50 | |
| 51 | # Tests availability of the required tools |
| 52 | function testToolchain { |
pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 53 | for tool in bash python3 git java javac mvn tar; do |
Thomas Vachuska | 6891884 | 2016-03-04 10:38:55 -0800 | [diff] [blame] | 54 | testTool $tool; |
| 55 | done |
| 56 | testGerritTool |
| 57 | testGpgTool |
| 58 | testJavaVersion |
| 59 | } |
| 60 | |
| 61 | # Tests that the specified artifact dependency is not a snapshot version |
| 62 | function testArtifactDependency { |
| 63 | trap "echo 'FAILED'" ERR |
| 64 | printf "Checking $1 dependency... " |
| 65 | grep "<$1.version>.*</$1.version>" $ONOS_ROOT/pom.xml | grep -q SNAPSHOT && false |
| 66 | echo "OK" |
| 67 | } |
| 68 | |
| 69 | # Tests that the ONOS-base is not a snapshot version |
| 70 | function testOnosBase { |
| 71 | trap "echo 'FAILED'" ERR |
| 72 | printf "Checking onos-base dependency... " |
| 73 | grep -A1 "onos-base" $ONOS_ROOT/pom.xml | grep -q SNAPSHOT && false |
| 74 | echo "OK" |
| 75 | } |
| 76 | |
| 77 | # Tests that the root pom does not contain any snapshot dependencies |
| 78 | # on anxillary artifacts, e.g. openflowj, copycat |
| 79 | function testSnapshotDependencies { |
| 80 | testOnosBase |
| 81 | for artifact in onos-build-conf onos-maven-plugin openflowj atomix copycat; do |
| 82 | testArtifactDependency $artifact |
| 83 | done |
| 84 | } |
| 85 | |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 86 | # Test access to Gerrit (Administrator) |
| 87 | function testGerritAccess { |
| 88 | trap "echo 'FAILED'" ERR |
Brian O'Connor | 156c480 | 2016-03-02 15:50:38 -0800 | [diff] [blame] | 89 | printf "Checking Gerrit ONOS Release group access... " |
| 90 | ssh -p 29418 gerrit.onosproject.org gerrit ls-members "ONOS\ Release"\ |
| 91 | --recursive | grep -q $GERRIT_USER |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 92 | echo "OK" |
| 93 | } |
| 94 | |
Ray Milkey | 46b3e85 | 2017-09-05 19:41:15 -0700 | [diff] [blame] | 95 | # Test access to api.onosproject.org |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 96 | function testWikiAccess { |
| 97 | trap "echo 'FAILED'" ERR |
| 98 | printf "Checking Wiki access... " |
Ray Milkey | 46b3e85 | 2017-09-05 19:41:15 -0700 | [diff] [blame] | 99 | ssh $WIKI_USER@api.onosproject.org "test -w /var/www/api/index.html" |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 100 | echo "OK" |
| 101 | } |
| 102 | |
Ray Milkey | 4867af2 | 2018-08-10 16:52:28 -0700 | [diff] [blame] | 103 | # Test access to EC2 |
| 104 | function testEC2Access { |
| 105 | aux=$(mktemp) |
| 106 | trap "cat $aux; rm -f $aux; echo 'FAILED'" ERR |
| 107 | printf "Checking EC2 access... " |
| 108 | : "${AWS_ACCESS_KEY_ID:?AWS_ACCESS_KEY_ID must be set}" |
| 109 | : "${AWS_SECRET_ACCESS_KEY:?AWS_SECRET_ACCESS_KEY must be set}" |
| 110 | |
| 111 | uploadToS3.py -v 1>$aux 2>&1 |
| 112 | rm -f $aux |
| 113 | echo "OK" |
| 114 | } |
| 115 | |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 116 | # Sonatype account must be created & ~/.m2/settings.xml must be configured |
| 117 | # Test by "releasing" a fake project setup for that purpose to validate access. |
Brian O'Connor | d89bfd0 | 2016-11-22 15:39:49 -0800 | [diff] [blame] | 118 | function testSonatypeAccessMvn { |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 119 | aux=$(mktemp) |
| 120 | trap "cat $aux; rm -f $aux; echo 'FAILED'" ERR |
Brian O'Connor | d89bfd0 | 2016-11-22 15:39:49 -0800 | [diff] [blame] | 121 | printf "Checking Sonatype access via Maven... " |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 122 | pushd $ONOS_ROOT/tools/build/release-test >/dev/null |
| 123 | # TODO: Figure out how to supress the GPG note |
| 124 | mvn -Prelease clean deploy org.sonatype.plugins:nexus-staging-maven-plugin:drop \ |
| 125 | 1>$aux 2>&1 </dev/null |
| 126 | mvn clean >/dev/null |
| 127 | rm -f $aux |
| 128 | popd >/dev/null |
| 129 | echo "OK" |
| 130 | } |
| 131 | |
Brian O'Connor | d89bfd0 | 2016-11-22 15:39:49 -0800 | [diff] [blame] | 132 | function testSonatypeAccessRest { |
Ray Milkey | d6e2e44 | 2016-11-30 10:15:23 -0800 | [diff] [blame] | 133 | : "${SONATYPE_USER:?SONATYPE_USER must be set}" |
| 134 | : "${SONATYPE_PASSWORD:?SONATYPE_PASSWORD must be set}" |
Brian O'Connor | d89bfd0 | 2016-11-22 15:39:49 -0800 | [diff] [blame] | 135 | export ONOS_VERSION=1.2.3 |
| 136 | printf "Checking Sonatype access via REST... " |
| 137 | pushd $ONOS_ROOT/tools/build/release-test >/dev/null |
| 138 | #FIXME this won't work on Linux |
| 139 | md5 pom.xml > pom.xml.md5 |
| 140 | shasum pom.xml > pom.xml.sha1 |
| 141 | gpg --detach-sign --output pom.xml.asc pom.xml |
| 142 | # Upload the files to staging |
| 143 | curl -s -u$SONATYPE_USER:$SONATYPE_PASSWORD --upload-file pom.xml \ |
| 144 | https://oss.sonatype.org/service/local/staging/deploy/maven2/org/onosproject/onos-api/$ONOS_VERSION/onos-api-$ONOS_VERSION.pom |
| 145 | curl -s -u$SONATYPE_USER:$SONATYPE_PASSWORD --upload-file pom.xml.md5 \ |
| 146 | https://oss.sonatype.org/service/local/staging/deploy/maven2/org/onosproject/onos-api/$ONOS_VERSION/onos-api-$ONOS_VERSION.pom.md5 |
| 147 | curl -s -u$SONATYPE_USER:$SONATYPE_PASSWORD --upload-file pom.xml.sha1 \ |
| 148 | https://oss.sonatype.org/service/local/staging/deploy/maven2/org/onosproject/onos-api/$ONOS_VERSION/onos-api-$ONOS_VERSION.pom.sha1 |
| 149 | curl -s -u$SONATYPE_USER:$SONATYPE_PASSWORD --upload-file pom.xml.asc \ |
| 150 | https://oss.sonatype.org/service/local/staging/deploy/maven2/org/onosproject/onos-api/$ONOS_VERSION/onos-api-$ONOS_VERSION.pom.asc |
| 151 | rm pom.xml.md5 pom.xml.sha1 pom.xml.asc |
| 152 | onos-close-staging -d >/dev/null |
| 153 | popd >/dev/null |
| 154 | unset ONOS_VERSION |
| 155 | echo "OK" |
| 156 | } |
| 157 | |
Ray Milkey | 4867af2 | 2018-08-10 16:52:28 -0700 | [diff] [blame] | 158 | # .buckconfig.local must exist and the sonatype credentials must be set up |
| 159 | function testBuckconfigLocal() { |
| 160 | printf "Checking local buck config..." |
| 161 | if [ ! -f $ONOS_ROOT/.buckconfig.local ]; then |
| 162 | echo ".buckconfig.local not found" |
| 163 | return 1 |
| 164 | fi |
| 165 | |
| 166 | trap "echo [publish] must be specified" ERR |
| 167 | grep -q "^\[publish\]" $ONOS_ROOT/.buckconfig.local |
| 168 | |
| 169 | trap "echo maven_url must be specified" ERR |
| 170 | grep -q "maven_url" $ONOS_ROOT/.buckconfig.local |
| 171 | |
| 172 | trap "echo maven_user must be specified" ERR |
| 173 | grep -q "maven_user" $ONOS_ROOT/.buckconfig.local |
| 174 | |
| 175 | trap "echo maven_password must be specified" ERR |
| 176 | grep -q "maven_password" $ONOS_ROOT/.buckconfig.local |
| 177 | |
| 178 | trap "echo pgp_keyring must be specified" ERR |
| 179 | grep -q "pgp_keyring" $ONOS_ROOT/.buckconfig.local |
| 180 | |
| 181 | echo "OK" |
| 182 | } |
| 183 | |
| 184 | testBuckconfigLocal |
Thomas Vachuska | 6891884 | 2016-03-04 10:38:55 -0800 | [diff] [blame] | 185 | testToolchain |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 186 | testGerritAccess |
Ray Milkey | 13d3ae3 | 2017-01-03 15:00:04 -0800 | [diff] [blame] | 187 | |
| 188 | if [ ${dryRun} -eq 0 ]; then |
| 189 | testWikiAccess |
Ray Milkey | 4867af2 | 2018-08-10 16:52:28 -0700 | [diff] [blame] | 190 | testEC2Access |
Ray Milkey | 13d3ae3 | 2017-01-03 15:00:04 -0800 | [diff] [blame] | 191 | testSonatypeAccessMvn |
| 192 | testSonatypeAccessRest |
| 193 | fi |
Thomas Vachuska | 4702a26 | 2016-03-02 15:31:52 -0800 | [diff] [blame] | 194 | |
| 195 | echo "Ready to commence release process!" |