20 set TclPath [
file dirname [
info script]]/..
21 set repo_path [
file normalize "$TclPath/../.."]
22 source $TclPath/hog.tcl
24 set usage "- CI script that creates GitLab badges with utilisation and timing results for a chosen Hog project \n USAGE: $::argv0 <push token> <Gitlab api url> <Gitlab project id> <Gitlab project url> <GitLab Server URL> <Hog project> <ext_path>"
26 if { [
llength $argv] < 7 } {
32 set result [
catch {
package require json} JsonFound]
33 if {"$result" != "0"} {
34 Msg CriticalWarning "Cannot find JSON package equal or higher than 1.0.\n $JsonFound\n Exiting"
38 set push_token [
lindex $argv 0]
39 set api_url [
lindex $argv 1]
40 set project_id [
lindex $argv 2]
41 set project_url [
lindex $argv 3]
42 set gitlab_url [
lindex $argv 4]
43 set project [
lindex $argv 5]
44 set ext_path [
lindex $argv 6]
46 set resources [dict create "LUTs" "LUTs" "Registers" "FFs" "Block" "BRAM" "URAM" "URAM" "DSPs" "DSPs"]
54 lassign [
ExecuteRet curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges?page=$page" --request GET] ret content
55 if {[
llength $content] > 0 && $page < 100} {
56 set accumulated "$accumulated$content"
59 set current_badges [json::json2dict $accumulated]
65 if {[
catch {glob -types d $repo_path/bin/$project-${ver}} prj_dir]} {
66 Msg CriticalWarning "Cannot find $project binaries in artifacts"
71 if {[
file exists utilization.txt]} {
72 set fp [open utilization.txt]
73 set lines [
split [read $fp] "\n"]
75 set new_badges [dict create]
76 set prj_name [
string map {/ _} $project]
79 set usage_dict [dict create]
82 set str [
string map {| ""} $line]
83 set str [
string map {"<" ""} $str]
84 set str [
string trim $str]
86 set usage [
lindex [
split $str] end]
87 foreach res [dict keys $resources] {
88 if {[
string first $res $str] > -1} {
89 set res_name [dict get $resources $res]
90 dict set usage_dict $res_name $usage
94 foreach res [dict keys $usage_dict] {
95 set usage [
DictGet $usage_dict $res]
96 append res_value $res ": $usage\% "
99 Execute anybadge -l "$project-$ver" -v "$res_value" -f $prj_name.svg --color=blue -o
100 dict set new_badges "$prj_name" "$prj_name"
103 if {[
file exists timing_error.txt]} {
104 Execute anybadge -l timing -v "FAILED" -f timing-$prj_name.svg --color=red -o
105 }
elseif {[
file exists timing_ok.txt]} {
106 Execute anybadge -l timing -v "OK" -f timing-$prj_name.svg --color=green -o
108 Execute anybadge -l timing -v "UNKNOWN" -f timing-$prj_name.svg --color=orange -o
110 dict set new_badges "timing-$prj_name" "timing-$prj_name"
114 foreach badge_name [dict keys $new_badges] {
116 Msg Info "Uploading badge image $badge_name.svg ...."
117 lassign [
ExecuteRet curl --request POST --header "PRIVATE-TOKEN: ${push_token}" --form "file=@$badge_name.svg" $api_url/projects/$project_id/uploads] ret content
118 set image_url [
ParseJSON $content full_path]
119 set image_url $gitlab_url/$image_url
120 foreach badge $current_badges {
121 set current_badge_name [dict get $badge "name"]
122 set badge_id [dict get $badge "id"]
123 if {$current_badge_name == $badge_name} {
125 Msg Info "Badge $badge_name exists, updating it..."
126 Execute curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges/$badge_id" --request PUT --data "image_url=$image_url"
130 if {$badge_found == 0} {
131 Msg Info "Badge $badge_name does not exist yet. Creating it..."
132 Execute curl --header "PRIVATE-TOKEN: $push_token" --request POST --data "link_url=$project_url/-/releases&image_url=$image_url&name=$badge_name" "$api_url/projects/$project_id/badges"