From debfddd081bba3ffb2428da77725e6c100ca1913 Mon Sep 17 00:00:00 2001 From: ATQlove Date: Wed, 31 Jul 2024 20:27:39 +0800 Subject: [PATCH] Convert jingkaimori doc to html for CICD (#35) --- .../workflows/cd-convert-debian-bookworm.yml | 39 ++++++++++++ CICD/tm2html_CICD.scm | 61 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/cd-convert-debian-bookworm.yml create mode 100644 CICD/tm2html_CICD.scm diff --git a/.github/workflows/cd-convert-debian-bookworm.yml b/.github/workflows/cd-convert-debian-bookworm.yml new file mode 100644 index 0000000..bfc8175 --- /dev/null +++ b/.github/workflows/cd-convert-debian-bookworm.yml @@ -0,0 +1,39 @@ +name: CI/CD for Converting tm format to html + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + container: debian:bookworm + runs-on: ubuntu-22.04 + steps: + - name: Install dependencies + run: apt-get update && apt-get install -y wget git + + - uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: download release from mogan research repository + run: | + wget https://github.com/XmacsLabs/mogan/releases/download/v1.2.8-rc1/mogan-research-v1.2.8-rc1-debian12.deb -O /tmp/mogan-research.deb + DEBIAN_FRONTEND=noninteractive apt install -y /tmp/mogan-research.deb + + - name: convert document to html format + run: | + /usr/bin/MoganResearch -headless -b CICD/tm2html_CICD.scm -x "(tm2html_CICD)" -q + + # Deploy to local repo + - name: Deploy + uses: s0/git-publish-subdir-action@develop + env: + REPO: self + BRANCH: gh-pages + FOLDER: CICD/html + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/CICD/tm2html_CICD.scm b/CICD/tm2html_CICD.scm new file mode 100644 index 0000000..5e2a71d --- /dev/null +++ b/CICD/tm2html_CICD.scm @@ -0,0 +1,61 @@ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; MODULE : tm2html_CICD.scm +;; DESCRIPTION : Convert tm format to html for CICD +;; COPYRIGHT : (C) 2024 ATQlove +;; +;; This software falls under the GNU general public license version 3 or later. +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE +;; in the root directory or . +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define (list-files dir) + (let* ((filtered-files (url->list + (url-expand + (url-complete + (url-append (url-descendants dir) + (url-or (url-wildcard "*.tm") + (url-wildcard "*.tmu"))) + "fr"))))) + ; (display "Filtered files:\n") + ; (for-each (lambda (file) (display (string-append (url->string file) "\n"))) filtered-files) + filtered-files)) + +(define (export-file-to-html file base-dir output-dir) + (let* ((relative-path (url-delta base-dir file)) + (output-file-url (url-append output-dir relative-path)) + (output-file-url (url-unglue output-file-url 3)) ; Remove ".tm" or ".tmu" extension + (html-file-url (url-glue output-file-url ".html")) + (output-dir-url (url-head html-file-url))) + + ; Debugging information; expect information are just some example + (display (string-append "Base directory: " (url->string base-dir) "\n")) ; Expect: file:///F:/mogan/planet/CICD/try + (display (string-append "File: " (url->string file) "\n")) ; Expect: file:///F:/mogan/planet/CICD/try/2/24_10_tmhtml_test.tmu + (display (string-append "Relative path: " (url->string relative-path) "\n")) ; Expect: /2/24_10_tmhtml_test.tmu + (display (string-append "Output file URL (before unglue): " (url->string output-file-url) "\n")) ; Expect: file:///F:/mogan/planet/CICD/html/2/24_10_tmhtml_test.tmu + (display (string-append "Output file URL (after unglue): " (url->string (url-unglue output-file-url 3)) "\n")) ; Expect: file:///F:/mogan/planet/CICD/html/2/24_10_tmhtml_test + (display (string-append "HTML file URL: " (url->string html-file-url) "\n")) ; Expect: file:///F:/mogan/planet/CICD/html/2/24_10_tmhtml_test.html + (display (string-append "Output directory URL: " (url->string output-dir-url) "\n")) ; Expect: file:///F:/mogan/planet/CICD/html/2 + + (make-directory (url->string output-dir-url)) + (display (string-append "Exporting " (url->string file) " to " (url->string html-file-url) "\n")) + (load-buffer (url->string file)) + (export-buffer-main (current-buffer) (url->string html-file-url) "html" ()))) + +(define (make-directory dir) + (system (string-append "mkdir -p " dir))) + +(define (export-directory dir output-dir) + (let* ((files (list-files dir))) + (for-each (lambda (file) + (export-file-to-html file dir output-dir)) + files))) + +(tm-define (tm2html_CICD) + (url-exists? "/__w/planet/planet/jingkaimori") + (url-exists? "/__w/planet/planet/CICD") + (export-directory "/__w/planet/planet/jingkaimori" "/__w/planet/planet/CICD/html") + (display "Conversion from tm/tmu to html end\n")) + \ No newline at end of file