Skip to content

Commit

Permalink
chore: 更新 CI 脚本
Browse files Browse the repository at this point in the history
Update CI
  • Loading branch information
atxy-blip committed May 15, 2023
2 parents 736c8d5 + c8a224b commit 01235b1
Show file tree
Hide file tree
Showing 11 changed files with 1,180 additions and 385 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:

env:
CTAN_URL: https://mirrors.rit.edu/CTAN
TL_PACKAGES: alphalph auxhook biber biblatex biblatex-gb7714-2015 bigfoot blindtext booktabs caption circledtext cleveref cm-unicode csquotes ctex dashundergaps emptypage enumitem fancyhdr fancyvrb fandol footmisc grfext hologo hycolor hypdoc hyperref l3experimental l3build latexmk libertinus-fonts listings lua-ul lualatex-math luatex85 makecell makeindex mathtools newcomputermodern ninecolors njuvisual ntheorem pict2e preview psnfss setspace siunitx standalone symbol tabularray tex-gyre tex-gyre-math threeparttable translator underscore unicode-math xits xstring zhlipsum zref
PACKAGES: latexmk cleveref enumitem footmisc tex-gyre xits biblatex-gb7714-2015 biber

jobs:
build-on-ubuntu:
Expand All @@ -30,13 +30,20 @@ jobs:
wget ${{ env.CTAN_URL }}/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xzf install-tl-unx.tar.gz
cd install-tl-20* && ./install-tl --profile ../.github/workflows/texlive.profile
tlmgr install ${{ env.TL_PACKAGES }}
tlmgr update --self --all --no-auto-install --repository=${{ env.CTAN_URL }}/systems/texlive/tlnet/
- name: Install latest njuthesis
run: |
${{ env.SET_PATH }}
tlmgr option repository ${{ env.CTAN_URL }}/systems/texlive/tlnet/
tlmgr install xetex l3build
l3build install
cd scripts
bash download.sh ${{ env.CTAN_URL }}
cd data
wget https://raw.githubusercontent.com/stone-zeng/tl-depend-analysis/data/data/tl-depend.json
cd ..
python3 main.py --pkg "${{ env.PACKAGES }}" --exclude "njuthesis-doc.cls"
tlmgr update --self --all --no-auto-install
- name: Compile test file
run: |
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

env:
CTAN_URL: https://mirrors.rit.edu/CTAN
TL_PACKAGES: alphalph auxhook background bibtex bigfoot booktabs caption cm-unicode colortbl csquotes ctex dashundergaps diagbox enumitem everypage fancyhdr fancyvrb fandol footmisc hologo hycolor hypdoc hyperref l3build lexend libertinus-fonts listings lm-math makecell makeindex mathtools natbib ninecolors njuvisual pict2e poormanlog preview psnfss setspace siunitx symbol tabularray tex-gyre tex-gyre-math threeparttable translator underscore unicode-math url xint xits xstring zhlineskip zref
PACKAGES: cm-unicode tex-gyre tex-gyre-math lexend xits natbib makeindex

