From c7d8aec8e8ea482a6f585ca19fb1048e334c34c8 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Mon, 31 Oct 2022 17:40:06 +0800 Subject: [PATCH 01/13] feat: l3build add-contrib --- src/build.lua | 68 ++++++++++++++++++- src/support/newcontrib.template.tex | 11 +++ .../sjtubeamerthemenewcontrib.template.ltx | 21 ++++++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/support/newcontrib.template.tex create mode 100644 src/support/sjtubeamerthemenewcontrib.template.ltx diff --git a/src/build.lua b/src/build.lua index 31c4a2b8..4533432f 100644 --- a/src/build.lua +++ b/src/build.lua @@ -412,7 +412,9 @@ if options["target"] == "add-demo" then -- modify the number in usr doc content. local cnt - usrdoccontent, cnt = string.gsub(usrdoccontent, "step" .. string.gsub(string.gsub(oldid,"%+","%%+"),"%-","%%-") .. "%.", "step" .. newid .. ".") -- avoid the magical character insertion + usrdoccontent, cnt = string.gsub(usrdoccontent, "step" .. + string.gsub(string.gsub(oldid,"%+","%%+"),"%-","%%-") .. + "%.", "step" .. newid .. ".") -- avoid the magical character insertion print("step" .. oldid .. " -> " .. "step" .. newid .. " Doc replaced: " .. cnt) end @@ -435,4 +437,68 @@ if options["target"] == "add-demo" then adddemo(demonum) os.exit(0) +end + +-- usage: l3build add-contrib [pluginname] +-- description: initialize a plugin called [pluginname]. +if options["target"] == "add-contrib" then + if options["names"] == nil or #options["names"] > 1 then + print("Error: Please specify one and only one contrib name. (" .. module .. ")") + os.exit(1) + end + + local pluginname = options["names"][1] + + local function addcontrib(pluginname) + local contribdir = "../contrib" + local plugindir = contribdir .. "/" .. pluginname + if not direxists(plugindir) then + -- make plugin directory + mkdir(plugindir) + + -- generate plugin document itself + cp("sjtubeamerthemenewcontrib.template.ltx", supportdir, plugindir) + ren(plugindir, "sjtubeamerthemenewcontrib.template.ltx", "sjtubeamertheme" .. pluginname .. ".ltx") + local pluginpath = plugindir .. "/" .. "sjtubeamertheme" .. pluginname .. ".ltx" + local pluginfile = io.open(pluginpath, 'r') + local pluginfilecontent = pluginfile:read('a') + pluginfile:close() + pluginfilecontent = string.gsub( + string.gsub( + string.gsub(pluginfilecontent, "", os.date("%Y")), + "0000/00/00",os.date("%Y/%m/%d")), + "newcontrib", pluginname + ) + local author = io.popen("git config --get user.name",'r') -- get author info + if author ~= nil then + pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) + end + author:close() + pluginfile = io.open(pluginpath, 'w') + pluginfile:write(pluginfilecontent) + pluginfile:close() + + -- generate plugin documentation + cp("newcontrib.template.tex", supportdir, plugindir) + ren(plugindir, "newcontrib.template.tex", pluginname .. ".tex") + local plugindocpath = plugindir .. "/" .. pluginname .. ".tex" + local plugindocfile = io.open(plugindocpath, 'r') + local plugindoccontent = plugindocfile:read('a') + plugindocfile:close() + plugindoccontent = string.gsub(plugindoccontent, "newcontrib", pluginname) + plugindocfile = io.open(plugindocpath, 'w') + plugindocfile:write(plugindoccontent) + plugindocfile:close() + + print(pluginname .. " plugin is created.") + print(" > Plugin itself: " .. pluginpath) + print(" > Plugin documentation: " ..plugindocpath) + else + print("Error: " .. pluginname .. " has already existed.") + os.exit(1) + end + end + + addcontrib(pluginname) + os.exit(0) end \ No newline at end of file diff --git a/src/support/newcontrib.template.tex b/src/support/newcontrib.template.tex new file mode 100644 index 00000000..9d5d4a22 --- /dev/null +++ b/src/support/newcontrib.template.tex @@ -0,0 +1,11 @@ +\documentclass{ctexbeamer} +\usetheme{sjtubeamer} +\usesjtutheme{newcontrib} +\begin{document} + \begin{frame} + \frametitle{newcontrib 插件} + + % 插件文档... + + \end{frame} +\end{document} \ No newline at end of file diff --git a/src/support/sjtubeamerthemenewcontrib.template.ltx b/src/support/sjtubeamerthemenewcontrib.template.ltx new file mode 100644 index 00000000..eff97408 --- /dev/null +++ b/src/support/sjtubeamerthemenewcontrib.template.ltx @@ -0,0 +1,21 @@ +%% ------------------------------------------------------------------------ +%% Copyright (C) +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% ------------------------------------------------------------------------ +% 文件元数据 +\ProvidesFile{sjtubeamerthemenewcontrib.ltx}[0000/00/00 newcontrib for sjtubeamer] +% 传入选项的处理 +\if\EqualOption{newcontrib}{debug}{true} + \PackageInfo{You are debugging newcontrib} +\fi \ No newline at end of file From ba150dd142a2b5f3f8297dbbf2795540c6953c69 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Mon, 31 Oct 2022 17:44:05 +0800 Subject: [PATCH 02/13] ci: format --- src/support/newcontrib.template.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/support/newcontrib.template.tex b/src/support/newcontrib.template.tex index 9d5d4a22..430a9ab5 100644 --- a/src/support/newcontrib.template.tex +++ b/src/support/newcontrib.template.tex @@ -2,10 +2,10 @@ \usetheme{sjtubeamer} \usesjtutheme{newcontrib} \begin{document} - \begin{frame} - \frametitle{newcontrib 插件} +\begin{frame} + \frametitle{newcontrib 插件} - % 插件文档... + % 插件文档... - \end{frame} +\end{frame} \end{document} \ No newline at end of file From 8dd550c3a6aa85917f23a9191c0b50047ba041b2 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 01:17:29 +0800 Subject: [PATCH 03/13] fix: author substitution --- src/build.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/build.lua b/src/build.lua index 4533432f..a55afc07 100644 --- a/src/build.lua +++ b/src/build.lua @@ -471,7 +471,7 @@ if options["target"] == "add-contrib" then ) local author = io.popen("git config --get user.name",'r') -- get author info if author ~= nil then - pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) + pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) end author:close() pluginfile = io.open(pluginpath, 'w') From 2b8b9555e6f0a7b7ecb094f80ce17fc03bd61681 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 01:30:25 +0800 Subject: [PATCH 04/13] fix: no author when no git --- src/build.lua | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/build.lua b/src/build.lua index a55afc07..2c43488b 100644 --- a/src/build.lua +++ b/src/build.lua @@ -469,11 +469,14 @@ if options["target"] == "add-contrib" then "0000/00/00",os.date("%Y/%m/%d")), "newcontrib", pluginname ) - local author = io.popen("git config --get user.name",'r') -- get author info - if author ~= nil then - pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) + local errorlevel = os.execute("git --version") + if errorlevel == 0 then + local author = io.popen("git config --get user.name",'r') -- get author info + if author ~= nil then + pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) + end + author:close() end - author:close() pluginfile = io.open(pluginpath, 'w') pluginfile:write(pluginfilecontent) pluginfile:close() From 75acd6cd1c6196a0084b21495fa3f91d81593d2c Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 10:36:02 +0800 Subject: [PATCH 05/13] feat: add email to plugin --- contrib/minted/sjtubeamerthememinted.ltx | 2 +- contrib/poster/sjtubeamerthemeposter.ltx | 2 +- contrib/sjtug/sjtubeamerthemesjtug.ltx | 2 +- src/build.lua | 10 +++++++++- src/support/sjtubeamerthemenewcontrib.template.ltx | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/contrib/minted/sjtubeamerthememinted.ltx b/contrib/minted/sjtubeamerthememinted.ltx index a5139f17..9824bb2d 100644 --- a/contrib/minted/sjtubeamerthememinted.ltx +++ b/contrib/minted/sjtubeamerthememinted.ltx @@ -1,5 +1,5 @@ %% ------------------------------------------------------------------------ -%% Copyright (C) 2022 LogCreative +%% Copyright (C) 2022 LogCreative %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/contrib/poster/sjtubeamerthemeposter.ltx b/contrib/poster/sjtubeamerthemeposter.ltx index 36275a5d..40382b9a 100644 --- a/contrib/poster/sjtubeamerthemeposter.ltx +++ b/contrib/poster/sjtubeamerthemeposter.ltx @@ -1,5 +1,5 @@ %% ------------------------------------------------------------------------ -%% Copyright (C) 2022 LogCreative +%% Copyright (C) 2022 LogCreative %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/contrib/sjtug/sjtubeamerthemesjtug.ltx b/contrib/sjtug/sjtubeamerthemesjtug.ltx index 33f4a2c8..129c1f39 100644 --- a/contrib/sjtug/sjtubeamerthemesjtug.ltx +++ b/contrib/sjtug/sjtubeamerthemesjtug.ltx @@ -1,5 +1,5 @@ %% ------------------------------------------------------------------------ -%% Copyright (C) 2022 LogCreative +%% Copyright (C) 2022 LogCreative %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. diff --git a/src/build.lua b/src/build.lua index 2c43488b..b6d9f353 100644 --- a/src/build.lua +++ b/src/build.lua @@ -469,13 +469,21 @@ if options["target"] == "add-contrib" then "0000/00/00",os.date("%Y/%m/%d")), "newcontrib", pluginname ) + -- get information from git + -- no swap when no git + print('Trying to get author and email information from:') local errorlevel = os.execute("git --version") if errorlevel == 0 then local author = io.popen("git config --get user.name",'r') -- get author info if author ~= nil then - pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*a')) + pluginfilecontent = string.gsub(pluginfilecontent, '', author:read('*l')) end author:close() + local email = io.popen("git config --get user.email",'r') -- get author email + if email ~= nil then + pluginfilecontent = string.gsub(pluginfilecontent, '', '<' .. email:read('*l') .. '>') + end + email:close() end pluginfile = io.open(pluginpath, 'w') pluginfile:write(pluginfilecontent) diff --git a/src/support/sjtubeamerthemenewcontrib.template.ltx b/src/support/sjtubeamerthemenewcontrib.template.ltx index eff97408..8cbb2e4f 100644 --- a/src/support/sjtubeamerthemenewcontrib.template.ltx +++ b/src/support/sjtubeamerthemenewcontrib.template.ltx @@ -1,5 +1,5 @@ %% ------------------------------------------------------------------------ -%% Copyright (C) +%% Copyright (C) %% %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. From 0432edf592fc6571e66d54eaabfaac460d84931b Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 13:18:40 +0800 Subject: [PATCH 06/13] style: make contribdir public --- src/build.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/build.lua b/src/build.lua index b6d9f353..641cb82d 100644 --- a/src/build.lua +++ b/src/build.lua @@ -439,6 +439,9 @@ if options["target"] == "add-demo" then os.exit(0) end +-- contrib directory +contribdir = "../contrib" + -- usage: l3build add-contrib [pluginname] -- description: initialize a plugin called [pluginname]. if options["target"] == "add-contrib" then @@ -450,7 +453,6 @@ if options["target"] == "add-contrib" then local pluginname = options["names"][1] local function addcontrib(pluginname) - local contribdir = "../contrib" local plugindir = contribdir .. "/" .. pluginname if not direxists(plugindir) then -- make plugin directory From 050725641ae44b4836f544d1046a620a5f12297a Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 13:25:35 +0800 Subject: [PATCH 07/13] docs: prompts after l3build add-contrib --- src/build.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/build.lua b/src/build.lua index 641cb82d..f1a0d282 100644 --- a/src/build.lua +++ b/src/build.lua @@ -458,7 +458,7 @@ if options["target"] == "add-contrib" then -- make plugin directory mkdir(plugindir) - -- generate plugin document itself + -- generate plugin itself cp("sjtubeamerthemenewcontrib.template.ltx", supportdir, plugindir) ren(plugindir, "sjtubeamerthemenewcontrib.template.ltx", "sjtubeamertheme" .. pluginname .. ".ltx") local pluginpath = plugindir .. "/" .. "sjtubeamertheme" .. pluginname .. ".ltx" @@ -506,6 +506,9 @@ if options["target"] == "add-contrib" then print(pluginname .. " plugin is created.") print(" > Plugin itself: " .. pluginpath) print(" > Plugin documentation: " ..plugindocpath) + print("To debug the plugin, install the current version of sjtubeamer globally first by:") + print(" l3build install") + print("Then compile the documentation in the contrib directory: " .. plugindir) else print("Error: " .. pluginname .. " has already existed.") os.exit(1) @@ -514,4 +517,4 @@ if options["target"] == "add-contrib" then addcontrib(pluginname) os.exit(0) -end \ No newline at end of file +end From f0cb8ddbee5ce41057f640350f6944076c1a975a Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 13:35:45 +0800 Subject: [PATCH 08/13] docs: dev doc about l3build add-contrib --- src/doc/sjtubeamerdevguide.tex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/sjtubeamerdevguide.tex b/src/doc/sjtubeamerdevguide.tex index c13e94a0..38fe7326 100644 --- a/src/doc/sjtubeamerdevguide.tex +++ b/src/doc/sjtubeamerdevguide.tex @@ -191,6 +191,8 @@ \subsubsection{Exclusive Commands}\label{sec:exclcmd} \end{tabular} \end{table} +\fcmd{l3build add-contrib test} This command will create a plugin called \texttt{test} in the directory \texttt{../contrib}. This command will grab the information from \texttt{git} to fill the blanks of ``author'' and ``email'' (left blank when no git is installed). + \subsection{Customize Generation}\label{sec:precompile} In \verb"source/beamerthemesjtubeamer.ins", you could customize what templates you want to output on the line: From 7b67d74bf518a922db32f35ce63fae3e449c4252 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 17:28:46 +0800 Subject: [PATCH 09/13] ci: add contrib skip commit identifier --- .github/workflows/contrib.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 298a0308..237ac615 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -16,6 +16,7 @@ name: Contrib jobs: build-contrib: runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, 'contrib skip')" # permission to the environment will # need to be approved by one of the collaborators environment: IMGUR From bae9e78e4dac1968bc9312fe8eb30aaf9e058912 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 17:43:09 +0800 Subject: [PATCH 10/13] ci: test tag [contrib skip] --- .github/workflows/contrib.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 237ac615..7d01dbd0 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -16,6 +16,7 @@ name: Contrib jobs: build-contrib: runs-on: ubuntu-latest + # ignore the commit with [contrib skip] tag. if: "!contains(github.event.head_commit.message, 'contrib skip')" # permission to the environment will # need to be approved by one of the collaborators From 359b523d77174260f6b1a6bd920fcb90e7d9c60b Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 18:01:30 +0800 Subject: [PATCH 11/13] ci: use ci-skip action [contrib skip] --- .github/workflows/contrib.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 7d01dbd0..a430a0ab 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -16,8 +16,6 @@ name: Contrib jobs: build-contrib: runs-on: ubuntu-latest - # ignore the commit with [contrib skip] tag. - if: "!contains(github.event.head_commit.message, 'contrib skip')" # permission to the environment will # need to be approved by one of the collaborators environment: IMGUR @@ -26,6 +24,10 @@ jobs: name: checkout code with: fetch-depth: 0 + - uses: mstachniuk/ci-skip@v1 + with: + commit-filter: 'contrib skip;skip contrib' + commit-filter-separator: ';' - name: get newly contributed package (pull request) if: github.event_name == 'pull_request' run: | From cc3507e13c119f4c5ce3119cf6823a782abb4fbb Mon Sep 17 00:00:00 2001 From: LogCreative Date: Tue, 1 Nov 2022 18:04:18 +0800 Subject: [PATCH 12/13] Revert "ci: use ci-skip action [contrib skip]" This reverts commit 359b523d77174260f6b1a6bd920fcb90e7d9c60b. --- .github/workflows/contrib.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index a430a0ab..7d01dbd0 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -16,6 +16,8 @@ name: Contrib jobs: build-contrib: runs-on: ubuntu-latest + # ignore the commit with [contrib skip] tag. + if: "!contains(github.event.head_commit.message, 'contrib skip')" # permission to the environment will # need to be approved by one of the collaborators environment: IMGUR @@ -24,10 +26,6 @@ jobs: name: checkout code with: fetch-depth: 0 - - uses: mstachniuk/ci-skip@v1 - with: - commit-filter: 'contrib skip;skip contrib' - commit-filter-separator: ';' - name: get newly contributed package (pull request) if: github.event_name == 'pull_request' run: | From c95fca9da7f7bf9b92c4a3ad916d26694c81ac20 Mon Sep 17 00:00:00 2001 From: LogCreative Date: Wed, 2 Nov 2022 08:59:54 +0800 Subject: [PATCH 13/13] ci: remove detecting contrib ci label --- .github/workflows/contrib.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/contrib.yml b/.github/workflows/contrib.yml index 7d01dbd0..51724bda 100644 --- a/.github/workflows/contrib.yml +++ b/.github/workflows/contrib.yml @@ -16,8 +16,6 @@ name: Contrib jobs: build-contrib: runs-on: ubuntu-latest - # ignore the commit with [contrib skip] tag. - if: "!contains(github.event.head_commit.message, 'contrib skip')" # permission to the environment will # need to be approved by one of the collaborators environment: IMGUR @@ -101,4 +99,4 @@ jobs: join(fromJSON(steps.contrib_png.outputs.markdown_urls), ' ') ) }} - name: comment (push) \ No newline at end of file + name: comment (push)