Skip to content

Update action status badge layout #34018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 28, 2025
Merged

Conversation

bytedream
Copy link
Contributor

@bytedream bytedream commented Mar 26, 2025

The current action status badge are looking different from most other badges renders, which is especially noticeable when using them along with other badges. This PR updates the action badges to match the commonly used badges from other providers.

Old (first 3 are gitea badges, the others are from shields.io):
Screenshot_20250326_012707

New:
Screenshot_20250326_022620

A tricky part is the calculation of the text width, which is required to set the correct width of the label and message part of the badge. The used font is DejaVu Sans, which isn't monospaced, so different badge texts with the same letter count may be rendered with different lengths in the browser.
To get the correct width, dynamic text width calculations must be done server side. All widths of printable characters from 0x00 to 0xFF are "prerendered". The comments in badge_glyph_width.go describe how the width generation was done. I've added a build script that downloads the font, renders the width of each supported character (at font size 11) and generates a table/map with all widths that is then used to get the approximate text width. This results in a rather big codegen file, as the font has ~5500 supported characters.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 26, 2025
@github-actions github-actions bot added modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files modifies/internal labels Mar 26, 2025
Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I do not think it is a proper approach to embed font widths at the moment. You can see that font-family="Geneva,DejaVu Sans,sans-serif" there are more fonts and the render might use none of them if there is a fallback.

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 26, 2025
@wxiaoguang
Copy link
Contributor

Some more thoughts:

  1. Do we really need that many "font widths"? I guess no. That badge only renders ASCII letters and numbers.
  2. Do we really need to handle various fonts? I guess no, we could use some "preferred" fonts and use the guessed width. The "preferred" fonts could be carefully chosen to make sure they have similar character widths.

@bytedream
Copy link
Contributor Author

bytedream commented Mar 26, 2025

Sorry but I do not think it is a proper approach to embed font widths at the moment. You can see that font-family="Geneva,DejaVu Sans,sans-serif" there are more fonts and the render might use none of them if there is a fallback.

I looked at the implementation of shields.io and they are using the same approach to get the font width.
GitHub uses 'DejaVu Sans',Verdana,Geneva,sans-serif for their action shields, shields.io Verdana,Geneva,DejaVu Sans,sans-serif. From what I've read they have mostly the same widths with some small differences for some letters. Verdana is the biggest, Geneva the smallest and DejaVu Sans is in between them. The "spec" also recommends using DejaVu Sans.

  1. Do we really need that many "font widths"? I guess no. That badge only renders ASCII letters and numbers.

The label of the badge is the workflow name, non-ascii letters could be used there. But true, I also think this isn't the case so often. For this cases a fallback width could be used.

  1. Do we really need to handle various fonts? I guess no, we could use some "preferred" fonts and use the guessed width. The "preferred" fonts could be carefully chosen to make sure they have similar character widths.

GitHub and shields.io are both using DejaVu Sans, Verdana and Geneva as fonts, so using them as preferred fonts is relatively safe.

@wxiaoguang
Copy link
Contributor

  1. Do we really need that many "font widths"? I guess no. That badge only renders ASCII letters and numbers.

The label of the badge is the workflow name, non-ascii letters could be used there. But true, I also think this isn't the case so often. For this cases a fallback width could be used.

If non-ascii letters would be used, what would happen if there are CJK characters?

@bytedream
Copy link
Contributor Author

bytedream commented Mar 26, 2025

The last commit added a fallback. So any glyph that isn't in the generated width map (like CJK) will use the width of m. m is also used as fallback for shields.io which is why I chose this char to be the fallback

image

@bytedream
Copy link
Contributor Author

Do we really need that many "font widths"? I guess no.

With the fallback implemented, reducing the amount of font/glyph width is a good idea.
Storing only ascii characters is pretty valid. This would result in a map with 95 width entries. I'd extend the supported char range to unicode.MaxLatin1 (\u00FF) which supports some more specials characters and thus may handle more edgecases. This would will result in 188 map entries. I don't know if including said extended char range is really necessary in practice, so I'm also fine if you say ascii only is enough.