jobs:
release:
Expand All @@ -32,8 +32,19 @@ jobs:
wget ${{ env.CTAN_URL }}/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xzf install-tl-unx.tar.gz
cd install-tl-20* && ./install-tl --profile ../.github/workflows/texlive.profile
- name: Install latest njuthesis
run: |
${{ env.SET_PATH }}
tlmgr option repository ${{ env.CTAN_URL }}/systems/texlive/tlnet/
tlmgr install ${{ env.TL_PACKAGES }}
tlmgr install xetex l3build
l3build install
cd scripts
bash download.sh ${{ env.CTAN_URL }}
cd data
wget https://raw.githubusercontent.com/stone-zeng/tl-depend-analysis/data/data/tl-depend.json
cd ..
python3 main.py --pkg "${{ env.PACKAGES }}" --exclude "njuthesis.cls"
tlmgr update --self --all --no-auto-install
- name: Install fonts
Expand All @@ -59,7 +70,7 @@ jobs:
mv njuthesis-ctan.zip njuthesis-ctan-$VERSION.zip
mv njuthesis.pdf njuthesis-$VERSION.pdf
- name: Zip RELEASE package
- name: Zip USER package
run: |
${{ env.SET_PATH }}
mv docs/* .
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ test*.pdf
build/
release/
support/
scripts/data
TDS/
temp/
mythesis/
__pycache__/

## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

## [未发布]

### 新增

- 新增定理类环境共享计数器选项 `theorem/share-counter` - [#207]
- 自动补全研究生专业型学位封面上的专业信息 - [#208]
- 增加 `info/major` 定义方式

### 修复

- 修复批量创建环境时缺少 `\crefname` 的问题 - [#206]

### 杂项

- 手册源码部分添加语法高亮
- 手册样式设置拆分为单独的 `njuthesis-doc.cls`
- 使用 [`tl-depend-analysis`] 重构 CI 脚本
- 感谢 [@stone-zeng]

## [1.2.1] - 2023-05-03

### 修复
Expand Down Expand Up @@ -547,14 +564,19 @@
[#200]: https://github.com/nju-lug/NJUThesis/discussions/200
[#202]: https://github.com/nju-lug/NJUThesis/discussions/202
[#204]: https://github.com/nju-lug/NJUThesis/issues/204
[#206]: https://github.com/nju-lug/NJUThesis/issues/206
[#207]: https://github.com/nju-lug/NJUThesis/issues/207
[#208]: https://github.com/nju-lug/NJUThesis/issues/208

[更新日志]: https://keepachangelog.com/zh-CN/1.0.0/
[语义化版本]: https://semver.org/lang/zh-CN/
[南大 TeX]: https://tex.nju.edu.cn/
[NJU Thesis 2021]: https://github.com/FengChendian/NJUThesis2021
[`tl-depend-analysis`]: https://github.com/stone-zeng/tl-depend-analysis/

[@zepinglee]: https://github.com/zepinglee
[@hushidong]: https://github.com/hushidong
[@zhoujian9410]: https://github.com/zhoujian9410
[@note286]: https://github.com/note286
[@AlphaZTX]: https://github.com/AlphaZTX
[@stone-zeng]: https://github.com/stone-zeng
15 changes: 8 additions & 7 deletions docs/njuthesis-setup.def
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
% njuthesis 参数设置文件 v1.2.1 2023-05-03
% njuthesis 参数设置文件 v1.3.0 2023-05-07

% 一些提醒:
% 1. \njusetup 内部千万不要有空行
Expand Down Expand Up @@ -214,12 +214,13 @@
% define,
% 默认创建内置的七种定理环境
%
% style = remark,
% header-font = \sffamily \bfseries,
% body-font = \normalfont,
% qed-symbol = \ensuremath { \male },
% counter = section,
% type = {...}
% style = remark,
% header-font = \sffamily \bfseries,
% body-font = \normalfont,
% qed-symbol = \ensuremath { \male },
% counter = section,
% share-counter = true,
% type = {...}
% 以上设置项在重新调用 theorem/define 后生效
}

Expand Down
1 change: 1 addition & 0 deletions install-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ xetex "njuthesis.dtx" > /dev/null
rm *.dtx
rm *.ins
rm *.log
rm njuthesis-doc.cls

cd ..
1 change: 1 addition & 0 deletions install-win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ xetex "njuthesis.dtx" > NUL
DEL "*.dtx"
DEL "*.ins"
DEL "*.log"
DEL "njuthesis-doc.cls"

CD ..
18 changes: 18 additions & 0 deletions scripts/download.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# https://github.com/stone-zeng/tl-depend-analysis/

if [ -z "$1" ]; then
MIRROR=https://mirror.ctan.org
else
MIRROR=$1
fi

curl -o texlive.tlpdb $MIRROR/systems/texlive/tlnet/tlpkg/texlive.tlpdb
curl -o texlive.tlpdb.sha512 $MIRROR/systems/texlive/tlnet/tlpkg/texlive.tlpdb.sha512
sha512sum -c texlive.tlpdb.sha512
rm texlive.tlpdb.sha512

if [ ! -d data ]; then
mkdir data
fi

mv texlive.tlpdb data/
196 changes: 196 additions & 0 deletions scripts/file_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# https://github.com/stone-zeng/tl-depend-analysis/

import os
import re
import sys
from typing import TextIO


LUA_MODULE_PATTERN = re.compile(r'''
\brequire\s*
\(?\s*["'](.+?)["']
''', re.VERBOSE)
LUALIBS_MODULE_PATTERN = re.compile(r'''
loadmodule\s*
\(*\s*["'](.+\.lua)["']
''', re.VERBOSE)
CLASS_PATTERN = re.compile(r'''
\\(?:LoadClass|LoadClassWithOptions|documentclass)\s*
(?:\[.*\]\s*)?
\{\s*(.+?)\s*\}
''', re.VERBOSE)
PACKAGE_PATTERN = re.compile(r'''
\\(?:RequirePackage|RequirePackageWithOptions|usepackage)\s*
(?:\[.*\]\s*)?
\{\s*(.+?)\s*\}
''', re.VERBOSE)
USEFONT_PATTERN = re.compile(r'''
\\usefont\s*
\{\s*(.+?)\s*\}\s*
\{\s*(.+?)\s*\}
''', re.VERBOSE)


class Parser:

def __init__(self, path: str):
self.path = path
self.state = State()
self.depend: set[str] = set()

def parse(self):
try:
with open(self.path, 'r', encoding='utf-8', errors='replace') as fp:
match os.path.splitext(self.path)[1]:
case '.tex' | '.ltx' | '.cls' | '.sty' | '.def' | '.clo':
self._parse_tex(fp)
case '.lua':
self._parse_lua(fp)
case _:
print('Unknown file type:', self.path, file=sys.stderr)
except FileNotFoundError:
print('File not found:', self.path, file=sys.stderr)

def _parse_lua(self, fp: TextIO):
comment_flag = False
for line in fp:
line = line.strip()
if line.startswith('--[['):
comment_flag = True
continue
if line.endswith(']]') or line.endswith(']]--'):
comment_flag = False
continue
if not comment_flag and not line.startswith('--'):
self.depend.update(self._parse_lua_line(line))

def _parse_lua_line(self, line: str) -> list[str]:
if match := LUA_MODULE_PATTERN.findall(line):
return [match[0] + '.lua']
if match := LUALIBS_MODULE_PATTERN.findall(line):
return [match[0]]
return []

def _parse_tex(self, fp: TextIO):
for line in fp:
if line.rstrip() == '\\endinput':
return
if not line.strip().startswith('%'):
self.depend.update(self._parse_tex_line(line))

def _parse_tex_line(self, line: str) -> list[str]:
if self.state.stack == '':
# Classes (single line)
# - \LoadClass[...]{class}
# - \documentclass[...]{class}
if match := CLASS_PATTERN.findall(line):
return self._parse_cls_sty_match(match, suffix='.cls')

# Packages (single line)
# - \RequirePackage[...]{package}
# - \usepackage[...]{package}
if match := PACKAGE_PATTERN.findall(line):
return self._parse_cls_sty_match(match, suffix='.sty')

# Packages (multiple line)
if '\\RequirePackage' in line or '\\usepackage' in line:
self.state.update(line.split('%')[0].strip())

if match := USEFONT_PATTERN.findall(line):
return self._parse_font_match(match)

return []

self.state.update(line.split('%')[0].strip())

if self.state.is_braces_closed():
match = PACKAGE_PATTERN.findall(self.state.stack)
self.state.reset()
return self._parse_cls_sty_match(match, suffix='.sty')

return []

@staticmethod
def _parse_cls_sty_match(match: list[str], suffix: str) -> list[str]:
res = []
for m in match:
for s in map(str.strip, m.split(',')):
if Parser._is_valid_name(s):
res.append(s + suffix)
return res

@staticmethod
def _parse_font_match(match: list[str]) -> list[str]:
res = []
for m in match:
encoding, family = m
if Parser._is_valid_name(encoding) and Parser._is_valid_name(family):
res.append(f'{encoding.strip()}{family.strip()}.fd'.lower())
return res

@staticmethod
def _is_valid_name(name: str) -> bool:
return (
name != ''
and '\\' not in name and '#' not in name
and not name.startswith('.')
)


class State:
def __init__(self):
self.stack = ''
self.braces_count = 0
self.braces_open = False
self.brackets_count = 0
self.brackets_open = False

def __repr__(self) -> str:
return ', '.join([
f'stack = "{self.stack}"',
f'braces_count = {self.braces_count}',
f'braces_open = {self.braces_open}',
f'brackets_count = {self.brackets_count}',
f'brackets_open = {self.brackets_open}',
])

def update(self, line: str):
self.stack += line
for c in line:
match c:
case '{':
self.braces_count += 1
self.braces_open = True
case '}':
self.braces_count -= 1
case '[':
self.brackets_count += 1
self.brackets_open = True
case ']':
self.brackets_count -= 1
self.brackets_open = False

def is_braces_closed(self):
return self.braces_count == 0 and self.braces_open and not self.brackets_open

def reset(self):
self.stack = ''
self.braces_count = 0
self.braces_open = False
self.brackets_count = 0
self.brackets_open = False


def _main():
if len(sys.argv) < 2:
print('Usage: python file_parser.py <file>', file=sys.stderr)
sys.exit(1)

parser = Parser(sys.argv[1])
parser.parse()
for d in sorted(parser.depend):
print(d)


if __name__ == '__main__':
_main()

0 comments on commit 01235b1

Please sign in to comment.