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