blob: fb90ebc2ba1772bee5ce721b51a7b75426f60e2e [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 Armstrong06a68372023-07-24 16:37:16 -040040 // v1.9.1 - https://github.com/opencord/voltctl/releases/tag/untagged-cd611c39178f25b95a87
41 'voltha-2.12' : '1.8.45',
Joey Armstrongb65ada32023-08-03 12:50:20 -040042 'voltha-2.11' : '1.8.45',
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
Joey Armstrongb65ada32023-08-03 12:50:20 -0400109# set -eu -o pipefail
Joey Armstrong97643b32022-11-14 17:33:27 -0500110
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 {
Joey Armstrong379660e2022-12-14 19:21:00 -0500156 process(branch)
157 }
158 catch (Exception err)
159 {
160 println("** ${iam}: EXCEPTION ${err}")
161 throw err
162 }
163 finally
164 {
165 println("** ${iam}: LEAVE")
166 }
167 return
168}
169
Joey Armstrong97643b32022-11-14 17:33:27 -0500170// [EOF]