Skip to content

Commit

Permalink
refactor: 调整打包结构,适应集市规则
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed May 17, 2023
1 parent a6eeafd commit a70a921
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 255 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI
on:
push:
branches:
- main
- dev

jobs:
Expand Down Expand Up @@ -35,5 +34,4 @@ jobs:
run: pnpm build

- name: Package
# 上面的 Build 已经构建过了,这里可以忽略 Build ,避免重复运行
run: pnpm package
76 changes: 75 additions & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,78 @@ jobs:
## header used within the release PR body, defaults to using :robot: I have created a release *beep* *boop*
pull-request-header: ':robot: A new release will be created'
## A JSON formatted String containing to override the outputted changelog sections
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"refactor","section":"Code Refactoring","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false},{"type":"perf","section":"Performance Improvements","hidden":false}]'
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"refactor","section":"Code Refactoring","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":false},{"type":"perf","section":"Performance Improvements","hidden":false}]'

# Checkout
- name: Checkout
if: ${{ steps.release.outputs.release_created }}
uses: actions/checkout@v3

# Install Node.js
- name: Install Node.js
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'

# Install pnpm
- name: Install pnpm
if: ${{ steps.release.outputs.release_created }}
uses: pnpm/action-setup@v2
id: pnpm-install
with:
version: 8
run_install: false

# Get pnpm store directory
- name: Get pnpm store directory
if: ${{ steps.release.outputs.release_created }}
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
# Setup pnpm cache
- name: Setup pnpm cache
if: ${{ steps.release.outputs.release_created }}
uses: actions/cache@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
# Install dependencies
- name: Install dependencies
if: ${{ steps.release.outputs.release_created }}
run: pnpm install

# Prepare new version
# https://github.com/google-github-actions/release-please-action#outputs
- name: Prepare new version
if: ${{ steps.release.outputs.release_created }}
run: |
pnpm prepareRelease
# Build for production
- name: Build for production
if: ${{ steps.release.outputs.release_created }}
run: pnpm build

# Archive package
- name: Build for production
if: ${{ steps.release.outputs.release_created }}
run: pnpm package

