Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 3 | def call(String branch) { |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 4 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 5 | // This logic seems odd given we branch & tag repositories |
| 6 | // for release so hilight non-frozen until we know for sure. |
| 7 | def released=[ |
| 8 | 'voltha-2.10' : '1.7.6', |
| 9 | 'voltha-2.9' : '1.7.4', |
| 10 | 'voltha-2.8' : '1.6.11', |
| 11 | ] |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 12 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 13 | boolean have_released = released.containsKey(branch) |
| 14 | boolean is_release = false |
| 15 | // TODO: Enable with parameter: RELEASE_VOLTHA= |
| 16 | boolean has_binding = binding.hasVariable('WORKSPACE') |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 17 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 18 | // WIP: Probe to find out what is available |
| 19 | print(" ** have_released: ${have_released}") |
| 20 | print(" ** has_binding: ${has_binding}") |
Matteo Scandolo | b47a6fd | 2021-10-27 17:02:49 -0700 | [diff] [blame] | 21 | |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 22 | // --------------------------------------------- |
| 23 | // Sanity check: released version must be frozen |
| 24 | // --------------------------------------------- |
| 25 | if (is_release && ! released.containsKey(branch)) { |
| 26 | // Fingers crossed: jenkins may rewrite the callstack. |
| 27 | def iam = this.class.getName() |
| 28 | |
| 29 | String url = [ |
| 30 | 'https://docs.voltha.org/master', |
| 31 | 'howto/release/installVoltctl.html', |
| 32 | ].join('/') |
| 33 | |
| 34 | String error = [ |
| 35 | iam, "ERROR:", |
| 36 | "Detected release version=[$branch]", |
| 37 | "but voltctl is not frozen.", |
| 38 | '', |
| 39 | "See Also:", url, |
| 40 | ].join(' ') |
| 41 | throw new Exception(error) |
| 42 | } |
| 43 | |
| 44 | // -------------------------------- |
| 45 | // General answer: latest available |
| 46 | // -------------------------------- |
| 47 | if (! have_released) { |
| 48 | url = 'https://api.github.com/repos/opencord/voltctl/releases/latest' |
| 49 | get_version = [ |
| 50 | "curl -sSL ${url}", |
| 51 | "jq -r .tag_name", |
| 52 | "sed -e 's/^v//g'", |
| 53 | ].join(' | ') |
| 54 | |
| 55 | print(" ** RUNNING: ${get_version}") |
| 56 | released[branch] = sh ( |
Joey Armstrong | 0f7db04 | 2022-11-24 07:50:42 -0500 | [diff] [blame^] | 57 | script: get_version, |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 58 | returnStdout: true |
| 59 | ).trim() |
| 60 | } |
| 61 | |
| 62 | voltctlVersion = released[branch] |
| 63 | println "Installing voltctl version ${voltctlVersion} on branch ${branch}" |
| 64 | |
| 65 | // ----------------------------------------------------------------------- |
| 66 | // groovy expansion: ${var} |
| 67 | // shell expansion: \${var} |
| 68 | // ----------------------------------------------------------------------- |
| 69 | sh returnStdout: false, script: """#!/bin/bash |
| 70 | |
| 71 | set -eu -o pipefail |
| 72 | |
| 73 | bin_voltctl="$WORKSPACE/bin/voltctl" |
| 74 | |
| 75 | mkdir -p "$WORKSPACE/bin" |
| 76 | cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; } |
| 77 | |
| 78 | HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')" |
| 79 | HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')" |
| 80 | if [ "\$HOSTARCH" == "x86_64" ]; then |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 81 | HOSTARCH="amd64" |
| 82 | fi |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 83 | |
| 84 | # Retrieve versioned voltctl binary |
| 85 | download_url="https://github.com/opencord/voltctl/releases/download" |
| 86 | vol_ver="v${voltctlVersion}" |
| 87 | vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}" |
| 88 | curl -o "$bin_voltctl" -sSL "${download_url}/${vol_ver}/${vol_name}" |
| 89 | |
| 90 | chmod u=rwx,go=rx "$bin_voltctl" |
| 91 | chmod 755 "$bin_voltctl" |
| 92 | /bin/ls -l "$bin_voltctl" |
| 93 | |
| 94 | ## Verify these are the same binary |
| 95 | "${bin_voltctl}" version --clientonly |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 96 | voltctl version --clientonly |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 97 | |
| 98 | # Should use diff or md5sum here |
| 99 | /bin/ls -l \$(which voltha) |
Hardik Windlass | 9658cd2 | 2021-10-25 11:13:25 +0000 | [diff] [blame] | 100 | """ |
| 101 | } |
Joey Armstrong | 97643b3 | 2022-11-14 17:33:27 -0500 | [diff] [blame] | 102 | |
| 103 | // [EOF] |