Skip to content

Commit

Permalink
Migrated to TypeScript, switched to local Badgen instance
Browse files Browse the repository at this point in the history
Improved icon support as well, allowing for both links and Base64 encoded SVGs.
  • Loading branch information
RubbaBoy committed Nov 25, 2021
1 parent 9909838 commit 24f4642
Show file tree
Hide file tree
Showing 19 changed files with 5,767 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ doc/api/
*.iml

dist/
!workers/badgen/dist
node_modules/
worker/
wrangler.toml
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Adam Yarris
Copyright (c) 2021 Adam Yarris

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

![](https://byob.yarr.is/RubbaBoy/BYOBTest/git)

#### Custom Icon
#### Custom Icon URL

```yaml
NAME: custom
Expand All @@ -78,6 +78,19 @@ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

![](https://byob.yarr.is/RubbaBoy/BYOBTest/custom)

#### Custom Icon Inline SVG

```yaml
NAME: custom
ICON: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI0YwMCI+PHBhdGggZD0iTTAgMGgyNHYyNEgweiIgZmlsbD0ibm9uZSIvPjxwYXRoIGQ9Ik0xMiAyMS4zNWwtMS40NS0xLjMyQzUuNCAxNS4zNiAyIDEyLjI4IDIgOC41IDIgNS40MiA0LjQyIDMgNy41IDNjMS43NCAwIDMuNDEuODEgNC41IDIuMDlDMTMuMDkgMy44MSAxNC43NiAzIDE2LjUgMyAxOS41OCAzIDIyIDUuNDIgMjIgOC41YzAgMy43OC0zLjQgNi44Ni04LjU1IDExLjU0TDEyIDIxLjM1eiIvPjwvc3ZnPg=='
STATUS: 'Custom Icons'
COLOR: blue
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```

The above `ICON` value is a Base64 encoded representation of a colored SVG [Material Icon](https://fonts.google.com/icons?selected=Material+Icons). This provides for great flexibility, with the benefit of keeping it local. The resulting icon is:

![](https://byob.yarr.is/RubbaBoy/BYOBTest/custom_inline)

Other URL schemes are supported as well. The general scheme after `https://byob.yarr.is/` is:

Expand Down Expand Up @@ -131,22 +144,22 @@ ACTOR: RubbaBoy
### Inputs

| **Name** | **Required** | **Default** | **Description** |
| ------------ | ----- | --------------- | ------------------------------------------------------------ |
| name | yes | | The alphanumeric (-_ included) name of the badge, 32 chars or less. Used only for identification purposes. |
| label | yes | | The left label of the badge, usually static. |
| icon | yes | | An icon name from [badgen](https://badgen.net/), or an SVG URL |
| status | yes | | The right status as the badge, usually based on results. |
| color | yes | | The hex color of the badge. |
| github_token | yes | | The GitHub token to push to the current repo. Suggested as `${{ secrets.GITHUB_TOKEN }}` |
| path | no | `/shields.json` | The absolute file path to store the JSON data to. |
| branch | no | `shields` | The branch to contain the shields file. |
| repository | no | | Allows to publish json to an alternate repo. Useful to host the json in a public repo and have the action in a private repo. |
| actor | no | | Required if repository is specified to use along with custom GitHub Access token |
| ------------ | ------------ | --------------- | ------------------------------------------------------------ |
| name | yes | | The alphanumeric (-_ included) name of the badge, 32 chars or less. Used only for identification purposes. |
| label | yes | | The left label of the badge, usually static. |
| icon | yes | | An icon name from [badgen](https://badgen.net/), an SVG URL, or a Base64 Encoded representation of an SVG |
| status | yes | | The right status as the badge, usually based on results. |
| color | yes | | The hex color of the badge. |
| github_token | yes | | The GitHub token to push to the current repo. Suggested as `${{ secrets.GITHUB_TOKEN }}` |
| path | no | `/shields.json` | The absolute file path to store the JSON data to. |
| branch | no | `shields` | The branch to contain the shields file. |
| repository | no | | Allows to publish json to an alternate repo. Useful to host the json in a public repo and have the action in a private repo. |
| actor | no | | Required if repository is specified to use along with custom GitHub Access token |

## How It Works

BYOB is very simple, consisting of the GitHub Action and a small server-side script. The Action updates a json file containing all badge info. This is by default the `shields` branch as to keep the commit history clean on working branches. Each badge has a name associated with it only used for identification purposes, and is not displayed.

When the Action is invoked, it will update only the badge names that have changed, to allow for more persistent data. Whenever a badge is invoked, a push is made to the repo updating the file. No badge data is stored server-side.

The actual badges hosted by [Badgen](https://badgen.net/) (A great service, check it out if you have a chance!). The hosted endpoint uses the code [here](https://github.com/RubbaBoy/BYOB/blob/master/index.js). It reads the given repositories' JSON file containing shields data in it, and returns a Badgen-generated badge. This uses the static Badgen `/badge` endpoint to allow for much less caching, as paired with GitHub's aggressive caching it can be extremely slow.
The actual badges are generated by [Badgen](https://github.com/badgen/badgen) (A great service/API, check it out if you have a chance!). The hosted endpoint uses the code [here](https://github.com/RubbaBoy/BYOB/blob/master/workers/src/handler.ts). It reads the given repositories' JSON file containing shields data in it, and returns a Badgen-generated badge.
5 changes: 5 additions & 0 deletions workers/badgen/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Copyright 2018 Amio

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8 changes: 8 additions & 0 deletions workers/badgen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This is the packed source of [badgen](https://github.com/badgen/badgen), the badge-generator powering BYOB. The normal npm package could not be used, as Cloudflare Workers can't use Node libraries. I might just be stupid and overlooking something very basic, if so, let me know!

To rebuild these sources from the latest badgen commit, invoke
```bash
./build_badgen.sh
```

And the packaged files will be updated.
16 changes: 16 additions & 0 deletions workers/badgen/build_badgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rm -rf dist/*.js dist/*.js.map dist/*.ts
git clone https://github.com/badgen/badgen
cd badgen
npm run build:node
npm run build:types
cd ..
cp badgen/dist/*.* ./dist
rm -rf badgen

rm icons.json
git clone https://github.com/badgen/badgen-icons
node badgen-icons/build.js
cp badgen-icons/icons.json ./dist
rm -rf badgen-icons

echo "Updated badgen & icons!"
1 change: 1 addition & 0 deletions workers/badgen/dist/calc-text-width.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const Verdana110: ([...text]: Iterable<any>) => number;
14 changes: 14 additions & 0 deletions workers/badgen/dist/color-presets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
declare const _default: {
green: string;
blue: string;
red: string;
yellow: string;
orange: string;
purple: string;
pink: string;
grey: string;
gray: string;
cyan: string;
black: string;
};
export default _default;
Loading

0 comments on commit 24f4642

Please sign in to comment.