Procházet zdrojové kódy

Add create releases node file

杜府 před 3 roky
rodič
revize
a994b18963

+ 15 - 0
.github/package.json

@@ -0,0 +1,15 @@
+{
+  "name": "releases",
+  "version": "1.0.0",
+  "description": "",
+  "main": "releases.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC",
+  "devDependencies": {
+    "fs": "0.0.1-security",
+    "path": "^0.12.7"
+  }
+}

+ 37 - 0
.github/pnpm-lock.yaml

@@ -0,0 +1,37 @@
+lockfileVersion: '6.0'
+
+devDependencies:
+  fs:
+    specifier: 0.0.1-security
+    version: 0.0.1-security
+  path:
+    specifier: ^0.12.7
+    version: 0.12.7
+
+packages:
+
+  /fs@0.0.1-security:
+    resolution: {integrity: sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==}
+    dev: true
+
+  /inherits@2.0.3:
+    resolution: {integrity: sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==}
+    dev: true
+
+  /path@0.12.7:
+    resolution: {integrity: sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==}
+    dependencies:
+      process: 0.11.10
+      util: 0.10.4
+    dev: true
+
+  /process@0.11.10:
+    resolution: {integrity: sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==}
+    engines: {node: '>= 0.6.0'}
+    dev: true
+
+  /util@0.10.4:
+    resolution: {integrity: sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==}
+    dependencies:
+      inherits: 2.0.3
+    dev: true

+ 35 - 0
.github/releases.js

