blob: e8b08d41e6277c0b3dcd9ddc978abc50a1e9411a [file] [log] [blame]
Joey Armstrong97643b32022-11-14 17:33:27 -05001#!/usr/bin/env groovy
Joey Armstrong379660e2022-12-14 19:21:00 -05002// -----------------------------------------------------------------------
Joey Armstrongaf679da2023-01-31 14:22:41 -05003// Copyright 2021-2023 Open Networking Foundation (ONF) and the ONF Contributors
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16// -----------------------------------------------------------------------
Joey Armstrong379660e2022-12-14 19:21:00 -050017// Install the voltctl command by branch name "voltha-xx"
18// -----------------------------------------------------------------------
Joey Armstrong97643b32022-11-14 17:33:27 -050019
Joey Armstrong379660e2022-12-14 19:21:00 -050020// -----------------------------------------------------------------------
21// -----------------------------------------------------------------------
22def getIam(String func)
23{
24 // Cannot rely on a stack trace due to jenkins manipulation
25 String src = 'vars/installVoltctl.groovy'
26 String iam = [src, func].join('::')
27 return iam
28}
29
30// -----------------------------------------------------------------------
31// -----------------------------------------------------------------------
32def process(String branch) {
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070033
Joey Armstrong96158a92022-11-25 10:36:06 -050034 String iam = 'vars/installVoltctl.groovy'
Joey Armstrong299f1f32022-11-24 08:45:25 -050035 println("** ${iam}: ENTER")
36
Joey Armstrong97643b32022-11-14 17:33:27 -050037 // This logic seems odd given we branch & tag repositories
38 // for release so hilight non-frozen until we know for sure.
39 def released=[
Joey Armstrong379660e2022-12-14 19:21:00 -050040 // https://github.com/opencord/voltctl/releases/tag/v1.8.1
Joey Armstrongca4cb462023-01-12 17:51:05 -050041 // 'voltha-2.11' : '1.8.4',
Joey Armstrong379660e2022-12-14 19:21:00 -050042 // https://github.com/opencord/voltctl/releases/tag/v1.7.6
Joey Armstrong97643b32022-11-14 17:33:27 -050043 'voltha-2.10' : '1.7.6',
44 'voltha-2.9' : '1.7.4',
45 'voltha-2.8' : '1.6.11',
46 ]
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070047
Joey Armstrong97643b32022-11-14 17:33:27 -050048 boolean have_released = released.containsKey(branch)
49 boolean is_release = false
50 // TODO: Enable with parameter: RELEASE_VOLTHA=
51 boolean has_binding = binding.hasVariable('WORKSPACE')
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070052
Joey Armstrong97643b32022-11-14 17:33:27 -050053 // WIP: Probe to find out what is available
Joey Armstrong96158a92022-11-25 10:36:06 -050054 print("""
55** have_released: ${have_released}
56** has_binding: ${has_binding}
57""")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070058
Joey Armstrong97643b32022-11-14 17:33:27 -050059 // ---------------------------------------------
60 // Sanity check: released version must be frozen
61 // ---------------------------------------------
62 if (is_release && ! released.containsKey(branch)) {
63 // Fingers crossed: jenkins may rewrite the callstack.
Joey Armstrong21998a42022-11-24 08:58:13 -050064 def myname = this.class.getName()
Joey Armstrong97643b32022-11-14 17:33:27 -050065
66 String url = [
67 'https://docs.voltha.org/master',
68 'howto/release/installVoltctl.html',
69 ].join('/')
70
71 String error = [
Joey Armstrong21998a42022-11-24 08:58:13 -050072 myname, "ERROR:",
Joey Armstrong97643b32022-11-14 17:33:27 -050073 "Detected release version=[$branch]",
74 "but voltctl is not frozen.",
75 '',
76 "See Also:", url,
77 ].join(' ')
78 throw new Exception(error)
79 }
80
81 // --------------------------------
82 // General answer: latest available
83 // --------------------------------
84 if (! have_released) {
85 url = 'https://api.github.com/repos/opencord/voltctl/releases/latest'
86 get_version = [
87 "curl -sSL ${url}",
88 "jq -r .tag_name",
89 "sed -e 's/^v//g'",
90 ].join(' | ')
91
92 print(" ** RUNNING: ${get_version}")
93 released[branch] = sh (
Joey Armstrong0f7db042022-11-24 07:50:42 -050094 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050095 returnStdout: true
96 ).trim()
97 }
98
99 voltctlVersion = released[branch]
100 println "Installing voltctl version ${voltctlVersion} on branch ${branch}"
101
102 // -----------------------------------------------------------------------
103 // groovy expansion: ${var}
104 // shell expansion: \${var}
105 // -----------------------------------------------------------------------
106 sh returnStdout: false, script: """#!/bin/bash
107
108 set -eu -o pipefail
109
110 bin_voltctl="$WORKSPACE/bin/voltctl"
111
112 mkdir -p "$WORKSPACE/bin"
113 cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; }
114
115 HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')"
116 HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')"
117 if [ "\$HOSTARCH" == "x86_64" ]; then
Hardik Windlass9658cd22021-10-25 11:13:25 +0000118 HOSTARCH="amd64"
119 fi
Joey Armstrong97643b32022-11-14 17:33:27 -0500120
121 # Retrieve versioned voltctl binary
122 download_url="https://github.com/opencord/voltctl/releases/download"
123 vol_ver="v${voltctlVersion}"
124 vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}"
Joey Armstrongb2f89812022-11-24 08:09:40 -0500125 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -0500126
Joey Armstronga935e712022-11-24 08:03:15 -0500127 chmod u=rwx,go=rx "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -0500128
Joey Armstrong379660e2022-12-14 19:21:00 -0500129 # ---------------------------------------------------------
130 # /usr/local/bin/voltctl --version != bin/voltctl --version
131 # Problem when default searchpath has not been modified.
132 # ---------------------------------------------------------
Joey Armstronga935e712022-11-24 08:03:15 -0500133 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +0000134 voltctl version --clientonly
135 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500136
137 println("** ${iam}: LEAVE")
Hardik Windlass9658cd22021-10-25 11:13:25 +0000138}
Joey Armstrong97643b32022-11-14 17:33:27 -0500139
Joey Armstrong379660e2022-12-14 19:21:00 -0500140// -----------------------------------------------------------------------
141// -----------------------------------------------------------------------
142def call(String branch)
143{
144 String iam = getIam('main')
145 println("** ${iam}: ENTER")
146
147 /* - unused, string passed as argument
148 if (!config) {
149 config = [:]
150 }
151 */
152
153 try
154 {
155 def config = [:]
156 showCommands(config)
157 }
158 catch (Exception err)
159 {
160 println("** ${iam}: WARNING ${err}")
161 }
162
163 try
164 {
165 process(branch)
166 }
167 catch (Exception err)
168 {
169 println("** ${iam}: EXCEPTION ${err}")
170 throw err
171 }
172 finally
173 {
174 println("** ${iam}: LEAVE")
175 }
176 return
177}
178
Joey Armstrong97643b32022-11-14 17:33:27 -0500179// [EOF]