浏览代码

【修复】优化 HTML 文件生成和部署流程

- 修改包名为 markdown-html-generator
- 更新 target-dir 输入描述和默认值
- 重构生成和部署流程,使用预生成的 markdown.html 文件
- 添加版本获取步骤
- 使用 release-downloader action 下载指定版本文件
PJ568 1 年之前
父节点
当前提交
9bf94e715c
共有 3 个文件被更改,包括 31 次插入 和 34 次删除
  1. 1 1
      Cargo.toml
  2. 29 32
      action.yml
  3. 1 1
      index.html

+ 1 - 1
Cargo.toml

@@ -1,5 +1,5 @@
 [package]
-name = "markdown-html"
+name = "markdown-html-generator"
 version = "1.8.0"
 edition = "2021"
 

+ 29 - 32
action.yml

@@ -4,8 +4,8 @@ author: 'PJ568'
 
 inputs:
   target-dir:
-    description: Directory to deploy the minimized HTML file
-    default: "."
+    description: Relative path under $GITHUB_WORKSPACE to deploy the minimized HTML file
+    default: ""
   file-name:
     description: Name of the minimized HTML file
     default: "index.html"
@@ -19,45 +19,42 @@ inputs:
 runs:
   using: "composite"
   steps:
-    - name: Setup Rust
-      uses: MatteoH2O1999/setup-rust@v1
-      if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
-      working-directory: ${{ github.action_path }}
 
-    - name: Cache Rust dependencies
-      if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
-      uses: Swatinem/rust-cache@v2
-      working-directory: 
-      with:
-        workspaces: "${{ github.action_path }} -> target"
-        cache-on-failure: "true"
-
-    - name: Build project
-      if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
-      run: cargo build --release
-      shell: bash
-      working-directory: ${{ github.action_path }}
-
-    - name: Generate minimized HTML
-      if: ${{ inputs.use-minified == 'true' || inputs.use-all-in-one == 'true' }}
-      run: cargo run --release -- index.html
+    - name: Get version
+      id: version-get
+      run: |
+        chmod +x ./scripts/get-version.bash
+        VERSION=$(./scripts/get-version.bash)
+        echo "version=${VERSION}" >> $GITHUB_OUTPUT
+        if [ "$VERSION" != "0" ]; then
+          echo "Version detected: $VERSION"
+        else
+          echo "No version detacted"
+        fi
       shell: bash
-      working-directory: ${{ github.action_path }}
 
-    - name: Deploy file
+    - name: Generate file name
       run: |
-        mkdir -p "${{ inputs.target-dir }}"
-        USE_MINIFIED=""
         USE_ALL_IN_ONE=""
-        if [ "${{ inputs.use-minified }}" = "true" ]; then
-          USE_MINIFIED=".min"
-        fi
+        USE_MINIFIED=""
         if [ "${{ inputs.use-all-in-one }}" = "true" ]; then
           USE_ALL_IN_ONE=".allinone"
         fi
-        cp -uv index${USE_ALL_IN_ONE}${USE_MINIFIED}.html "${{ inputs.target-dir }}/${{ inputs.file-name }}"
+        if [ "${{ inputs.use-minified }}" = "true" ]; then
+          USE_MINIFIED=".min"
+        fi
+        echo "file_name=index${USE_ALL_IN_ONE}${USE_MINIFIED}.html" >> $GITHUB_OUTPUT
       shell: bash
-      working-directory: ${{ github.action_path }}
+
+    - name: Deploy pre-generated markdown.html file
+      uses: robinraju/release-downloader@v1
+      with:
+        repository: 'PJ-568/MAKRDOWN.HTML'
+        tag: ${{ steps.version-get.outputs.version }}
+        fileName: ${{ steps.file-name.outputs.file_name }}
+        tarBall: false
+        zipBall: false
+        out-file-path: ${{ inputs.target-dir }}
 
 branding:
   icon: 'book-open'

+ 1 - 1
index.html

@@ -1,7 +1,7 @@
 <!doctype html>
 
 <html>
-<markdown-html version="1.17.3" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
+<markdown-html version="1.17.4" author="PJ568" repo="https://github.com/PJ-568/markdown.html"
   license="CC BY-SA 4.0 International"></markdown-html>
 
 <head>