-
-
Notifications
You must be signed in to change notification settings - Fork 13
Badger 5.x: Laravel 12/13 support, release automation, for-the-badge style #5
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a63d3c8
Add Laravel 12 and 13 support and automated releases
jbrooksuk 279a590
Add for-the-badge style
jbrooksuk 00a8eee
Fix code styling
jbrooksuk 84e4d2c
Address review feedback
jbrooksuk 0006d17
Regenerate for-the-badge snapshots with CI font metrics
jbrooksuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ name: "Fix Code Styling" | |
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| - '*.x' | ||
|
|
||
| jobs: | ||
| lint: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: "Publish Release" | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - 'v*' | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Determine release branch | ||
| id: branch | ||
| run: | | ||
| branch=$(git branch -r --contains "$GITHUB_SHA" --format='%(refname:short)' | sed 's#^origin/##' | grep -E '^[0-9]+\.x$' | head -n1) | ||
| if [ -z "$branch" ]; then | ||
| echo "Could not find a release branch containing $GITHUB_SHA" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "branch=$branch" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Publish release | ||
| uses: softprops/action-gh-release@v2 | ||
| with: | ||
| generate_release_notes: true | ||
|
|
||
| - name: Fetch release notes | ||
| id: notes | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| { | ||
| echo 'body<<RELEASE_NOTES_EOF' | ||
| gh release view "$GITHUB_REF_NAME" --json body --jq .body | ||
| echo 'RELEASE_NOTES_EOF' | ||
| } >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Switch to release branch | ||
| run: git checkout ${{ steps.branch.outputs.branch }} | ||
|
|
||
| - name: Update Changelog | ||
| uses: stefanzweifel/changelog-updater-action@v1 | ||
| with: | ||
| latest-version: ${{ github.ref_name }} | ||
| release-notes: ${{ steps.notes.outputs.body }} | ||
|
|
||
| - name: Commit updated CHANGELOG | ||
| uses: stefanzweifel/git-auto-commit-action@v5 | ||
| with: | ||
| branch: ${{ steps.branch.outputs.branch }} | ||
| commit_message: Update CHANGELOG | ||
| file_pattern: CHANGELOG.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to `cachethq/badger` will be documented in this file. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| namespace Cachet\Badger\Render; | ||
|
|
||
| use Cachet\Badger\Badge; | ||
| use Cachet\Badger\BadgeImage; | ||
|
|
||
| class ForTheBadgeRender extends AbstractRender | ||
| { | ||
| /** | ||
| * The additional horizontal padding applied to each section. | ||
| */ | ||
| protected const EXTRA_PADDING = 10; | ||
|
|
||
| /** | ||
| * The extra width added per character by the template's letter spacing. | ||
| */ | ||
| protected const LETTER_SPACING = 1; | ||
|
|
||
| /** | ||
| * Return a list of supported formats by the render. | ||
| */ | ||
| public function getSupportedFormats(): array | ||
| { | ||
| return ['for-the-badge']; | ||
| } | ||
|
|
||
| /** | ||
| * Render a badge. | ||
| */ | ||
| public function render(Badge $badge): BadgeImage | ||
| { | ||
| $subject = $this->uppercase($badge->subject()); | ||
| $status = $this->uppercase($badge->status()); | ||
|
|
||
| $subjectWidth = $this->sectionWidth($subject); | ||
| $statusWidth = $this->sectionWidth($status); | ||
|
|
||
| $params = [ | ||
| 'vendorWidth' => $subjectWidth, | ||
| 'valueWidth' => $statusWidth, | ||
| 'totalWidth' => $subjectWidth + $statusWidth, | ||
| 'vendorColor' => $this->color, | ||
| 'valueColor' => $badge->hexColor(), | ||
| 'vendor' => $subject, | ||
| 'value' => $status, | ||
| 'vendorStartPosition' => round($subjectWidth / 2, 1) + 1, | ||
| 'valueStartPosition' => $subjectWidth + round($statusWidth / 2, 1) - 1, | ||
| ]; | ||
|
|
||
| return $this->renderSvg($params, $badge->format()); | ||
| } | ||
|
|
||
| /** | ||
| * Uppercase already XML-escaped text without corrupting its entities. | ||
| */ | ||
| protected function uppercase(string $text): string | ||
| { | ||
| return htmlspecialchars( | ||
| mb_strtoupper(htmlspecialchars_decode($text, ENT_XML1)), | ||
| ENT_XML1, | ||
| 'UTF-8' | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Calculate the width of a badge section, accounting for letter spacing and padding. | ||
| */ | ||
| protected function sectionWidth(string $text): float | ||
| { | ||
| return $this->stringWidth($text) + (mb_strlen($text) * self::LETTER_SPACING) + self::EXTRA_PADDING; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the template contents. | ||
| */ | ||
| protected function getTemplate(): string | ||
| { | ||
| return 'for-the-badge.svg'; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.