From 080e038b9546a254ce7cba9746a946c014f82f33 Mon Sep 17 00:00:00 2001 From: terwer Date: Fri, 16 Jun 2023 22:18:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E7=BA=BF=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E7=AC=AC=E4=B8=80=E7=89=88-=E5=AE=8C=E5=96=84=E6=89=93?= =?UTF-8?q?=E5=8C=85=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 39 +++++ .github/workflows/ci.yml | 37 +++++ .github/workflows/release-please.yml | 103 ++++++++++++ .gitignore | 2 + layouts/default.vue | 12 +- locales/en_US.ts | 2 + locales/zh_CN.ts | 2 + nuxt.config.ts | 8 + package.json | 12 +- pages/index.vue | 6 +- scripts/README.md | 7 + scripts/build.sh | 27 +++ scripts/dev.sh | 31 ++++ scripts/docker.sh | 2 + scripts/package.py | 27 +++ scripts/parse_changelog.py | 109 +++++++++++++ scripts/scriptutils.py | 236 +++++++++++++++++++++++++++ scripts/version.py | 71 ++++++++ 18 files changed, 723 insertions(+), 10 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release-please.yml create mode 100644 scripts/README.md create mode 100644 scripts/build.sh create mode 100644 scripts/dev.sh create mode 100644 scripts/docker.sh create mode 100644 scripts/package.py create mode 100644 scripts/parse_changelog.py create mode 100644 scripts/scriptutils.py create mode 100644 scripts/version.py diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..96b767de --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,39 @@ +version: 2 +updates: + # Fetch and update latest `npm` packages + - package-ecosystem: npm + directory: "/" + schedule: + interval: daily + time: "00:00" + open-pull-requests-limit: 10 + reviewers: + - terwer + assignees: + - terwer + commit-message: + prefix: fix + prefix-development: chore + include: scope + labels: + - "npm dependencies" + - "npm" + + # Fetch and update latest `github-actions` pkgs + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + time: "00:00" + open-pull-requests-limit: 10 + reviewers: + - terwer + assignees: + - terwer + commit-message: + prefix: fix + prefix-development: chore + include: scope + labels: + - "github actions" + - "ci" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..0ae09e3c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + push: + branches: + - dev + +jobs: + build: + name: Build + timeout-minutes: 15 + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - uses: pnpm/action-setup@v2.2.4 + with: + version: 8 + + - name: Setup Node.js environment + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Package + run: pnpm package diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 00000000..d2353c45 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,103 @@ +on: + push: + branches: + - main + +name: release-please +jobs: + release-please: + runs-on: ubuntu-latest + steps: + # Create release + - name: Create release + uses: google-github-actions/release-please-action@v3 + id: release + with: + release-type: node + package-name: release-please-action + ## branch to open pull release PR against (detected by default) + default-branch: main + ## Should breaking changes before 1.0.0 produce minor bumps? Default false + bump-minor-pre-major: false + ## Should feat changes before 1.0.0 produce patch bumps instead of minor bumps? Default false + bump-patch-for-minor-pre-major: false + ## If set, create releases that are pre-major or pre-release version marked as pre-release on GitHub. Defaults false + prerelease: false + ## 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}]' + + # 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: Archive package + 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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index d7897009..d661390b 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ .cache dist .env.docker +build +__pycache__ # Node dependencies node_modules diff --git a/layouts/default.vue b/layouts/default.vue index 9a0d758f..e5829bd0 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -4,9 +4,13 @@ import Footer from "~/components/default/Footer.vue" diff --git a/locales/en_US.ts b/locales/en_US.ts index 404716d2..459eb126 100644 --- a/locales/en_US.ts +++ b/locales/en_US.ts @@ -44,4 +44,6 @@ export default { "main.opt.warning.tip": "This operation cannot be undone, continue?", "switch.active.text": "Debug", "switch.unactive.text": "Normal", + "blog.index.no.home": "Oh, you haven't set up your homepage yet!", + "blog.index.goto.set.home": "Go to set up my homepage now", } diff --git a/locales/zh_CN.ts b/locales/zh_CN.ts index 58a46b66..6fe1fcca 100644 --- a/locales/zh_CN.ts +++ b/locales/zh_CN.ts @@ -44,4 +44,6 @@ export default { "main.opt.warning.tip": "此操作不可恢复,是否继续?", "switch.active.text": "调试模式", "switch.unactive.text": "正常模式", + "blog.index.no.home": "啊哦,您还没设置自己的主页哟!", + "blog.index.goto.set.home": "马上去设置我的主页", } diff --git a/nuxt.config.ts b/nuxt.config.ts index 393382c3..b22acaa3 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -1,3 +1,5 @@ +import path from "path" + const getAppBase = (isSiyuanBuild: boolean, isNodeBuild: boolean, isVercelBuild: boolean, isDev: boolean): string => { if (isSiyuanBuild) { return "/plugins/siyuan-blog/" @@ -111,6 +113,8 @@ export default defineNuxtConfig({ classSuffix: "", }, + builder: "vite", + vite: { define: { "process.env.DEV_MODE": `"${isDev || debugMode}"` }, plugins: [], @@ -142,5 +146,9 @@ export default defineNuxtConfig({ preset: ssrPreset, // 开启之后将进行静态伺服 serveStatic: ssrServeStatic, + output: { + // 静态构建放到 dist ,否则放到默认目录 .output/public + publicDir: ssrServeStatic ? path.join(__dirname, "dist") : path.join(__dirname, ".output", "public"), + }, }, }) diff --git a/package.json b/package.json index bc1f0292..a8fd9a09 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,17 @@ "type": "module", "scripts": { "serve": "nuxt dev", - "build": "pnpm pluginBuild && pnpm siyuanBuild", - "dev": "rm -rf ./dist && pnpm pluginBuild && DEBUG_MODE=true pnpm siyuanBuild && pnpm siyuanSync", + "dev": "bash scripts/dev.sh", + "build": "bash scripts/build.sh", "pluginBuild": "zhi-build --production", + "siyuanBuild": "BUILD_TYPE=siyuan nuxt generate", "vercelBuild": "BUILD_TYPE=vercel nuxt build", "nodeBuild": "BUILD_TYPE=node nuxt build", - "siyuanBuild": "BUILD_TYPE=siyuan nuxt generate && cp -r .output/public/* ./dist", - "siyuanSync": "cp -r ./dist/* /Users/terwer/Documents/mydocs/SiYuanWorkspace/public/data/plugins/siyuan-blog", + "dockerPackage": "bash scripts/docker.sh", + "syncVersion": "python scripts/version.py", + "parseChangelog": "python scripts/parse_changelog.py", + "prepareRelease": "pnpm syncVersion && pnpm parseChangelog", + "package": "python scripts/package.py", "postinstall": "nuxt prepare" }, "devDependencies": { diff --git a/pages/index.vue b/pages/index.vue index 6733e5ca..b010248e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,4 +1,6 @@