From f3429859a940c5bb8d857cac6b5f729cbc4b1fe0 Mon Sep 17 00:00:00 2001 From: Harttle Date: Mon, 5 Jun 2023 06:18:40 +0800 Subject: [PATCH] chore: split Github Actions workflows --- .github/workflows/build.yml | 40 ++++++++++++++++++ .github/workflows/ci-build.yml | 28 +++++++++++++ .github/workflows/{check.yml => coverage.yml} | 28 ++++--------- .github/workflows/docs.yml | 8 ++-- .github/workflows/lint.yml | 25 +++++++++++ .github/workflows/performance.yml | 33 +++++++++++++++ .github/workflows/pr-build.yml | 22 ++++++++++ .github/workflows/{pr.yml => pr-check.yml} | 9 ++-- .github/workflows/release.yml | 28 ++++++++----- .github/workflows/test.yml | 34 +++++++++++++++ .gitignore | 3 ++ CONTRIBUTING.md | 42 ++++++++----------- bin/build-docs-liquid.sh | 5 +++ bin/build-docs.sh | 1 + bin/perf-diff.sh | 4 -- .../navy/layout/partial/after_footer.swig | 2 +- package.json | 12 +++--- test/.eslintrc.json | 5 +++ test/tsconfig.json | 17 ++++++++ tsconfig.json | 2 +- 20 files changed, 269 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci-build.yml rename .github/workflows/{check.yml => coverage.yml} (54%) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/performance.yml create mode 100644 .github/workflows/pr-build.yml rename .github/workflows/{pr.yml => pr-check.yml} (57%) create mode 100644 .github/workflows/test.yml create mode 100755 bin/build-docs-liquid.sh create mode 100644 test/tsconfig.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..a976e0d2b2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build +on: + workflow_call: + inputs: + os: + required: true + type: string + bundles: + required: false + type: string +env: + BUNDLES: ${{ inputs.bundles }} +jobs: + build: + name: Build + runs-on: ${{ inputs.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Install dependencies + run: npm ci + - name: Build + run: npm run build + - name: Archive artifacts + uses: actions/upload-artifact@v3 + with: + name: dist-${{ inputs.os }} + path: dist + - name: Archive npm failure logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml new file mode 100644 index 0000000000..3f41a8bc42 --- /dev/null +++ b/.github/workflows/ci-build.yml @@ -0,0 +1,28 @@ +name: CI Build +on: + push: + branches: + - 'master' + - 'test' +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + uses: ./.github/workflows/build.yml + with: + os: ${{ matrix.os }} + lint: + uses: ./.github/workflows/lint.yml + test: + needs: build + uses: ./.github/workflows/test.yml + coverage: + uses: ./.github/workflows/coverage.yml + performance: + needs: build + uses: ./.github/workflows/performance.yml + with: + os: ubuntu-latest + docs: + uses: ./.github/workflows/docs.yml diff --git a/.github/workflows/check.yml b/.github/workflows/coverage.yml similarity index 54% rename from .github/workflows/check.yml rename to .github/workflows/coverage.yml index f785b2d991..d940072aa5 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/coverage.yml @@ -1,12 +1,9 @@ -name: Check -on: [push, pull_request] +name: Test Coverage +on: workflow_call jobs: - check: - name: Check - strategy: - matrix: - os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} + coverage: + name: Test Coverage + runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 @@ -16,23 +13,14 @@ jobs: uses: actions/setup-node@v2 with: node-version: '14' - - name: Build - run: | - npm ci - npm run build + - name: Install dependencies + run: npm ci - name: Test - run: | - npm run lint - TZ=Etc/GMT npm run test - TZ=Asia/Shanghai npm run test - TZ=America/New_York npm run test + run: npm run test:coverage - name: Coverage uses: coverallsapp/github-action@v1.1.2 with: github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Performance - run: | - npm run perf:diff - name: Archive npm failure logs uses: actions/upload-artifact@v2 if: failure() diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 511b815693..6a4bc2ab97 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,8 +1,5 @@ name: Docs -on: - push: - branches: - - master +on: [workflow_dispatch, workflow_call] jobs: docs: name: Docs @@ -19,8 +16,9 @@ jobs: - name: Build run: | npm ci - npm run build + npm run build:docs - name: Publish + if: github.ref == 'refs/heads/master' uses: JamesIves/github-pages-deploy-action@4.1.4 with: branch: gh-pages diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..3252bc4f28 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,25 @@ +name: Lint +on: [workflow_dispatch, workflow_call] +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Install dependencies + run: npm ci + - name: Lint + run: npm run lint + - name: Archive npm failure logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml new file mode 100644 index 0000000000..f239f62ad2 --- /dev/null +++ b/.github/workflows/performance.yml @@ -0,0 +1,33 @@ +name: Performance Check +on: + workflow_call: + inputs: + os: + required: true + type: string +jobs: + performance: + name: Performance + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: dist-${{ inputs.os }} + path: dist + - name: Check Performance + run: npm run perf:diff + - name: Archive npm failure logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml new file mode 100644 index 0000000000..5db01eb0b1 --- /dev/null +++ b/.github/workflows/pr-build.yml @@ -0,0 +1,22 @@ +name: PR Build +on: pull_request +jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + uses: ./.github/workflows/build.yml + with: + os: ${{ matrix.os }} + lint: + uses: ./.github/workflows/lint.yml + test: + needs: build + uses: ./.github/workflows/test.yml + coverage: + uses: ./.github/workflows/coverage.yml + performance: + needs: build + uses: ./.github/workflows/performance.yml + with: + os: ubuntu-latest \ No newline at end of file diff --git a/.github/workflows/pr.yml b/.github/workflows/pr-check.yml similarity index 57% rename from .github/workflows/pr.yml rename to .github/workflows/pr-check.yml index 2a17906ac2..165949dc03 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr-check.yml @@ -1,15 +1,12 @@ -name: "PR Title Checker" - +name: PR Check on: pull_request_target: types: - opened - edited - - synchronize - jobs: - main: - name: Validate PR title + title: + name: Check PR title runs-on: ubuntu-latest steps: - uses: amannn/action-semantic-pull-request@v5 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 67d4211ded..97ea3c6940 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,19 @@ name: Release on: workflow_dispatch jobs: + build: + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + uses: ./.github/workflows/build.yml + with: + os: ${{ matrix.os }} + test: + needs: build + uses: ./.github/workflows/test.yml release: name: Release + needs: [build, test] runs-on: ubuntu-latest steps: - name: Checkout @@ -13,18 +24,13 @@ jobs: uses: actions/setup-node@v2 with: node-version: '14' - - name: Build - run: | - npm ci - npm run build:dist - - name: Test - run: | - npm run lint - npm run test - - name: Coverage - uses: coverallsapp/github-action@v1.1.2 + - name: Install dependencies + run: npm ci + - name: Download artifacts + uses: actions/download-artifact@v3 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + name: dist-ubuntu-latest + path: dist - name: Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..8c8bd807f7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Test +on: workflow_call +jobs: + test: + name: Test + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + timezone: [Etc/GMT, Asia/Shanghai, America/New_York] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + - name: Install dependencies + run: npm ci + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: dist-${{ matrix.os }} + path: dist + - name: Run Test + run: TZ=${{ matrix.timezone }} npm test + - name: Archive npm failure logs + uses: actions/upload-artifact@v2 + if: failure() + with: + name: npm-logs + path: ~/.npm/_logs diff --git a/.gitignore b/.gitignore index ee606141eb..36dd6c582a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,9 @@ coverage/ # modules node_modules/ + +# tmp +docs/public/js/liquid.browser.min.js dist/ demo/*/package-lock.json demo/*/yarn.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 674c2647cd..d6dee5f828 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,14 +16,14 @@ - Ensure the build runs because the Husky pre-commit hook checks it - `npm run check` checks runs the build, tests, lint and perf tests - `commitlint` checks the commit message format - + If there is a problem you will see it in the pre-commit hook output. In VS Code, this output will be shown in a new file in a new tab if the pre-commit hook fails. If you want to check the commit message without using the VS Code Source Control UI, you can run `echo "feat: my commit message" > npx commitlint` directly. - + - `git switch -c your_branch_name` (do this in your fork not the main repo) - `git add .` - `git commit -m "feat: Adding my change"` @@ -33,32 +33,24 @@ ## Playground The Playground runs off the `docs` directory. -`npm run:docs` is used to build it and that's included in `npm run build`. +`npm run build:docs` is used to build it. -To start the site locally, go to `docs` and run `npm start`, then visit +Then, to start the site locally, go to `docs` and run `npm start`, then visit http://localhost:4000/playground.html. -At the moment, the Playground uses the latest NPM version of the LiquidJS -library instead of using the built artifact produced by `npm run build:dist` -(also included in `npm run build`). +The Playground uses a local built LiquidJS, which is created during `npm run build:docs`. +To update that, you'll need to run `./bin/build-docs-liquid.sh` each time after making changes. +Then refresh the Playground site for the changes to take effect. + +## Performance + +If your change can have a performance impact, you can update and run performance cases under `benchmark/`. -To use the Playground with the local build of the library, make these changes: +1. `npm run build:cjs` to build a CommonJS bundle for the perf test. +2. `npm run perf:diff` to check whether there's a regression compared against `liquidjs@latest` -- Copy `dist/liquid.browser.min.js` to `docs/public/js/liquid.browser.min.js` -- Open `docs/themes/navy/layout/partial/after_footer.swig` -- Remove `https://cdn.jsdelivr.net/npm/liquidjs/dist/liquid.browser.min.js` line -- Add `{{ js('liquid.browser.min.js') }}` line before `{{ js('js/main') }}` line -- Refresh the Playground site for the changes to take effect -- Replace `liquid.browser.min.js` each time after making changes and building +Further more, `benchmark/` contains different cases to check its ops/sec. Useful when debugging perf regressions, to use it: -```diff - {% if page.layout === 'playground' %} -- - - {% endif %} - -+{{ js('js/liquid.browser.min.js') }} - {{ js('js/main') }} - - -``` +- `cd benchmark` go into benchmark project +- `npm ci` install dependencies +- `npm start` run the cases diff --git a/bin/build-docs-liquid.sh b/bin/build-docs-liquid.sh new file mode 100755 index 0000000000..104a670c7e --- /dev/null +++ b/bin/build-docs-liquid.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +BUNDLES=min npm run build +cp dist/liquid.browser.min.js docs/public/js/ + diff --git a/bin/build-docs.sh b/bin/build-docs.sh index 96538ec5b8..3d9fb1ddad 100755 --- a/bin/build-docs.sh +++ b/bin/build-docs.sh @@ -2,6 +2,7 @@ set -ex +./bin/build-docs-liquid.sh ./bin/build-contributors.sh ./bin/build-apidoc.sh ./bin/build-changelog.sh diff --git a/bin/perf-diff.sh b/bin/perf-diff.sh index cdd2d78604..f2ce1aaf7d 100755 --- a/bin/perf-diff.sh +++ b/bin/perf-diff.sh @@ -9,8 +9,4 @@ if [ ! -f $FILE_LATEST ]; then curl $URL_LATEST > $FILE_LATEST fi -# if [ ! -f $FILE_LOCAL ]; then -BUNDLES=cjs npm run build:dist -# fi - exec node benchmark/diff.js $FILE_LOCAL $FILE_LATEST diff --git a/docs/themes/navy/layout/partial/after_footer.swig b/docs/themes/navy/layout/partial/after_footer.swig index f0db1e31ae..95d864a3fb 100644 --- a/docs/themes/navy/layout/partial/after_footer.swig +++ b/docs/themes/navy/layout/partial/after_footer.swig @@ -1,5 +1,5 @@ {% if page.layout === 'playground' %} - +{{ js('js/liquid.browser.min.js') }} {% endif %} diff --git a/package.json b/package.json index 2afca7c8f6..785237344e 100644 --- a/package.json +++ b/package.json @@ -15,16 +15,16 @@ }, "scripts": { "lint": "eslint \"**/*.mjs\" \"**/*.ts\" .", - "check": "npm run build && npm test && npm run lint && npm run perf:diff", - "test": "jest --coverage", + "check": "npm run build && npm run build:docs && npm test && npm run lint && npm run perf:diff", + "test": "jest", + "test:coverage": "jest --coverage src test/integration", "test:e2e": "jest test/e2e", - "perf": "cd benchmark && npm ci && npm start", "perf:diff": "bin/perf-diff.sh", "perf:engines": "cd benchmark && npm run engines", - "postversion": "npm run build:dist", - "build": "npm run build:dist && npm run build:docs", - "build:dist": "rollup -c rollup.config.mjs", + "build": "rollup -c rollup.config.mjs", "build:cjs": "BUNDLES=cjs rollup -c rollup.config.mjs", + "build:min": "BUNDLES=min rollup -c rollup.config.mjs", + "build:umd": "BUNDLES=umd rollup -c rollup.config.mjs", "build:docs": "bin/build-docs.sh" }, "bin": { diff --git a/test/.eslintrc.json b/test/.eslintrc.json index 870214ca17..bb05da7db2 100644 --- a/test/.eslintrc.json +++ b/test/.eslintrc.json @@ -1,11 +1,16 @@ { + "extends": ["../.eslintrc.json"], "env": { "mocha": true }, "plugins": [ "mocha" ], + "parserOptions": { + "project": "test/tsconfig.json" + }, "rules": { + "deprecation/deprecation": "off", "@typescript-eslint/no-var-requires": "off", "no-unused-expressions": "off", "no-new": "off" diff --git a/test/tsconfig.json b/test/tsconfig.json new file mode 100644 index 0000000000..83e0923c2b --- /dev/null +++ b/test/tsconfig.json @@ -0,0 +1,17 @@ +{ + "compilerOptions": { + "target": "es6", + "module":"CommonJS", + "lib": ["es2015", "es2016", "es2017", "dom"], + "sourceMap": true, + "outDir": "dist", + "declaration": true, + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "resolveJsonModule": true, + "downlevelIteration": true, + "strict": true, + "suppressImplicitAnyIndexErrors": true + }, + "all": true +} diff --git a/tsconfig.json b/tsconfig.json index 5929b89cd6..258f536b4b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,5 +14,5 @@ "suppressImplicitAnyIndexErrors": true }, "all": true, - "exclude": [ "node_modules", "dist", "demo" ] + "exclude": [ "node_modules", "dist", "demo", "test" ] }