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 | 06a6837 | 2023-07-24 16:37:16 -0400 | [diff] [blame] | 40 | // v1.9.1 - https://github.com/opencord/voltctl/releases/tag/untagged-cd611c39178f25b95a87 |
| 41 | 'voltha-2.12' : '1.8.45', |
Joey Armstrong | b65ada3 | 2023-08-03 12:50:20 -0400 | [diff] [blame] | 42 | 'voltha-2.11' : '1.8.45', |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 43 | // https://github.com/opencord/voltctl/releases/tag/v1.7.6 |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 44 | 'voltha-2.10' : '1.7.6', |
| 45 | 'voltha-2.9' : '1.7.4', |
| 46 | 'voltha-2.8' : '1.6.11', |
| 47 | ] |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 48 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 49 | boolean have_released = released.containsKey(branch) |
| 50 | boolean is_release = false |
| 51 | // TODO: Enable with parameter: RELEASE_VOLTHA= |
| 52 | boolean has_binding = binding.hasVariable('WORKSPACE') |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 53 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 54 | // WIP: Probe to find out what is available |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 55 | print(""" |
| 56 | ** have_released: ${have_released} |
| 57 | ** has_binding: ${has_binding} |
| 58 | """) |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 59 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 60 | // --------------------------------------------- |
| 61 | // Sanity check: released version must be frozen |
| 62 | // --------------------------------------------- |
| 63 | if (is_release && ! released.containsKey(branch)) { |
| 64 | // Fingers crossed: jenkins may rewrite the callstack. |
Joey Armstrong | 21998a4 | 2022-11-24 08:58:13 -0500 | [diff] [blame] | 65 | def myname = this.class.getName() |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 66 | |
| 67 | String url = [ |
| 68 | 'https://docs.voltha.org/master', |
| 69 | 'howto/release/installVoltctl.html', |
| 70 | ].join('/') |
| 71 | |
| 72 | String error = [ |
Joey Armstrong | 21998a4 | 2022-11-24 08:58:13 -0500 | [diff] [blame] | 73 | myname, "ERROR:", |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 74 | "Detected release version=[$branch]", |
| 75 | "but voltctl is not frozen.", |
| 76 | '', |
| 77 | "See Also:", url, |
| 78 | ].join(' ') |
| 79 | throw new Exception(error) |
| 80 | } |
| 81 | |
| 82 | // -------------------------------- |
| 83 | // General answer: latest available |
| 84 | // -------------------------------- |
| 85 | if (! have_released) { |
| 86 | url = 'https://api.github.com/repos/opencord/voltctl/releases/latest' |
| 87 | get_version = [ |
| 88 | "curl -sSL ${url}", |
| 89 | "jq -r .tag_name", |
| 90 | "sed -e 's/^v//g'", |
| 91 | ].join(' | ') |
| 92 | |
| 93 | print(" ** RUNNING: ${get_version}") |
| 94 | released[branch] = sh ( |
Joey Armstrong | 0f7db04 | 2022-11-24 07:50:42 -0500 | [diff] [blame] | 95 | script: get_version, |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 96 | returnStdout: true |
| 97 | ).trim() |
| 98 | } |
| 99 | |
| 100 | voltctlVersion = released[branch] |
| 101 | println "Installing voltctl version ${voltctlVersion} on branch ${branch}" |
| 102 | |
| 103 | // ----------------------------------------------------------------------- |
| 104 | // groovy expansion: ${var} |
| 105 | // shell expansion: \${var} |
| 106 | // ----------------------------------------------------------------------- |
| 107 | sh returnStdout: false, script: """#!/bin/bash |
| 108 | |
Joey Armstrong | b65ada3 | 2023-08-03 12:50:20 -0400 | [diff] [blame] | 109 | # set -eu -o pipefail |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 110 | |
| 111 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 112 | |
| 113 | mkdir -p "$WORKSPACE/bin" |
| 114 | cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; } |
| 115 | |
| 116 | HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 117 | HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')" |
| 118 | if [ "\$HOSTARCH" == "x86_64" ]; then |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 119 | HOSTARCH="amd64" |
| 120 | fi |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 121 | |
| 122 | # Retrieve versioned voltctl binary |
| 123 | download_url="https://github.com/opencord/voltctl/releases/download" |
| 124 | vol_ver="v${voltctlVersion}" |
| 125 | vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}" |
Joey Armstrong | b2f8981 | 2022-11-24 08:09:40 -0500 | [diff] [blame] | 126 | curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 127 | |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 128 | chmod u=rwx,go=rx "\$bin_voltctl" |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 129 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 130 | # --------------------------------------------------------- |
| 131 | # /usr/local/bin/voltctl --version != bin/voltctl --version |
| 132 | # Problem when default searchpath has not been modified. |
| 133 | # --------------------------------------------------------- |
Joey Armstrong | a935e71 | 2022-11-24 08:03:15 -0500 | [diff] [blame] | 134 | "\${bin_voltctl}" version --clientonly |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 135 | voltctl version --clientonly |
| 136 | """ |
Joey Armstrong | 299f1f3 | 2022-11-24 08:45:25 -0500 | [diff] [blame] | 137 | |
| 138 | println("** ${iam}: LEAVE") |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 139 | } |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 140 | |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 141 | // ----------------------------------------------------------------------- |
| 142 | // ----------------------------------------------------------------------- |
| 143 | def call(String branch) |
| 144 | { |
| 145 | String iam = getIam('main') |
| 146 | println("** ${iam}: ENTER") |
| 147 | |
| 148 | /* - unused, string passed as argument |
| 149 | if (!config) { |
| 150 | config = [:] |
| 151 | } |
| 152 | */ |
| 153 | |
| 154 | try |
| 155 | { |
Joey Armstrong | 379660e | 2022-12-14 19:21:00 -0500 | [diff] [blame] | 156 | process(branch) |
| 157 | } |
| 158 | catch (Exception err) |
| 159 | { |
| 160 | println("** ${iam}: EXCEPTION ${err}") |
| 161 | throw err |
| 162 | } |
| 163 | finally |
| 164 | { |
| 165 | println("** ${iam}: LEAVE") |
| 166 | } |
| 167 | return |
| 168 | } |
| 169 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 170 | // [EOF] |