Skip to content

Commit 136cc07

Browse files
committed
refine
1 parent 070a7f6 commit 136cc07

File tree

3 files changed

+82
-41
lines changed

3 files changed

+82
-41
lines changed

action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: 'Font browser tests'
22
description: 'Test font rendering on different browsers'
33
inputs:
4-
path:
5-
description: 'path to fonts'
4+
paths:
5+
description: 'paths to directory fonts'
66
required: true
77
pt_size:
88
description: 'Set pt size of sample images'
@@ -12,6 +12,10 @@ inputs:
1212
description: 'Diff against an earlier version of the fonts'
1313
required: false
1414
default: 'none'
15+
out:
16+
description: 'Output dir for images'
17+
required: false
18+
default: "screenshots"
1519
width:
1620
description: 'Width of diff images. Default is 1280px'
1721
required: false
@@ -42,7 +46,7 @@ runs:
4246
- name: Gen Screenshots
4347
run: |
4448
chromedriver --url-base=/wd/hub &
45-
python $GITHUB_ACTION_PATH/test.py ${{ inputs.path }} --pt_size ${{ inputs.pt_size }} --fonts_before ${{ inputs.fonts_before }}
49+
python $GITHUB_ACTION_PATH/test.py ${{ inputs.path }} --pt_size ${{ inputs.pt_size }} --fonts_before ${{ inputs.fonts_before }} --out ${{ inputs.out }}
4650
env:
4751
PYTHONIOENCODING: 'utf-8'
4852
PYTHONUTF8: '1'
@@ -52,4 +56,4 @@ runs:
5256
uses: actions/upload-artifact@v2
5357
with:
5458
name: images
55-
path: ./screenshots/img
59+
path: ${{ inputs.out }}

readme.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Font Browser Tests Action
1+
# Diffbrowsers Action
22

3-
Test how your fonts render on different browsers
3+
Test how fonts render on different browsers using `gftools gen-html`
44

5-
## Example
5+
## Usage
66

77
Create a `.github/workflows/test.yml` with the following contents:
88

9-
```
9+
```YAML
1010
on: [push]
1111

1212
jobs:
@@ -15,16 +15,51 @@ jobs:
1515
name: Check fonts on different browsers
1616
steps:
1717
- uses: actions/checkout@v2
18-
- uses: m4rc1e/font-browser-tests-action
18+
- uses: m4rc1e/diffbrowsers-action@latest
19+
with:
20+
path: ./fonts # Path to a directory of fonts
21+
pt_size: 15 # Change text pt size in html docs (Optional)
22+
fonts_before: 'google-fonts' # Diff against previous fonts (Optional)
1923
```
2024
21-
2225
Want to test different operating systems? use a matrix.
2326
27+
```YAML
28+
name: Test screenshots
29+
30+
on:
31+
push:
32+
branches: [main]
33+
34+
jobs:
35+
screenshot:
36+
runs-on: ${{ matrix.os }}
37+
strategy:
38+
matrix:
39+
python-version: [3.9]
40+
os: [ubuntu-latest, windows-latest, macos-latest]
41+
steps:
42+
- uses: actions/checkout@v2
43+
with:
44+
submodules: recursive
45+
fetch-depth: 0
46+
- uses: m4rc1e/diffbrowsers-action@v0.0.34
47+
with:
48+
path: ./fonts
49+
pt_size: 15
50+
fonts_before: google-fonts
51+
width: 1280
2452
```
25-
TODO
53+
54+
55+
Use `upload-artifact` to save the images
56+
57+
```YAML
58+
- name: Create Artifacts
59+
uses: actions/upload-artifact@v2
60+
with:
61+
name: images
62+
path: ./screenshots/img
2663
```
2764

28-
## Inputs
2965

30-
You can further customise the action using the following inputs:

test.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,42 @@
1212

1313

1414
parser = argparse.ArgumentParser()
15-
parser.add_argument("path")
15+
parser.add_argument("--paths", nargs="+", required=True)
1616
parser.add_argument("--pt_size", default=16)
17-
parser.add_argument("--fonts_before")
17+
parser.add_argument("--fonts_before", default="none")
1818
parser.add_argument("--width", type=int, default=1280)
19+
parser.add_argument("--out", default="screenshots")
1920
args = parser.parse_args()
2021

22+
os.mkdir(args.out)
2123

22-
fonts = glob(os.path.join(args.path, "*.ttf"))
23-
24-
# User just wants proofs
25-
if args.fonts_before == "none":
26-
html = HtmlProof(
27-
fonts,
28-
out="screenshots",
29-
selenium_screenshots=True
30-
)
31-
else:
32-
# User wants to diff against Google Fonts
24+
for font_dir in args.paths:
25+
fonts = glob(os.path.join(font_dir, "*.ttf"))
3326
ttFont = TTFont(fonts[0])
3427
family_name = font_familyname(ttFont)
35-
if args.fonts_before == "google-fonts":
36-
os.mkdir("fonts_before")
37-
fonts_before = download_family_from_Google_Fonts(
38-
family_name,
39-
"fonts_before"
28+
out = os.path.join(args.out, family_name)
29+
30+
# User just wants proofs
31+
if args.fonts_before == "none":
32+
html = HtmlProof(
33+
fonts,
34+
out=out,
35+
selenium_screenshots=True
36+
)
37+
else:
38+
# User wants to diff against Google Fonts
39+
if args.fonts_before == "google-fonts":
40+
os.mkdir("fonts_before")
41+
fonts_before = download_family_from_Google_Fonts(
42+
family_name,
43+
"fonts_before"
44+
)
45+
html = HtmlDiff(
46+
fonts_before,
47+
fonts,
48+
out=out,
49+
selenium_screenshots=True
4050
)
41-
# TODO add more font_before inputs
42-
html = HtmlDiff(
43-
fonts_before,
44-
fonts,
45-
out="screenshots",
46-
selenium_screenshots=True
47-
)
48-
4951

50-
html.build_pages(pt_size=args.pt_size)
51-
html.save_imgs(width=args.width)
52+
html.build_pages(pt_size=args.pt_size)
53+
html.save_imgs(width=args.width)

0 commit comments

Comments
 (0)