# Upload package to release
# https://github.com/philips-labs/terraform-aws-github-runner/blob/main/.github/workflows/release.yml#L46
- name: Upload package.zip to the release
if: ${{ steps.release.outputs.releases_created }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
ls -l ./build
for f in $(find ./build -name '*.zip'); do
gh release upload ${{ steps.release.outputs.tag_name }} $f
done
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
## [1.1.0](https://github.com/terwer/siyuan-plugin-importer/compare/v1.0.0...v1.1.0) (2023-05-17)
### Features
* 初始化插件项目 ([e41c745](https://github.com/terwer/siyuan-plugin-importer/commit/e41c7458cf8f3882b072e214a78fb858d33a29f6))
* 完善国际化以及项目说明 ([4ad0fef](https://github.com/terwer/siyuan-plugin-importer/commit/4ad0fefeef1b04257515cc7afc41fc03685bd3a0))
* 完善国际化以及项目说明 ([07a2099](https://github.com/terwer/siyuan-plugin-importer/commit/07a2099912318ea8f73e666b70f1d0d438f78ee7))
* 完成导入epub基础功能 ([a0580fa](https://github.com/terwer/siyuan-plugin-importer/commit/a0580fabfba2834cdd73bfa5d4ce2da79ba52a5a))
* 完成导出epub、docx、opml、html测试 ([1d671b6](https://github.com/terwer/siyuan-plugin-importer/commit/1d671b697b006d881315a90dfd45310d415272a1))
* 导入工具第一个版本 ([1fc739b](https://github.com/terwer/siyuan-plugin-importer/commit/1fc739b676ba51460c7f57e4e22c00869517b74f))
* 导入工具第一个版本 ([1fc739b2](https://github.com/terwer/siyuan-plugin-importer/commit/1fc739b676ba51460c7f57e4e22c00869517b74f))
* 插件最小化运行单位 ([155a825](https://github.com/terwer/siyuan-plugin-importer/commit/155a825461bf447d45083329ccce9eb93b3857d6))
* 新增kernelApi ([80ca482](https://github.com/terwer/siyuan-plugin-importer/commit/80ca4829e5949c871ddaacad2e6fced1771bd336))
* 完善国际化以及项目说明 ([07a2099](https://github.com/terwer/siyuan-plugin-importer/commit/07a2099912318ea8f73e666b70f1d0d438f78ee7))
* 新增kernelapi ([80ca482](https://github.com/terwer/siyuan-plugin-importer/commit/80ca4829e5949c871ddaacad2e6fced1771bd336))
### Miscellaneous
* **main:** release 1.0.0 ([74258ce](https://github.com/terwer/siyuan-plugin-importer/commit/74258ce418a45bd64c7a4c2b947508a842691605))
File renamed without changes
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
"build": "vite build",
"start": "vite preview",
"test": "vitest --watch",
"syncVersion": "ts-node-esm --experimental-specifier-resolution=node tools/syncVersion.ts",
"parseChangelog": "ts-node-esm --experimental-specifier-resolution=node tools/changelogParser.ts",
"syncVersion": "python scripts/version.py",
"parseChangelog": "python scripts/parse_changelog.py",
"prepareRelease": "pnpm syncVersion && pnpm parseChangelog",
"package": "ts-node-esm --experimental-specifier-resolution=node tools/packageApp.ts"
"package": "python scripts/package.py"
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^2.0.3",
"@terwer/changelog-parser": "^1.1.0",
"@terwer/eslint-config-custom": "^1.2.0",
"@terwer/vite-config-custom": "^0.6.0",
"@tsconfig/svelte": "^4.0.1",
"archiver": "^5.3.1",
"glob": "^7.2.3",
"minimist": "^1.2.8",
"rollup-plugin-livereload": "^2.0.5",
Expand Down
File renamed without changes.
File renamed without changes
27 changes: 27 additions & 0 deletions scripts/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

import scriptutils

if __name__ == "__main__":
# 切换工作空间
scriptutils.switch_workdir()

# 获取当前工作空间
cwd = scriptutils.get_workdir()

dist_folder = "./dist"
data = scriptutils.read_json_file(cwd + "package.json")
v = data["version"]

src_folder = dist_folder
tmp_folder_name = "./siyuan-importer"
build_zip_path = "./build"
build_zip_name = "siyuan-plugin-importer-" + v + ".zip"

try:
# 压缩dist为zip
scriptutils.zip_folder(src_folder, tmp_folder_name, build_zip_path, build_zip_name)
scriptutils.cp_file(os.path.join(build_zip_path, build_zip_name), os.path.join(build_zip_path, "package.zip"))
except Exception as e:
print(f"打包错误,{str(e)}")
print("插件打包完毕.")
87 changes: 87 additions & 0 deletions scripts/parse_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import re
import shutil
from collections import defaultdict


def parse_changelog():
"""
:robot: A new release will be created
---
## 1.0.0 (2023-04-24)
### ⚠ BREAKING CHANGES
* **esbuild-config-custom:** previews esbuild config need to be a attr value for esbuild property, add a new customConfig property
### Features
* [#163](https://github.com/terwer/zhi/issues/163) ([d9fae8a](https://github.com/terwer/zhi/commit/d9fae8af6f96052a82e62f9aea79505a52fdbb23))
* Add a vuepress 2 blog ([9862b18](https://github.com/terwer/zhi/commit/9862b1811663a2b34b05d140d3197075d943696b))
* add api docs ([97751dc](https://github.com/terwer/zhi/commit/97751dc63b6ed9143a9d6eb0d673a22d4f9c9f6a))
* add api docs ([3b5ff6f](https://github.com/terwer/zhi/commit/3b5ff6fbb1ab3ea161e41d0436037e85e4a6cee3))
* add api docs ([b338a67](https://github.com/terwer/zhi/commit/b338a67268e767b9289a8d768377c5cd8ce29fbe))
* add api docs ([6f9ebd9](https://github.com/terwer/zhi/commit/6f9ebd939c8bdabc5e2e377feb13363dc0dbe769))
* Add api docs ([9c1a5e5](https://github.com/terwer/zhi/commit/9c1a5e5036c3d95d050e4672df5f505386d29962))
"""

# will print

"""
:robot: a new release will be created
---
## 1.0.0 (2023-04-24)
### ⚠ BREAKING CHANGES
* **esbuild-config-custom:** previews esbuild config need to be a attr value for esbuild property, add a new customconfig property
### Features
* [#163](https://github.com/terwer/zhi/issues/163) ([d9fae8a](https://github.com/terwer/zhi/commit/d9fae8af6f96052a82e62f9aea79505a52fdbb23))
* add a vuepress 2 blog ([9862b18](https://github.com/terwer/zhi/commit/9862b1811663a2b34b05d140d3197075d943696b))
* add api docs ([9c1a5e5](https://github.com/terwer/zhi/commit/9c1a5e5036c3d95d050e4672df5f505386d29962))
"""

# make a backup copy of the original file
original_file = 'CHANGELOG.md'
# backup_file = original_file.replace(".md", "_backup.md")
# shutil.copyfile(original_file, backup_file)

# handle repeat lines
with open(original_file, 'r', encoding='utf-8') as f:
lines = [line.strip() for line in f.readlines()]
unique_commits = remove_same_commit(lines)

# save new file
save_file = original_file
with open(save_file, 'w', encoding='utf-8') as f:
f.write('\n'.join(unique_commits))
print(f"comment parsed.saved to => {save_file}")


def remove_same_commit(commit_list):
commit_map = defaultdict()
for line in commit_list:
if '#' not in line:
line = line.lower()
# 先匹配常规的
match = re.search(r'(?<=\*\s).*?(?=\()', line)
if match:
title = match.group(0).strip()
commit_map[title] = line
else:
# 接下来匹配有模块的
match2 = re.search(r'[*] [**](.*)[**] ([^:]+): (.*) \((.*)\)', line)
if match2:
message_title = match.group(3).strip()
commit_map[message_title] = line
else:
# 最后处理剩下的
commit_map[line] = line

return commit_map.values()


if __name__ == "__main__":
parse_changelog()
Loading

0 comments on commit a70a921

Please sign in to comment.