Parcourir la source

【维护】重构 GitHub Actions 工作流

- 移除 check-version-and-push-tag.yml 文件
- 更新 release.yml 文件,增加版本检查和推送标签的步骤
- 添加构建项目和生成压缩 HTML 的步骤
- 修改发布 release 的步骤,使用检查到的版本号
PJ568 il y a 1 an
Parent
commit
6c3eb953bd
2 fichiers modifiés avec 50 ajouts et 42 suppressions
  1. 0 38
      .github/workflows/check-version-and-push-tag.yml
  2. 50 4
      .github/workflows/release.yml

+ 0 - 38
.github/workflows/check-version-and-push-tag.yml

@@ -1,38 +0,0 @@
-name: check version and push tag
-
-on:
-  workflow_dispatch:
-  push:
-    branches:
-      - main
-
-jobs:
-  check:
-    runs-on: ubuntu-latest
-    permissions: write-all
-    steps:
-
-    - name: Checkout
-      uses: actions/checkout@v4
-    
-    - name: Check version
-      id: version-check
-      run: |
-        chmod +x ./scripts/is-newer-version.bash
-        chmod +x ./scripts/get-version.bash
-        VERSION=$(./scripts/is-newer-version.bash)
-        echo "version=${VERSION}" >> $GITHUB_OUTPUT
-        if [ "$VERSION" != "0" ]; then
-          echo "New version detected: $VERSION"
-        else
-          echo "No new version to release"
-        fi
-
-    - name: Push tag
-      if: steps.version-check.outputs.version != '0'
-      run: |
-        tag="v${{ steps.version-check.outputs.version }}"
-        git config user.name "${GITHUB_ACTOR}"
-        git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
-        git tag -a "${tag}" -m "Release ${tag}"
-        git push origin "${tag}"

+ 50 - 4
.github/workflows/release.yml

@@ -1,9 +1,10 @@
 name: release
 
-on: 
+on:
+  workflow_dispatch:
   push:
-    tags:
-      - "v*"
+    branches:
+      - main
 
 jobs:
   release:
@@ -14,11 +15,56 @@ jobs:
 
     - name: Checkout
       uses: actions/checkout@v4
+      with:
+        fetch-depth: 0
+    
+    - name: Check version
+      id: version-check
+      run: |
+        chmod +x ./scripts/is-newer-version.bash
+        chmod +x ./scripts/get-version.bash
+        VERSION=$(./scripts/is-newer-version.bash)
+        echo "version=${VERSION}" >> $GITHUB_OUTPUT
+        if [ "$VERSION" != "0" ]; then
+          echo "New version detected: $VERSION"
+        else
+          echo "No new version to release"
+        fi
+
+    - name: Push tag
+      if: steps.version-check.outputs.version != '0'
+      run: |
+        tag="v${{ steps.version-check.outputs.version }}"
+        git config user.name "${GITHUB_ACTOR}"
+        git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
+        git tag -a "${tag}" -m "Release ${tag}"
+        git push origin "${tag}"
+
+    - name: Checkout
+      if: steps.version-check.outputs.version != '0'
+      uses: actions/checkout@v4
+
+    - name: Setup Rust
+      if: steps.version-check.outputs.version != '0'
+      uses: MatteoH2O1999/setup-rust@v1
+
+    - name: Build project
+      if: steps.version-check.outputs.version != '0'
+      run: cargo build --release
+      shell: bash
+      working-directory: ${{ github.action_path }}
+
+    - name: Generate minimized HTML
+      if: steps.version-check.outputs.version != '0'
+      run: cargo run --release -- ${{ github.action_path }}/index.html ${{ github.action_path }}/index.min.html
+      shell: bash
+      working-directory: ${{ github.action_path }}
 
     - name: Create release
+      if: steps.version-check.outputs.version != '0'
       uses: ncipollo/release-action@v1
       with:
         token: ${{ secrets.TOKEN }}
         generateReleaseNotes: true
-        tag: ${{ github.ref_name }}
+        tag: "v${{ steps.version-check.outputs.version }}"
         artifacts: "index.html,index.min.html"