Hog Hog2026.2-1
get_binary_links.tcl
Go to the documentation of this file.
1 #!/usr/bin/env tclsh
2 # Copyright 2018-2026 The University of Birmingham
3 # Copyright 2018-2026 Max-Planck-Institute for Physics
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 
17 # @file
18 # Retrieves binary files links or creates new one to be uploaded as Releases
19 
20 
21 set OldPath [pwd]
22 set TclPath [file dirname [info script]]/..
23 set repo_path [file normalize "$TclPath/../.."]
24 source $TclPath/hog.tcl
25 
26 if {[catch {package require cmdline} ERROR]} {
27  Msg Error "$ERROR\n If you are running this script on tclsh, you can fix this by installing 'tcllib'"
28  return
29 }
30 
31 set parameters {
32  {force "Forces the creation of new project links"}
33 }
34 
35 set usage "- CI script that retrieves binary files links or creates new ones to be uploaded to a GitLab release\n \
36 USAGE: $::argv0 <tag> <ext_path> \[OPTIONS\] \n. Options:"
37 
38 if {[catch {array set options [cmdline::getoptions ::argv $parameters $usage]}] || [llength $argv] < 2} {
39  Msg Info [cmdline::usage $parameters $usage]
40  cd $OldPath
41  return
42 }
43 
44 set tag [lindex $argv 0]
45 set ext_path [lindex $argv 1]
46 cd $repo_path
47 # Find link for every project:
48 set projects_list [SearchHogProjects $repo_path/Top]
49 
50 foreach proj $projects_list {
51  #find project version
52  set proj_name [file tail $proj]
53  set proj_dir [file dirname $proj]
54  set dir $repo_path/Top/$proj
55  set ver [GetProjectVersion $dir $repo_path $ext_path 1]
56  if {"$ver" == "0" || "$ver" == "$tag" || $options(force) == 1} {
57  # Project was modified in current version, upload the files
58  Msg Info "Retrieving $proj binaries and tag $tag..."
59  if {[catch {glob -types d $repo_path/bin/$proj*} prj_dir]} {
60  Msg CriticalWarning "Cannot find $proj binaries in artifacts"
61  continue
62  }
63  if {$proj_dir != "."} {
64  set proj_zip [string map {/ _} $proj_dir]
65  set files [glob -nocomplain -directory "$repo_path/zipped/" ${proj_zip}_${proj_name}-${tag}.z*]
66  } else {
67  set files [glob -nocomplain -directory "$repo_path/zipped/" ${proj_name}-${tag}.z*]
68  }
69  foreach f $files {
70  set ext [file extension $f]
71  Execute glab release upload $tag "$f#${proj}-${tag}$ext"
72  }
73  } elseif {"$ver" == "-1"} {
74  # Something went wrong...
75  Msg CriticalWarning "Something went wrong when tried to retrieve version for project $proj"
76  cd $OldPath
77  return
78  } else {
79  # Project was not modified in current version. Let's retrieve the last available link.
80  Msg Info "Retrieving existing link for $proj binaries and tag $ver"
81  lassign [ExecuteRet glab release view $ver] ret msg
82  if {$ret != 0} {
83  Msg Warning "Some problem when fetching release $ver : $msg"
84  } else {
85  set link ""
86  foreach line [split $msg "\n"] {
87  if {[string first "${proj}-${ver}.z" $line] == 0} {
88  set name [lindex [split $line] 0]
89  set link [lindex [split $line] 1]
90  set json "\[{ \"name\": \"$name\",\"url\": \"$link\",\"link_type\": \"other\" } \]"
91  Execute glab release upload $tag --assets-links=$json
92  }
93  }
94  }
95  }
96 }
97 cd $OldPath