Hog Hog2025.2-3
get_binary_links.tcl
Go to the documentation of this file.
1 #!/usr/bin/env tclsh
2 # Copyright 2018-2025 The University of Birmingham
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 
16 # @file
17 # Retrieves binary files links or creates new one to be uploaded as Releases
18 
19 
20 set OldPath [pwd]
21 set TclPath [file dirname [info script]]/..
22 set repo_path [file normalize "$TclPath/../.."]
23 source $TclPath/hog.tcl
24 
25 if {[catch {package require cmdline} ERROR]} {
26  Msg Error "$ERROR\n If you are running this script on tclsh, you can fix this by installing 'tcllib'"
27  return
28 }
29 
30 set parameters {
31  {force "Forces the creation of new project links"}
32 }
33 
34 set usage "- CI script that retrieves binary files links or creates new ones to be uploaded to a GitLab release\n \
35 USAGE: $::argv0 <tag> <ext_path> \[OPTIONS\] \n. Options:"
36 
37 if {[catch {array set options [cmdline::getoptions ::argv $parameters $usage]}] || [llength $argv] < 2} {
38  Msg Info [cmdline::usage $parameters $usage]
39  cd $OldPath
40  return
41 }
42 
43 set tag [lindex $argv 0]
44 set ext_path [lindex $argv 1]
45 cd $repo_path
46 # Find link for every project:
47 set projects_list [SearchHogProjects $repo_path/Top]
48 
49 foreach proj $projects_list {
50  #find project version
51  set proj_name [file tail $proj]
52  set proj_dir [file dirname $proj]
53  set dir $repo_path/Top/$proj
54  set ver [GetProjectVersion $dir $repo_path $ext_path 1]
55  if {"$ver" == "0" || "$ver" == "$tag" || $options(force) == 1} {
56  # Project was modified in current version, upload the files
57  Msg Info "Retrieving $proj binaries and tag $tag..."
58  if {[catch {glob -types d $repo_path/bin/$proj*} prj_dir]} {
59  Msg CriticalWarning "Cannot find $proj binaries in artifacts"
60  continue
61  }
62  if {$proj_dir != "."} {
63  set proj_zip [string map {/ _} $proj_dir]
64  set files [glob -nocomplain -directory "$repo_path/zipped/" ${proj_zip}_${proj_name}-${tag}.z*]
65  } else {
66  set files [glob -nocomplain -directory "$repo_path/zipped/" ${proj_name}-${tag}.z*]
67  }
68  foreach f $files {
69  set ext [file extension $f]
70  Execute glab release upload $tag "$f#${proj}-${tag}$ext"
71  }
72  } elseif {"$ver" == "-1"} {
73  # Something went wrong...
74  Msg CriticalWarning "Something went wrong when tried to retrieve version for project $proj"
75  cd $OldPath
76  return
77  } else {
78  # Project was not modified in current version. Let's retrieve the last available link.
79  Msg Info "Retrieving existing link for $proj binaries and tag $ver"
80  lassign [ExecuteRet glab release view $ver] ret msg
81  if {$ret != 0} {
82  Msg Warning "Some problem when fetching release $ver : $msg"
83  } else {
84  set link ""
85  foreach line [split $msg "\n"] {
86  if {[string first "${proj}-${ver}.z" $line] == 0} {
87  set name [lindex [split $line] 0]
88  set link [lindex [split $line] 1]
89  set json "\[{ \"name\": \"$name\",\"url\": \"$link\",\"link_type\": \"other\" } \]"
90  Execute glab release upload $tag --assets-links=$json
91  }
92  }
93  }
94  }
95 }
96 cd $OldPath