Skip to content

Commit

Permalink
通过 GitHub Action 构建 Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 1, 2024
1 parent b9c54f4 commit fa38dab
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 86 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Pages

on:
push:
branches: [master]

concurrency:
group: pages
cancel-in-progress: true

jobs:
pages:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
permissions:
pages: write
id-token: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install pip --upgrade
python -m pip install -r requirements.txt
- name: Build
run: python -m tools.build_www
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./build/outputs
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ Logo 捏他自 [《游戏王》](https://zh.wikipedia.org/wiki/%E9%81%8A%E6%88%B
- [Pillow](https://github.com/python-pillow/Pillow)
- [Beautiful Soup](https://www.crummy.com/software/BeautifulSoup/)
- [Jinja](https://github.com/pallets/jinja)
- [GitPython](https://github.com/gitpython-developers/GitPython)
- [HTTPX](https://github.com/encode/httpx)

## 赞助
Expand Down
1 change: 0 additions & 1 deletion assets/www-static/CNAME

This file was deleted.

1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ PyYAML==6.0.1
pillow==10.3.0
beautifulsoup4==4.12.3
Jinja2==3.1.4
GitPython==3.1.43
httpx==0.27.0
38 changes: 38 additions & 0 deletions tools/build_www.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from tools import configs
from tools.configs import path_define
from tools.configs.dump import DumpConfig
from tools.configs.fallback import FallbackConfig
from tools.configs.font import FontConfig
from tools.services import update_service, dump_service, template_service
from tools.services.font_service import DesignContext, FontContext


def main():
update_service.setup_ark_pixel_glyphs()

font_configs = FontConfig.load_all()
dump_configs = DumpConfig.load_all()
fallback_configs = FallbackConfig.load_all()

for font_size, font_config in font_configs.items():
for dump_config in dump_configs[font_size]:
dump_service.dump_font(dump_config)

for fallback_config in fallback_configs[font_size]:
dump_service.apply_fallback(fallback_config)

design_context = DesignContext.load(font_config, path_define.patch_glyphs_dir)
design_context.standardized()
design_context.fallback(DesignContext.load(font_config, path_define.ark_pixel_glyphs_dir))
design_context.fallback(DesignContext.load(font_config, path_define.fallback_glyphs_dir))
for width_mode in configs.width_modes:
font_context = FontContext(design_context, width_mode)
font_context.make_fonts('woff2')
template_service.make_alphabet_html(design_context, width_mode)
template_service.make_demo_html(design_context)
template_service.make_index_html(font_configs)
template_service.make_playground_html(font_configs)


if __name__ == '__main__':
main()
7 changes: 0 additions & 7 deletions tools/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from tools.configs.deploy import GitDeployConfig
from tools.configs.source import GithubSourceConfig, GitSourceType

font_version = '2024.05.12'
Expand Down Expand Up @@ -64,9 +63,3 @@
source_type=GitSourceType.TAG,
source_name=None,
)

git_deploy_configs = [GitDeployConfig(
url='[email protected]:TakWolf/fusion-pixel-font.git',
remote_name='github',
branch_name='gh-pages',
)]
10 changes: 0 additions & 10 deletions tools/configs/deploy.py

This file was deleted.

2 changes: 0 additions & 2 deletions tools/configs/path_define.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
patch_glyphs_dir = assets_dir.joinpath('patch-glyphs')
fonts_dir = assets_dir.joinpath('fonts')
templates_dir = assets_dir.joinpath('templates')
www_static_dir = assets_dir.joinpath('www-static')

build_dir = project_root_dir.joinpath('build')
cache_dir = build_dir.joinpath('cache')
Expand All @@ -15,6 +14,5 @@
fallback_glyphs_dir = build_dir.joinpath('fallback-glyphs')
outputs_dir = build_dir.joinpath('outputs')
releases_dir = build_dir.joinpath('releases')
www_dir = build_dir.joinpath('www')

docs_dir = project_root_dir.joinpath('docs')
10 changes: 0 additions & 10 deletions tools/deploy_www.py

This file was deleted.

54 changes: 0 additions & 54 deletions tools/services/publish_service.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import datetime
import logging
import os
import re
import shutil
import zipfile

import git

from tools import configs
from tools.configs import path_define

Expand Down Expand Up @@ -40,53 +36,3 @@ def update_docs():
path_to.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path_from, path_to)
logger.info("Copy file: '%s' -> '%s'", path_from, path_to)


def update_www():
if path_define.www_dir.exists():
for path in path_define.www_dir.iterdir():
if path.name == '.git':
continue
if path.is_file():
os.remove(path)
elif path.is_dir():
shutil.rmtree(path)

for file_dir, _, file_names in path_define.www_static_dir.walk():
for file_name in file_names:
if file_name == '.DS_Store':
continue
path_from = file_dir.joinpath(file_name)
path_to = path_define.www_dir.joinpath(path_from.relative_to(path_define.www_static_dir))
path_to.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path_from, path_to)
logger.info("Copy file: '%s' -> '%s'", path_from, path_to)

for file_dir, _, file_names in path_define.outputs_dir.walk():
for file_name in file_names:
if not file_name.endswith(('.html', '.woff2')):
continue
path_from = file_dir.joinpath(file_name)
path_to = path_define.www_dir.joinpath(path_from.relative_to(path_define.outputs_dir))
path_to.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(path_from, path_to)
logger.info("Copy file: '%s' -> '%s'", path_from, path_to)


def deploy_www():
if path_define.www_dir.joinpath('.git').exists():
repo = git.Repo(path_define.www_dir)
else:
repo = git.Repo.init(path_define.www_dir)

if len(repo.git.status('-s').splitlines()) > 0:
repo.git.add(all=True)
repo.git.commit(m=f'deployed at {datetime.datetime.now(datetime.UTC).isoformat()}')

remote_names = repo.git.remote().splitlines()
current_branch_name = repo.git.branch(show_current=True)
for config in configs.git_deploy_configs:
if config.remote_name in remote_names:
repo.git.remote('rm', config.remote_name)
repo.git.remote('add', config.remote_name, config.url)
repo.git.push(config.remote_name, f'{current_branch_name}:{config.branch_name}', '-f')

0 comments on commit fa38dab

Please sign in to comment.