blob: 4cd5cc0bd578dbfa50a13d9165e9767256d25617 [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 Armstrong299f1f32022-11-24 08:45:25 -05005 String iam = 'vars/installVoltha.groovy'
6 println("** ${iam}: ENTER")
7
Joey Armstrong97643b32022-11-14 17:33:27 -05008 // This logic seems odd given we branch & tag repositories
9 // for release so hilight non-frozen until we know for sure.
10 def released=[
11 'voltha-2.10' : '1.7.6',
12 'voltha-2.9' : '1.7.4',
13 'voltha-2.8' : '1.6.11',
14 ]
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070015
Joey Armstrong97643b32022-11-14 17:33:27 -050016 boolean have_released = released.containsKey(branch)
17 boolean is_release = false
18 // TODO: Enable with parameter: RELEASE_VOLTHA=
19 boolean has_binding = binding.hasVariable('WORKSPACE')
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070020
Joey Armstrong97643b32022-11-14 17:33:27 -050021 // WIP: Probe to find out what is available
22 print(" ** have_released: ${have_released}")
23 print(" ** has_binding: ${has_binding}")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070024
Joey Armstrong97643b32022-11-14 17:33:27 -050025 // ---------------------------------------------
26 // Sanity check: released version must be frozen
27 // ---------------------------------------------
28 if (is_release && ! released.containsKey(branch)) {
29 // Fingers crossed: jenkins may rewrite the callstack.
30 def iam = this.class.getName()
31
32 String url = [
33 'https://docs.voltha.org/master',
34 'howto/release/installVoltctl.html',
35 ].join('/')
36
37 String error = [
38 iam, "ERROR:",
39 "Detected release version=[$branch]",
40 "but voltctl is not frozen.",
41 '',
42 "See Also:", url,
43 ].join(' ')
44 throw new Exception(error)
45 }
46
47 // --------------------------------
48 // General answer: latest available
49 // --------------------------------
50 if (! have_released) {
51 url = 'https://api.github.com/repos/opencord/voltctl/releases/latest'
52 get_version = [
53 "curl -sSL ${url}",
54 "jq -r .tag_name",
55 "sed -e 's/^v//g'",
56 ].join(' | ')
57
58 print(" ** RUNNING: ${get_version}")
59 released[branch] = sh (
Joey Armstrong0f7db042022-11-24 07:50:42 -050060 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050061 returnStdout: true
62 ).trim()
63 }
64
65 voltctlVersion = released[branch]
66 println "Installing voltctl version ${voltctlVersion} on branch ${branch}"
67
68 // -----------------------------------------------------------------------
69 // groovy expansion: ${var}
70 // shell expansion: \${var}
71 // -----------------------------------------------------------------------
72 sh returnStdout: false, script: """#!/bin/bash
73
74 set -eu -o pipefail
75
76 bin_voltctl="$WORKSPACE/bin/voltctl"
77
78 mkdir -p "$WORKSPACE/bin"
79 cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; }
80
81 HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')"
82 HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')"
83 if [ "\$HOSTARCH" == "x86_64" ]; then
Hardik Windlass9658cd22021-10-25 11:13:25 +000084 HOSTARCH="amd64"
85 fi
Joey Armstrong97643b32022-11-14 17:33:27 -050086
87 # Retrieve versioned voltctl binary
88 download_url="https://github.com/opencord/voltctl/releases/download"
89 vol_ver="v${voltctlVersion}"
90 vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}"
Joey Armstrongb2f89812022-11-24 08:09:40 -050091 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -050092
Joey Armstronga935e712022-11-24 08:03:15 -050093 chmod u=rwx,go=rx "\$bin_voltctl"
94 chmod 755 "\$bin_voltctl"
95 /bin/ls -l "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -050096
97 ## Verify these are the same binary
Joey Armstronga935e712022-11-24 08:03:15 -050098 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +000099 voltctl version --clientonly
Joey Armstrong97643b32022-11-14 17:33:27 -0500100
101 # Should use diff or md5sum here
102 /bin/ls -l \$(which voltha)
Hardik Windlass9658cd22021-10-25 11:13:25 +0000103 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500104
105 println("** ${iam}: LEAVE")
Hardik Windlass9658cd22021-10-25 11:13:25 +0000106}
Joey Armstrong97643b32022-11-14 17:33:27 -0500107
108// [EOF]