blob: efeed498ccac508b15d5c0b7b2d0d360bdc53e96 [file] [log] [blame]
Joey Armstrong97643b32022-11-14 17:33:27 -05001#!/usr/bin/env groovy
Joey Armstrong379660e2022-12-14 19:21:00 -05002// -----------------------------------------------------------------------
3// Install the voltctl command by branch name "voltha-xx"
4// -----------------------------------------------------------------------
Joey Armstrong97643b32022-11-14 17:33:27 -05005
Joey Armstrong379660e2022-12-14 19:21:00 -05006// -----------------------------------------------------------------------
7// -----------------------------------------------------------------------
8def 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// -----------------------------------------------------------------------
18def process(String branch) {
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070019
Joey Armstrong96158a92022-11-25 10:36:06 -050020 String iam = 'vars/installVoltctl.groovy'
Joey Armstrong299f1f32022-11-24 08:45:25 -050021 println("** ${iam}: ENTER")
22
Joey Armstrong97643b32022-11-14 17:33:27 -050023 // 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 Armstrong379660e2022-12-14 19:21:00 -050026 // https://github.com/opencord/voltctl/releases/tag/v1.8.1
Joey Armstrongca4cb462023-01-12 17:51:05 -050027 // 'voltha-2.11' : '1.8.4',
Joey Armstrong379660e2022-12-14 19:21:00 -050028 // https://github.com/opencord/voltctl/releases/tag/v1.7.6
Joey Armstrong97643b32022-11-14 17:33:27 -050029 'voltha-2.10' : '1.7.6',
30 'voltha-2.9' : '1.7.4',
31 'voltha-2.8' : '1.6.11',
32 ]
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070033
Joey Armstrong97643b32022-11-14 17:33:27 -050034 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 Scandolob47a6fd2021-10-27 17:02:49 -070038
Joey Armstrong97643b32022-11-14 17:33:27 -050039 // WIP: Probe to find out what is available
Joey Armstrong96158a92022-11-25 10:36:06 -050040 print("""
41** have_released: ${have_released}
42** has_binding: ${has_binding}
43""")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070044
Joey Armstrong97643b32022-11-14 17:33:27 -050045 // ---------------------------------------------
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 Armstrong21998a42022-11-24 08:58:13 -050050 def myname = this.class.getName()
Joey Armstrong97643b32022-11-14 17:33:27 -050051
52 String url = [
53 'https://docs.voltha.org/master',
54 'howto/release/installVoltctl.html',
55 ].join('/')
56
57 String error = [
Joey Armstrong21998a42022-11-24 08:58:13 -050058 myname, "ERROR:",
Joey Armstrong97643b32022-11-14 17:33:27 -050059 "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 Armstrong0f7db042022-11-24 07:50:42 -050080 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050081 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 Windlass9658cd22021-10-25 11:13:25 +0000104 HOSTARCH="amd64"
105 fi
Joey Armstrong97643b32022-11-14 17:33:27 -0500106
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 Armstrongb2f89812022-11-24 08:09:40 -0500111 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -0500112
Joey Armstronga935e712022-11-24 08:03:15 -0500113 chmod u=rwx,go=rx "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -0500114
Joey Armstrong379660e2022-12-14 19:21:00 -0500115 # ---------------------------------------------------------
116 # /usr/local/bin/voltctl --version != bin/voltctl --version
117 # Problem when default searchpath has not been modified.
118 # ---------------------------------------------------------
Joey Armstronga935e712022-11-24 08:03:15 -0500119 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +0000120 voltctl version --clientonly
121 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500122
123 println("** ${iam}: LEAVE")
Hardik Windlass9658cd22021-10-25 11:13:25 +0000124}
Joey Armstrong97643b32022-11-14 17:33:27 -0500125
Joey Armstrong379660e2022-12-14 19:21:00 -0500126// -----------------------------------------------------------------------
127// -----------------------------------------------------------------------
128def 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 Armstrong97643b32022-11-14 17:33:27 -0500165// [EOF]