blob: ce2b71e6dc6e9f9fefaf1cd0034e3449cb964a25 [file] [log] [blame]
Joey Armstrong97643b32022-11-14 17:33:27 -05001#!/usr/bin/env groovy
2
Hardik Windlass9658cd22021-10-25 11:13:25 +00003def call(String branch) {
Matteo Scandolob47a6fd2021-10-27 17:02:49 -07004
Joey Armstrong97643b32022-11-14 17:33:27 -05005 // 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 Scandolob47a6fd2021-10-27 17:02:49 -070012
Joey Armstrong97643b32022-11-14 17:33:27 -050013 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 Scandolob47a6fd2021-10-27 17:02:49 -070017
Joey Armstrong97643b32022-11-14 17:33:27 -050018 // WIP: Probe to find out what is available
19 print(" ** have_released: ${have_released}")
20 print(" ** has_binding: ${has_binding}")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070021
Joey Armstrong97643b32022-11-14 17:33:27 -050022 // ---------------------------------------------
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 Armstrong0f7db042022-11-24 07:50:42 -050057 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050058 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 Windlass9658cd22021-10-25 11:13:25 +000081 HOSTARCH="amd64"
82 fi
Joey Armstrong97643b32022-11-14 17:33:27 -050083
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 Windlass9658cd22021-10-25 11:13:25 +000096 voltctl version --clientonly
Joey Armstrong97643b32022-11-14 17:33:27 -050097
98 # Should use diff or md5sum here
99 /bin/ls -l \$(which voltha)
Hardik Windlass9658cd22021-10-25 11:13:25 +0000100 """
101}
Joey Armstrong97643b32022-11-14 17:33:27 -0500102
103// [EOF]