20 proc generate_prj_badge {prj_name ver color file} {
22 set max_characters 20.0
23 puts [
string length $prj_name]
24 if { [
expr {[string length $prj_name] > $max_characters}] } {
25 set scaling_factor [
expr { $max_characters / [string length $prj_name] }]
27 set font_size [
expr {ceil($scaling_factor*$font_size)}]
32 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
33 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"250\" height=\"20\">
34 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
35 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
36 <stop offset=\"1\" stop-opacity=\".1\"/>
38 <mask id=\"hog_prj_badge\">
39 <rect width=\"250\" height=\"20\" rx=\"10\" fill=\"#fff\"/>
41 <g mask=\"url(#hog_prj_badge)\">
42 <path fill=\"$color\" d=\"M0 0h250v20H0z\"/>
43 <path fill=\"#262626\" d=\"M160 0h90v20H160z\"/>
44 <path fill=\"#262626\" d=\"M250,20 a1,1 0 0,0 0,-16\"/>
45 <path fill=\"url(#b)\" d=\"M0 0h250v20H0z\"/>
47 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"$font_size\">
48 <text x=\"80\" y=\"14\">$prj_name</text>
50 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
51 <text x=\"205\" y=\"14\">$ver</text>
60 error "Failed to write to file: $error_msg"
64 proc generate_res_badge {res res_value color file} {
65 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
66 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"120\" height=\"20\">
67 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
68 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
69 <stop offset=\"1\" stop-opacity=\".1\"/>
71 <mask id=\"hog_res_badge\">
72 <rect width=\"120\" height=\"20\" rx=\"3\" fill=\"#fff\"/>
74 <g mask=\"url(#hog_res_badge)\">
75 <path fill=\"#555\" d=\"M0 0h60v20H0z\"/>
76 <path fill=\"$color\" d=\"M60 0h60v20H60z\"/>
77 <path fill=\"url(#b)\" d=\"M0 0h120v20H0z\"/>
79 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
80 <text x=\"30\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$res</text>
81 <text x=\"30\" y=\"14\">$res</text>
83 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
84 <text x=\"90\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$res_value</text>
85 <text x=\"90\" y=\"14\">$res_value</text>
94 error "Failed to write to file: $error_msg"
100 set TclPath [
file dirname [
info script]]/..
101 set repo_path [
file normalize "$TclPath/../.."]
102 source $TclPath/hog.tcl
104 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>"
106 if { [
llength $argv] < 7 } {
112 set result [
catch {
package require json} JsonFound]
113 if {"$result" != "0"} {
114 Msg CriticalWarning "Cannot find JSON package equal or higher than 1.0.\n $JsonFound\n Exiting"
118 set push_token [
lindex $argv 0]
119 set api_url [
lindex $argv 1]
120 set project_id [
lindex $argv 2]
121 set project_url [
lindex $argv 3]
122 set gitlab_url [
lindex $argv 4]
123 set project [
lindex $argv 5]
124 set ext_path [
lindex $argv 6]
126 set resources [dict create "LUTs" "LUTs" "Registers" "FFs" "Block" "BRAM" "URAM" "URAM" "DSPs" "DSPs"]
130 set current_badges [dict create]
133 Msg Info "Retrieving current badges..."
135 lassign [
ExecuteRet curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges?page=$page" --request GET] ret content
136 set content_dict [json::json2dict $content]
137 if {[
llength $content_dict] > 0} {
138 foreach it $content_dict {
148 if {[
catch {glob -types d $repo_path/bin/$project-${ver}} prj_dir]} {
149 Msg CriticalWarning "Cannot find $project binaries in artifacts"
154 if {[
file exists utilization.txt]} {
155 set fp [open utilization.txt]
156 set lines [
split [read $fp] "\n"]
158 set new_badges [dict create]
159 set prj_name [
string map {/ _} $project]
162 if {[
file exists timing_error.txt]} {
164 }
elseif {[
file exists timing_ok.txt]} {
169 dict set new_badges "timing-$prj_name" "timing-$prj_name"
171 set usage_dict [dict create]
173 foreach line $lines {
174 set str [
string map {| ""} $line]
175 set str [
string map {"<" ""} $str]
176 set str [
string trim $str]
178 set usage [
lindex [
split $str] end]
179 foreach res [dict keys $resources] {
180 if {[
string first $res $str] > -1} {
181 set res_name [dict get $resources $res]
182 dict set usage_dict $res_name $usage
186 foreach res [dict keys $usage_dict] {
187 set usage [
DictGet $usage_dict $res]
188 set res_value "$usage\% "
189 if {[
expr {$usage < 50.0}]} {
191 }
elseif {[
expr {$usage < 80.0}]} {
196 dict set new_badges "$res-$prj_name" "$res-$prj_name"
199 foreach badge_name [dict keys $new_badges] {
201 Msg Info "Uploading badge image $badge_name.svg ...."
202 lassign [
ExecuteRet curl --request POST --header "PRIVATE-TOKEN: ${push_token}" --form "file=@$badge_name.svg" $api_url/projects/$project_id/uploads] ret content
203 set image_url [
ParseJSON $content full_path]
204 set image_url $gitlab_url/$image_url
205 if {[dict exists $current_badges $badge_name]} {
206 Msg Info "Badge $badge_name exists, updating it..."
207 set badge_id [
DictGet $current_badges $badge_name]
208 Execute curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges/$badge_id" --request PUT --data "image_url=$image_url"
210 Msg Info "Badge $badge_name does not exist yet. Creating it..."
211 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"