blob: cacf6e8a6fbcc580680664e682702440688392ca [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 Armstrong96158a92022-11-25 10:36:06 -05005 String iam = 'vars/installVoltctl.groovy'
Joey Armstrong299f1f32022-11-24 08:45:25 -05006 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
Joey Armstrong96158a92022-11-25 10:36:06 -050022 print("""
23** have_released: ${have_released}
24** has_binding: ${has_binding}
25""")
Matteo Scandolob47a6fd2021-10-27 17:02:49 -070026
Joey Armstrong97643b32022-11-14 17:33:27 -050027 // ---------------------------------------------
28 // Sanity check: released version must be frozen
29 // ---------------------------------------------
30 if (is_release && ! released.containsKey(branch)) {
31 // Fingers crossed: jenkins may rewrite the callstack.
Joey Armstrong21998a42022-11-24 08:58:13 -050032 def myname = this.class.getName()
Joey Armstrong97643b32022-11-14 17:33:27 -050033
34 String url = [
35 'https://docs.voltha.org/master',
36 'howto/release/installVoltctl.html',
37 ].join('/')
38
39 String error = [
Joey Armstrong21998a42022-11-24 08:58:13 -050040 myname, "ERROR:",
Joey Armstrong97643b32022-11-14 17:33:27 -050041 "Detected release version=[$branch]",
42 "but voltctl is not frozen.",
43 '',
44 "See Also:", url,
45 ].join(' ')
46 throw new Exception(error)
47 }
48
49 // --------------------------------
50 // General answer: latest available
51 // --------------------------------
52 if (! have_released) {
53 url = 'https://api.github.com/repos/opencord/voltctl/releases/latest'
54 get_version = [
55 "curl -sSL ${url}",
56 "jq -r .tag_name",
57 "sed -e 's/^v//g'",
58 ].join(' | ')
59
60 print(" ** RUNNING: ${get_version}")
61 released[branch] = sh (
Joey Armstrong0f7db042022-11-24 07:50:42 -050062 script: get_version,
Joey Armstrong97643b32022-11-14 17:33:27 -050063 returnStdout: true
64 ).trim()
65 }
66
67 voltctlVersion = released[branch]
68 println "Installing voltctl version ${voltctlVersion} on branch ${branch}"
69
70 // -----------------------------------------------------------------------
71 // groovy expansion: ${var}
72 // shell expansion: \${var}
73 // -----------------------------------------------------------------------
74 sh returnStdout: false, script: """#!/bin/bash
75
76 set -eu -o pipefail
77
78 bin_voltctl="$WORKSPACE/bin/voltctl"
79
80 mkdir -p "$WORKSPACE/bin"
81 cd "$WORKSPACE" || { echo "ERROR: cd $WORKSPACE failed"; exit 1; }
82
83 HOSTOS="\$(uname -s | tr '[:upper:]' '[:lower:]')"
84 HOSTARCH="\$(uname -m | tr '[:upper:]' '[:lower:]')"
85 if [ "\$HOSTARCH" == "x86_64" ]; then
Hardik Windlass9658cd22021-10-25 11:13:25 +000086 HOSTARCH="amd64"
87 fi
Joey Armstrong97643b32022-11-14 17:33:27 -050088
89 # Retrieve versioned voltctl binary
90 download_url="https://github.com/opencord/voltctl/releases/download"
91 vol_ver="v${voltctlVersion}"
92 vol_name="voltctl-${voltctlVersion}-\${HOSTOS}-\${HOSTARCH}"
Joey Armstrongb2f89812022-11-24 08:09:40 -050093 curl -o "\$bin_voltctl" -sSL "\${download_url}/\${vol_ver}/\${vol_name}"
Joey Armstrong97643b32022-11-14 17:33:27 -050094
Joey Armstronga935e712022-11-24 08:03:15 -050095 chmod u=rwx,go=rx "\$bin_voltctl"
96 chmod 755 "\$bin_voltctl"
97 /bin/ls -l "\$bin_voltctl"
Joey Armstrong97643b32022-11-14 17:33:27 -050098
99 ## Verify these are the same binary
Joey Armstronga935e712022-11-24 08:03:15 -0500100 "\${bin_voltctl}" version --clientonly
Hardik Windlass9658cd22021-10-25 11:13:25 +0000101 voltctl version --clientonly
Joey Armstrong97643b32022-11-14 17:33:27 -0500102
103 # Should use diff or md5sum here
Joey Armstrong96158a92022-11-25 10:36:06 -0500104 /bin/ls -l \$(which voltctl)
Hardik Windlass9658cd22021-10-25 11:13:25 +0000105 """
Joey Armstrong299f1f32022-11-24 08:45:25 -0500106
107 println("** ${iam}: LEAVE")
Hardik Windlass9658cd22021-10-25 11:13:25 +0000108}
Joey Armstrong97643b32022-11-14 17:33:27 -0500109
110// [EOF]