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