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