@@ -0,0 +1,35 @@
+// 读取项目 /doc/guide/changelog.md 文件,生成 releases 文本
+
+// 读取 ../doc/guide/changelog.md 和 ../doc/guide/changelog_en.md 文件,分别获取文件前两个二级标题之间的内容,包括空格和换行符
+// 例如:
+// ## 0.0.11
+//
+// - 优化 Input,详见 [Input](https://stdf.design/#/components?nav=input&tab=4)。
+//
+// ## 0.0.10
+// 只取 ## 0.0.11 和 ## 0.0.10 之间的内容
+// 结果为:
+// - 优化 Input,详见 [Input](https://stdf.design/#/components?nav=input&tab=4)。
+
+// 获取内容暂存为变量 changelogContent
+// 英文版的 changelog_en.md 文件同理,获取内容暂存为变量 changelogEnContent
+// 然后将获取的两个内容按照 Markdown 格式用单独一行 --- 分开,保存到 ./releases.md 文件中
+
+const fs = require('fs');
+const path = require('path');
+// const { version } = require('../../package.json');
+
+const changelogPath = path.resolve(__dirname, '../doc/guide/changelog.md');
+const changelogEnPath = path.resolve(__dirname, '../doc/guide/changelog_en.md');
+const releasesPath = path.resolve(__dirname, './releases.md');
+
+const changelog = fs.readFileSync(changelogPath, 'utf-8');
+const changelogEn = fs.readFileSync(changelogEnPath, 'utf-8');
+
+// 注意只取前两个二级标题之间的内容,二级标题不要
+const changelogContent = changelog.match(/##\s[\d\.]+\n\n([\s\S]*?)\n\n##\s[\d\.]+/)[1];
+const changelogEnContent = changelogEn.match(/##\s[\d\.]+\n\n([\s\S]*?)\n\n##\s[\d\.]+/)[1];
+
+const releasesContent = `${changelogContent}\n\n---\n\n${changelogEnContent}`;
+
+fs.writeFileSync(releasesPath, releasesContent);

+ 8 - 2
.github/workflows/auto-public-npm.yml

@@ -7,8 +7,6 @@ on:
     push:
         branches:
             - main
-        tags:
-            - 'v*'
 
 jobs:
     publish:
@@ -18,6 +16,14 @@ jobs:
             - name: Checkout
               uses: actions/checkout@v2
 
+              # 读取最新push的 tag 内容,如果是 v 开头,则往下执行,否则退出
+            - name: Check tag
+                run: |
+                    if [[ $GITHUB_REF != 'refs/tags/v'* ]]; then
+                        echo "This is not a tag push. Skipping."
+                        exit 78
+                    fi
+
             - name: Setup Node.js environment
               uses: actions/setup-node@v1
               with:

+ 29 - 38
.github/workflows/auto-releases.yml

@@ -15,8 +15,6 @@ on:
     push:
         branches:
             - main
-        tags:
-            - 'v*'
 
 jobs:
     release-please:
@@ -24,55 +22,43 @@ jobs:
 
         steps:
             - uses: actions/checkout@v2
+            # 读取最新push的 tag 内容,如果是 v 开头,则往下执行,否则退出
+            - name: Check tag
+              run: |
+                  if [[ $GITHUB_REF != 'refs/tags/v'* ]]; then
+                      echo "This is not a tag push. Skipping."
+                      exit 78
+                  fi
+
             # 读取 tag 内容,例如 v0.0.12,作为 Releases title
             - name: Get tag
               id: tag
               run: |
                   echo tag=${GITHUB_REF#refs/*/} >> $GITHUB_OUTPUT
-              #   echo ::set-output name=tag::${GITHUB_REF#refs/*/}
-            # 读取仓库内的 /doc/guide/changelog.md 中第一个二级标题与第二个二级标题之间的内容,包括换行,如
-            #  ## 0.0.12
-            #  -  新增了一个功能。
-            #  ## 0.0.11
-            # 只取第一个二级标题与第二个二级标题之间的内容,结果为:
-            #  -  新增了一个功能。
-            - name: Get changelog
-              id: changelog
+
+            - name: Setup Node.js environment
+              uses: actions/setup-node@v1
+              with:
+                  node-version: 18.x
+            # 安装 pnpm
+            - name: Install pnpm
               run: |
-                  echo changelog=$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog.md | sed -n '/^## /{n;p;}') >> $GITHUB_OUTPUT
-              #   echo ::set-output name=changelog::$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog.md | sed -n '/^## /{n;p;}')
+                  npm install -g pnpm
 
-            # 读取仓库内的 /doc/guide/changelog_en.md 中第一个二级标题与第二个二级标题之间的内容,包括换行,如
-            #  ## 0.0.12
-            #  -  Add a new feature.
-            #  ## 0.0.11
-            # 只取第一个二级标题与第二个二级标题之间的内容,结果为:
-            #  -  Add a new feature.
-            - name: Get changelog_en
-              id: changelog_en
+            # cd 到 .github/workflows 目录下,执行 pnpm install,再执行 node releases.js,生成 releases.md 文件
+            - name: Install dependencies
               run: |
-                  echo changelog_en=$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog_en.md | sed -n '/^## /{n;p;}') >> $GITHUB_OUTPUT
-              #   echo ::set-output name=changelog_en::$(awk '/^## /{n++}{if(n==2){exit}}1' doc/guide/changelog_en.md | sed -n '/^## /{n;p;}')
+                  cd .github/workflows
+                  pnpm install
 
-            # 将两个内容合并为一个字符串,中间使用 --- 分隔
+            # 读取 releases.md 文件内容,作为 Releases describe
             - name: Get body
               id: body
               run: |
-                  echo body=${{ steps.changelog.outputs.changelog }}\\n---\\n${{ steps.changelog_en.outputs.changelog_en }} >> $GITHUB_OUTPUT
-              #   echo ::set-output name=body::"${{ steps.changelog.outputs.changelog }}\n---\n${{ steps.changelog_en.outputs.changelog_en }}"
-
-            # 组成内容示例为:
-            # -  新增了一个功能。
-            # ---
-            # -  Add a new feature.
+                  echo body=$(cat releases.md) >> $GITHUB_OUTPUT
+              #   echo ::set-output name=body::$(cat releases.md)
 
-            # 此处打印一下上述步骤中的输出内容 body,用来检查输出内容是否正确
-            - name: Log outputs
-              run: |
-                  cat $GITHUB_OUTPUT
-                  echo $GITHUB_OUTPUT
-
-            # 将合并的内容作为 Releases describe,并作为 latest release 发布本次 Release
+            # 作为 latest release 发布本次 Release
             - name: Release
               uses: actions/create-release@v1
               env:
@@ -83,3 +69,8 @@ jobs:
                   body: ${{ steps.body.outputs.body }}
                   draft: false
                   prerelease: false
+
+            # 删除 releases.md 文件
+            - name: Remove releases.md
+              run: |
+                  rm releases.md

+ 2 - 2
doc/guide/changelog.md

@@ -1,10 +1,10 @@
 ## 0.0.11
 
-- 优化 Input,详见 [Input](https://stdf.design/#/components?nav=input&tab=4)。
+-   优化 Input,详见 [Input](https://stdf.design/#/components?nav=input&tab=4)。
 
 ## 0.0.10
 
-- 优化 Cell,详见 [Cell](https://stdf.design/#/components?nav=cell&tab=4)。
+-   优化 Cell,详见 [Cell](https://stdf.design/#/components?nav=cell&tab=4)。
 
 ## 0.0.9