@wxiaoguang
Copy link
Contributor

Hmm yes, if we could only store the widths for characters before 0x80 or 0xFF, it would be better.

@bytedream
Copy link
Contributor Author

Done with 0xFF (+ renamed font width to glyph width)

@wxiaoguang wxiaoguang dismissed their stale review March 27, 2025 15:07

dismiss

@GiteaBot GiteaBot added lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. and removed lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged labels Mar 27, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 28, 2025

The rendered images seem strange. Am I wrong?

image

Hmm ..... I guess I know the problem now .... the id conflicts

@wxiaoguang
Copy link
Contributor

Tested with different texts and fonts, seem good.

The last questions:

  1. Do we need to keep build/generate-glyph-width.go? IMO the font widths are fixed and won't change.
  2. (After 1): Maybe we could use once.Value to lazy-init the rune map to avoid consuming CPU&memory for other sub-commands.

@bytedream
Copy link
Contributor Author

bytedream commented Mar 28, 2025

Hmm ..... I guess I know the problem now .... the id conflicts

Oh you also solved this. I did a fix that only changes the devtests (subrequests for each svg).

  1. Do we need to keep build/generate-glyph-width.go? IMO the font widths are fixed and won't change.

My intention with the build script was to have a transparent source how the widths are calculated. But yea I also don't think that they'll ever change

@wxiaoguang
Copy link
Contributor

I made a change in ffc8c1d to use "sync.OnceValue".

Maybe we could either:

  • update the "generate" program
  • add some comments like these widths are generated by `ttfFont.GlyphAdvance(nil, glyphIndex, 11, font.HintingNone)` with https://github.com/dejavu-fonts/dejavu-fonts/releases/download/version_2_37/dejavu-sans-ttf-2.37.zip and then no need to include the "generate" program?

@bytedream
Copy link
Contributor Author

  • add some comments like these widths are generated by `ttfFont.GlyphAdvance(nil, glyphIndex, 11, font.HintingNone)` with https://github.com/dejavu-fonts/dejavu-fonts/releases/download/version_2_37/dejavu-sans-ttf-2.37.zip and then no need to include the "generate" program?

Comments sounds good

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 28, 2025
@wxiaoguang wxiaoguang added the type/enhancement An improvement of existing functionality label Mar 28, 2025
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Mar 28, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 28, 2025
@wxiaoguang wxiaoguang enabled auto-merge (squash) March 28, 2025 14:50
@wxiaoguang wxiaoguang merged commit bf9500b into go-gitea:main Mar 28, 2025
26 checks passed
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 31, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Add toggleClass function in dom.ts (go-gitea#34063)
  Add a config option to block "expensive" pages for anonymous users (go-gitea#34024)
  add additional ReplaceAll in pathsep to cater for different pathsep (go-gitea#34061)
  [skip ci] Updated translations via Crowdin
  enable staticcheck QFxxxx rules (go-gitea#34064)
  update to golangci-lint v2 (go-gitea#34054)
  Add descriptions for private repo public access settings and improve the UI (go-gitea#34057)
  Add anonymous access support for private/unlisted repositories (go-gitea#34051)
  Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (go-gitea#34053)
  Update action status badge layout (go-gitea#34018)
  Add anonymous access support for private repositories (backend) (go-gitea#33257)
  Simplify emoji rendering (go-gitea#34048)
  Adjust the layout of the toolbar on the Issues/Projects page (go-gitea#33667)
  Fix bug on downloading job logs (go-gitea#34041)
  Fix git client accessing renamed repo  (go-gitea#34034)
  Decouple Batch from git.Repository to simplify usage without requiring the creation of a Repository struct. (go-gitea#34001)
  fix org repo creation being limited by user limits (go-gitea#34030)
  Fix the issue with error message logging for the `check-attr` command on Windows OS. (go-gitea#34035)
  Try to fix check-attr bug (go-gitea#34029)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code modifies/templates This PR modifies the template files type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants