20 proc generate_prj_badge {prj_name ver color file} {
21 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
22 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"250\" height=\"20\">
23 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
24 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
25 <stop offset=\"1\" stop-opacity=\".1\"/>
27 <mask id=\"hog_prj_badge\">
28 <rect width=\"250\" height=\"20\" rx=\"10\" fill=\"#fff\"/>
30 <g mask=\"url(#hog_prj_badge)\">
31 <path fill=\"$color\" d=\"M0 0h250v20H0z\"/>
32 <path fill=\"#262626\" d=\"M160 0h90v20H160z\"/>
33 <path fill=\"#262626\" d=\"M250,20 a1,1 0 0,0 0,-16\"/>
34 <path fill=\"url(#b)\" d=\"M0 0h250v20H0z\"/>
36 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
37 <text x=\"80\" y=\"14\">$prj_name</text>
39 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
40 <text x=\"205\" y=\"14\">$ver</text>
49 error "Failed to write to file: $error_msg"
53 proc generate_res_badge {res res_value color file} {
54 set svg_content "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
55 <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"120\" height=\"20\">
56 <linearGradient id=\"b\" x2=\"0\" y2=\"100%\">
57 <stop offset=\"0\" stop-color=\"#bbb\" stop-opacity=\".1\"/>
58 <stop offset=\"1\" stop-opacity=\".1\"/>
60 <mask id=\"hog_res_badge\">
61 <rect width=\"120\" height=\"20\" rx=\"3\" fill=\"#fff\"/>
63 <g mask=\"url(#hog_res_badge)\">
64 <path fill=\"#555\" d=\"M0 0h60v20H0z\"/>
65 <path fill=\"$color\" d=\"M60 0h60v20H60z\"/>
66 <path fill=\"url(#b)\" d=\"M0 0h120v20H0z\"/>
68 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
69 <text x=\"30\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$res</text>
70 <text x=\"30\" y=\"14\">$res</text>
72 <g fill=\"#fff\" text-anchor=\"middle\" font-family=\"DejaVu Sans,Verdana,Geneva,sans-serif\" font-size=\"11\">
73 <text x=\"90\" y=\"15\" fill=\"#010101\" fill-opacity=\".3\">$res_value</text>
74 <text x=\"90\" y=\"14\">$res_value</text>
83 error "Failed to write to file: $error_msg"
89 set TclPath [
file dirname [
info script]]/..
90 set repo_path [
file normalize "$TclPath/../.."]
91 source $TclPath/hog.tcl
93 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>"
95 if { [
llength $argv] < 7 } {
101 set result [
catch {
package require json} JsonFound]
102 if {"$result" != "0"} {
103 Msg CriticalWarning "Cannot find JSON package equal or higher than 1.0.\n $JsonFound\n Exiting"
107 set push_token [
lindex $argv 0]
108 set api_url [
lindex $argv 1]
109 set project_id [
lindex $argv 2]
110 set project_url [
lindex $argv 3]
111 set gitlab_url [
lindex $argv 4]
112 set project [
lindex $argv 5]
113 set ext_path [
lindex $argv 6]
115 set resources [dict create "LUTs" "LUTs" "Registers" "FFs" "Block" "BRAM" "URAM" "URAM" "DSPs" "DSPs"]
119 set current_badges [dict create]
122 Msg Info "Retrieving current badges..."
124 lassign [
ExecuteRet curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges?page=$page" --request GET] ret content
125 set content_dict [json::json2dict $content]
126 if {[
llength $content_dict] > 0} {
127 foreach it $content_dict {
137 if {[
catch {glob -types d $repo_path/bin/$project-${ver}} prj_dir]} {
138 Msg CriticalWarning "Cannot find $project binaries in artifacts"
143 if {[
file exists utilization.txt]} {
144 set fp [open utilization.txt]
145 set lines [
split [read $fp] "\n"]
147 set new_badges [dict create]
148 set prj_name [
string map {/ _} $project]
151 if {[
file exists timing_error.txt]} {
153 }
elseif {[
file exists timing_ok.txt]} {
158 dict set new_badges "timing-$prj_name" "timing-$prj_name"
160 set usage_dict [dict create]
162 foreach line $lines {
163 set str [
string map {| ""} $line]
164 set str [
string map {"<" ""} $str]
165 set str [
string trim $str]
167 set usage [
lindex [
split $str] end]
168 foreach res [dict keys $resources] {
169 if {[
string first $res $str] > -1} {
170 set res_name [dict get $resources $res]
171 dict set usage_dict $res_name $usage
175 foreach res [dict keys $usage_dict] {
176 set usage [
DictGet $usage_dict $res]
177 set res_value "$usage\% "
178 if {[
expr {$usage < 50.0}]} {
180 }
elseif {[
expr {$usage < 80.0}]} {
185 dict set new_badges "$res-$prj_name" "$res-$prj_name"
188 foreach badge_name [dict keys $new_badges] {
190 Msg Info "Uploading badge image $badge_name.svg ...."
191 lassign [
ExecuteRet curl --request POST --header "PRIVATE-TOKEN: ${push_token}" --form "file=@$badge_name.svg" $api_url/projects/$project_id/uploads] ret content
192 set image_url [
ParseJSON $content full_path]
193 set image_url $gitlab_url/$image_url
195 if {[dict exists $current_badges $badge_name]} {
196 Msg Info "Badge $badge_name exists, updating it..."
197 set badge_id [
DictGet $current_badges $badge_name]
198 Execute curl --header "PRIVATE-TOKEN: $push_token" "$api_url/projects/${project_id}/badges/$badge_id" --request PUT --data "image_url=$image_url"
200 Msg Info "Badge $badge_name does not exist yet. Creating it..."
201 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"