Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 3 | // Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | // ----------------------------------------------------------------------- |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 17 | // Install the voltctl command by branch name "voltha-xx" |
| 18 | // ----------------------------------------------------------------------- |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 19 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 20 | // ----------------------------------------------------------------------- |
| 21 | // ----------------------------------------------------------------------- |
| 22 | def getIam(String func) |
| 23 | { |
| 24 | // Cannot rely on a stack trace due to jenkins manipulation |
| 25 | String src = 'vars/installVoltctl.groovy' |
| 26 | String iam = [src, func].join('::') |
| 27 | return iam |
| 28 | } |
| 29 | |
| 30 | // ----------------------------------------------------------------------- |
| 31 | // ----------------------------------------------------------------------- |
| 32 | def process(String branch) { |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 33 | |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 34 | String iam = 'vars/installVoltctl.groovy' |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 35 | println("** ${iam}: ENTER") |
| 36 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 37 | // This logic seems odd given we branch & tag repositories |
| 38 | // for release so hilight non-frozen until we know for sure. |
| 39 | def released=[ |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 40 | // https://github.com/opencord/voltctl/releases/tag/v1.8.1 |
Joey Armstrong | ca4cb46 | 2023-01-12 17:51:05 -0500 | [diff] [blame] | 41 | // 'voltha-2.11' : '1.8.4', |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 42 | // https://github.com/opencord/voltctl/releases/tag/v1.7.6 |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 43 | 'voltha-2.10' : '1.7.6', |
| 44 | 'voltha-2.9' : '1.7.4', |
| 45 | 'voltha-2.8' : '1.6.11', |
| 46 | ] |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 47 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 48 | boolean have_released = released.containsKey(branch) |
| 49 | boolean is_release = false |
| 50 | // TODO: Enable with parameter: RELEASE_VOLTHA= |
| 51 | boolean has_binding = binding.hasVariable('WORKSPACE') |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 52 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 53 | // WIP: Probe to find out what is available |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 54 | print(""" |
| 55 | ** have_released: ${have_released} |
| 56 | ** has_binding: ${has_binding} |
| 57 | """) |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 58 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 59 | // --------------------------------------------- |
| 60 | // Sanity check: released version must be frozen |
| 61 | // --------------------------------------------- |
| 62 | if (is_release && ! released.containsKey(branch)) { |
| 63 | // Fingers crossed: jenkins may rewrite the callstack. |
Joey Armstrong | 21998a4 | 2022-11-24 08:58:13 -0500 | [diff] [blame] | 64 | def myname = this.class.getName() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 65 | |
| 66 | String url = [ |
| 67 | 'https://docs.voltha.org/master', |
| 68 | 'howto/release/installVoltctl.html', |
| 69 | ].join('/') |
| 70 | |
| 71 | String error = [ |
Joey Armstrong | 21998a4 | 2022-11-24 08:58:13 -0500 | [diff] [blame] | 72 | myname, "ERROR:", |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 73 | "Detected release version=[$branch]", |
| 74 | "but voltctl is not frozen.", |
| 75 | '', |
| 76 | "See Also:", url, |
| 77 | ].join(' ') |
| 78 | throw new Exception(error) |
| 79 | } |
| 80 | |
| 81 | // -------------------------------- |
| 82 | // General answer: latest available |
| 83 | // -------------------------------- |
| 84 | if (! have_released) { |
| 85 | url = 'https://api.github.com/repos/opencord/voltctl/releases/latest' |
| 86 | get_version = [ |
| 87 | "curl -sSL ${url}", |
| 88 | "jq -r .tag_name", |
| 89 | "sed -e 's/^v//g'", |
| 90 | ].join(' | ') |
| 91 | |
| 92 | print(" ** RUNNING: ${get_version}") |
| 93 | released[branch] = sh ( |
Joey Armstrong | 0f7db04 | 2022-11-24 07:50:42 -0500 | [diff] [blame] | 94 | script: get_version, |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 95 | returnStdout: true |
| 96 | ).trim() |
| 97 | } |
| 98 | |
| 99 | voltctlVersion = released[branch] |
| 100 | println "Installing voltctl version ${voltctlVersion} on branch ${branch}" |
| 101 | |
| 102 | // ----------------------------------------------------------------------- |
| 103 | // groovy expansion: ${var} |
| 104 | // shell expansion: \${var} |
| 105 | // ----------------------------------------------------------------------- |
| 106 | sh returnStdout: false, script: """#!/bin/bash |
| 107 | |
| 108 | set -eu -o pipefail |
| 109 | |
| 110 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 111 | |
| 112 | mkdir -p "$WORKSPACE/bin" |
| 113 | cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; } |
| 114 | |
| 115 | HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 116 | HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')" |
| 117 | if [ "\$HOSTARCH" == "x86_64" ]; then |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 118 | HOSTARCH="amd64" |
| 119 | fi |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 120 | |
| 121 | # Retrieve versioned voltctl binary |
| 122 | download_url="https://github.com/opencord/voltctl/releases/download" |
| 123 | vol_ver="v${voltctlVersion}" |
| 124 | vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}" |
Joey Armstrong | b2f8981 | 2022-11-24 08:09:40 -0500 | [diff] [blame] | 125 | curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 126 | |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 127 | chmod u=rwx,go=rx "\$bin_voltctl" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 128 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 129 | # --------------------------------------------------------- |
| 130 | # /usr/local/bin/voltctl --version != bin/voltctl --version |
| 131 | # Problem when default searchpath has not been modified. |
| 132 | # --------------------------------------------------------- |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 133 | "\${bin_voltctl}" version --clientonly |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 134 | voltctl version --clientonly |
| 135 | """ |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 136 | |
| 137 | println("** ${iam}: LEAVE") |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 138 | } |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 139 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 140 | // ----------------------------------------------------------------------- |
| 141 | // ----------------------------------------------------------------------- |
| 142 | def call(String branch) |
| 143 | { |
| 144 | String iam = getIam('main') |
| 145 | println("** ${iam}: ENTER") |
| 146 | |
| 147 | /* - unused, string passed as argument |
| 148 | if (!config) { |
| 149 | config = [:] |
| 150 | } |
| 151 | */ |
| 152 | |
| 153 | try |
| 154 | { |
| 155 | def config = [:] |
| 156 | showCommands(config) |
| 157 | } |
| 158 | catch (Exception err) |
| 159 | { |
| 160 | println("** ${iam}: WARNING ${err}") |
| 161 | } |
| 162 | |
| 163 | try |
| 164 | { |
| 165 | process(branch) |
| 166 | } |
| 167 | catch (Exception err) |
| 168 | { |
| 169 | println("** ${iam}: EXCEPTION ${err}") |
| 170 | throw err |
| 171 | } |
| 172 | finally |
| 173 | { |
| 174 | println("** ${iam}: LEAVE") |
| 175 | } |
| 176 | return |
| 177 | } |
| 178 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 179 | // [EOF] |