blob: 7fea8471c4fd713fa9167f0fec6d0c69e4235be0 [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 Armstrong2d689982023-06-08 18:14:16 -040040 // 'voltha-2.12' : '?.?.?'
Joey Armstrong379660e2022-12-14 19:21:00 -050041 // https://github.com/opencord/voltctl/releases/tag/v1.8.1
Joey Armstrong0eb8bd82023-07-10 13:26:25 -040042 'voltha-2.11' : '1.8.4',
Joey Armstrong379660e2022-12-14 19:21:00 -050043 // https://github.com/opencord/voltctl/releases/tag/v1.7.6
Joey Armstrong97643b32022-11-14 17:33:27 -050044 'voltha-2.10' : '1.7.6',
45 'voltha-2.9' : '1.7.4',
46 'voltha-2.8' : '1.6.11',
47 ]
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070048
Joey Armstrong97643b32022-11-14 17:33:27 -050049 boolean have_released = released.containsKey(branch)
50 boolean is_release = false
51 // TODO: Enable with parameter: RELEASE_VOLTHA=
52 boolean has_binding = binding.hasVariable('WORKSPACE')
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070053
Joey Armstrong97643b32022-11-14 17:33:27 -050054 // WIP: Probe to find out what is available
Joey Armstrong96158a92022-11-25 10:36:06 -050055 print("""
56** have_released: ${have_released}
57** has_binding: ${has_binding}
58""")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070059
Joey Armstrong97643b32022-11-14 17:33:27 -050060 // ---------------------------------------------
61 // Sanity check: released version must be frozen
62 // ---------------------------------------------
63 if (is_release && ! released.containsKey(branch)) {
64 // Fingers crossed: jenkins may rewrite the callstack.
Joey Armstrong21998a42022-11-24 08:58:13 -050065 def myname = this.class.getName()
Joey Armstrong97643b32022-11-14 17:33:27 -050066
67 String url = [
68 'https://docs.voltha.org/master',
69 'howto/release/installVoltctl.html',
70 ].join('/')
71
72 String error = [
Joey Armstrong21998a42022-11-24 08:58:13 -050073 myname, "ERROR:",
Joey Armstrong97643b32022-11-14 17:33:27 -050074 "Detected release version=[$branch]",
75 "but voltctl is not frozen.",
76 '',
77 "See Also:", url,
78 ].join(' ')
79 throw new Exception(error)
80 }
81
82 // --------------------------------
83 // General answer: latest available
84 // --------------------------------
85 if (! have_released) {
86 url = 'https://api.github.com/repos/opencord/voltctl/releases/latest'
87 get_version = [
88 "curl -sSL ${url}",
89 "jq -r .tag_name",
90 "sed -e 's/^v//g'",
91 ].join(' | ')
92
93 print(" ** RUNNING: ${get_version}")
94 released[branch] = sh (
Joey Armstrong0f7db042022-11-24 07:50:42 -050095 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050096 returnStdout: true
97 ).trim()
98 }
99
100 voltctlVersion = released[branch]
101 println "Installing voltctl version ${voltctlVersion} on branch ${branch}"
102
103 // -----------------------------------------------------------------------
104 // groovy expansion: ${var}
105 // shell expansion: \${var}
106 // -----------------------------------------------------------------------
107 sh returnStdout: false, script: """#!/bin/bash
108
109 set -eu -o pipefail
110
111 bin_voltctl="$WORKSPACE/bin/voltctl"
112
113 mkdir -p "$WORKSPACE/bin"
114 cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; }
115
116 HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')"
117 HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')"
118 if [ "\$HOSTARCH" == "x86_64" ]; then
Hardik Windlass9658cd22021-10-25 11:13:25 +0000119 HOSTARCH="amd64"
120 fi
Joey Armstrong97643b32022-11-14 17:33:27 -0500121
122 # Retrieve versioned voltctl binary
123 download_url="https://github.com/opencord/voltctl/releases/download"
124 vol_ver="v${voltctlVersion}"
125 vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}"
Joey Armstrongb2f89812022-11-24 08:09:40 -0500126 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -0500127
Joey Armstronga935e712022-11-24 08:03:15 -0500128 chmod u=rwx,go=rx "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -0500129
Joey Armstrong379660e2022-12-14 19:21:00 -0500130 # ---------------------------------------------------------
131 # /usr/local/bin/voltctl --version != bin/voltctl --version
132 # Problem when default searchpath has not been modified.
133 # ---------------------------------------------------------
Joey Armstronga935e712022-11-24 08:03:15 -0500134 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +0000135 voltctl version --clientonly
136 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500137
138 println("** ${iam}: LEAVE")
Hardik Windlass9658cd22021-10-25 11:13:25 +0000139}
Joey Armstrong97643b32022-11-14 17:33:27 -0500140
Joey Armstrong379660e2022-12-14 19:21:00 -0500141// -----------------------------------------------------------------------
142// -----------------------------------------------------------------------
143def call(String branch)
144{
145 String iam = getIam('main')
146 println("** ${iam}: ENTER")
147
148 /* - unused, string passed as argument
149 if (!config) {
150 config = [:]
151 }
152 */
153
154 try
155 {
156 def config = [:]
157 showCommands(config)
158 }
159 catch (Exception err)
160 {
161 println("** ${iam}: WARNING ${err}")
162 }
163
164 try
165 {
166 process(branch)
167 }
168 catch (Exception err)
169 {
170 println("** ${iam}: EXCEPTION ${err}")
171 throw err
172 }
173 finally
174 {
175 println("** ${iam}: LEAVE")
176 }
177 return
178}
179
Joey Armstrong97643b32022-11-14 17:33:27 -0500180// [EOF]