diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 00000000..1bf440e2 --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,21 @@ +name: "Build" +inputs: + package-name: + description: 'Name of the package' + required: true +runs: + using: "composite" + steps: + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + + - name: Setup environment + uses: ./.github/actions/setup + + - name: Build the package with dependencies + env: + STRYKER_DASHBOARD_API_KEY: ${{ inputs.stryker_dashboard_api_key }} + shell: bash + run: yarn workspaces foreach -Rpt --from '${{ inputs.package-name }}' run build \ No newline at end of file diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml new file mode 100644 index 00000000..feb4a44c --- /dev/null +++ b/.github/actions/lint/action.yml @@ -0,0 +1,19 @@ +name: "Lint" +inputs: + package-name: + description: 'Name of the package' + required: true +runs: + using: "composite" + steps: + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + + - name: Setup environment + uses: ./.github/actions/setup + + - name: Run ESLint check + shell: bash + run: yarn workspace ${{ inputs.package-name }} lint:ci diff --git a/.github/actions/mutation-tests-all-files/action.yml b/.github/actions/mutation-tests-all-files/action.yml new file mode 100644 index 00000000..e8b741c3 --- /dev/null +++ b/.github/actions/mutation-tests-all-files/action.yml @@ -0,0 +1,22 @@ +name: Mutation tests for all files +inputs: + package-name: + description: 'Name of the package' + required: true + stryker_dashboard_api_key: + description: 'Stryker dashboard api key' + required: true +runs: + using: "composite" + steps: + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + + - name: Setup environment + uses: ./.github/actions/setup + + - name: Run mutation tests + shell: bash + id: run-mutation-tests + run: yarn workspace ${{ inputs.package-name }} test:mutations --dashboard.version main \ No newline at end of file diff --git a/.github/actions/mutation-tests-changed-files/action.yml b/.github/actions/mutation-tests-changed-files/action.yml new file mode 100644 index 00000000..e4fd88af --- /dev/null +++ b/.github/actions/mutation-tests-changed-files/action.yml @@ -0,0 +1,99 @@ +name: Mutation tests for changed files +inputs: + working-directory: + description: 'Path to the ./packages/name_of_your_package_folder' + required: true + package-name: + description: 'A full name of the package' + required: true + stryker_dashboard_api_key: + description: 'Stryker dashboard api key' + required: true +runs: + using: "composite" + steps: + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + + - name: Setup environment + uses: ./.github/actions/setup + + - name: Get changed files + uses: tj-actions/changed-files@v39.0.0 + id: changed-files + with: + files_yaml: | + src: + - 'src/**/*.ts' + - '!src/**/*.spec.ts' + - '!src/**/__mocks__/**' + separator: "','" + path: ${{ inputs.working-directory }} + + - name: Run mutation tests + if: steps.changed-files.outputs.src_any_changed == 'true' + shell: bash + id: run-mutation-tests + run: yarn workspace ${{ inputs.package-name }} test:mutations --mutate ${{format('''{0}''', steps.changed-files.outputs.src_all_changed_files)}} + continue-on-error: true + + - name: Find current PR's number + uses: jwalton/gh-find-current-pr@v1 + id: findPr + + - name: Comment on successful mutation testing + uses: thollander/actions-comment-pull-request@v2 + env: + STRYKER_DASHBOARD_API_KEY: ${{ inputs.stryker_dashboard_api_key }} + if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'success' && ${{ steps.findPr.outputs.number != '' }} + with: + message: | + ✅ Mutation testing passed for `${{ inputs.working-directory }}` + + Report: https://dashboard.stryker-mutator.io/reports/github.com/editor-js/document-model/PR-${{ github.event.number }} + +
+ Mutated files +
+            ${{ join(fromJson(format('[{0}]', format('''{0}''', steps.changed-files.outputs.src_all_changed_files))), '
') }} +
+
+ comment_tag: mutation-tests for `${{ inputs.working-directory }}` + pr_number: ${{ steps.findPr.outputs.number != '' && steps.findPr.outputs.number || '1'}} + + - name: Comment on failed mutation testing + uses: thollander/actions-comment-pull-request@v2 + env: + STRYKER_DASHBOARD_API_KEY: ${{ inputs.stryker_dashboard_api_key }} + if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'failure' && ${{ steps.findPr.outputs.number != '' }} + with: + message: | + ❌ Mutation testing hasn't passed score threshold for `${{ inputs.working-directory }}` + + Report: https://dashboard.stryker-mutator.io/reports/github.com/editor-js/document-model/PR-${{ github.event.number }} + +
+ Mutated files +
+            ${{ join(fromJson(format('[{0}]', format('''{0}''', steps.changed-files.outputs.src_all_changed_files))), '
') }} +
+
+ comment_tag: mutation-tests for `${{ inputs.working-directory }}` + pr_number: ${{ steps.findPr.outputs.number != '' && steps.findPr.outputs.number || '1'}} + + - name: Comment on empty changes + uses: thollander/actions-comment-pull-request@v2 + env: + STRYKER_DASHBOARD_API_KEY: ${{ inputs.stryker_dashboard_api_key }} + if: steps.changed-files.outputs.src_any_changed == 'false' && ${{ steps.findPr.outputs.number != '' }} + with: + message: | + ⏭️ No files to mutate for `${{ inputs.working-directory }}` + + comment_tag: mutation-tests for `${{ inputs.working-directory }}` + pr_number: ${{ steps.findPr.outputs.number != '' && steps.findPr.outputs.number || '1'}} + + - if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'failure' + shell: bash + run: exit 1 \ No newline at end of file diff --git a/.github/actions/unit-tests/action.yml b/.github/actions/unit-tests/action.yml new file mode 100644 index 00000000..e47ee8e7 --- /dev/null +++ b/.github/actions/unit-tests/action.yml @@ -0,0 +1,29 @@ +name: Unit tests +inputs: + working-directory: + description: 'Path to the ./packages/name_of_your_package_folder' + required: true + package-name: + description: 'A full name of the package' + required: true + +runs: + using: "composite" + steps: + - uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + - uses: ./.github/actions/setup + + # Find current PR's number + - uses: jwalton/gh-find-current-pr@v1 + id: findPr + + - name: Run unit tests + uses: ArtiomTr/jest-coverage-report-action@v2 + with: + custom-title: Coverage report for `${{ inputs.working-directory }}` + working-directory: ${{ inputs.working-directory }} + test-script: yarn workspace ${{ inputs.package-name }} test + package-manager: yarn + prnumber: ${{ steps.findPr.outputs.number }} \ No newline at end of file diff --git a/.github/workflows/dom-adapters.yml b/.github/workflows/dom-adapters.yml new file mode 100644 index 00000000..2947b41c --- /dev/null +++ b/.github/workflows/dom-adapters.yml @@ -0,0 +1,53 @@ +name: Dom-adapters check +on: + push: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run ESLint check + uses: ./.github/actions/lint + with: + package-name: '@editorjs/dom-adapters' + + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run unit tests + uses: ./.github/actions/unit-tests + with: + working-directory: './packages/dom-adapters' + package-name: '@editorjs/dom-adapters' + + mutation-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Run mutation tests for changed files + if: ${{ github.event_name == 'push' }} + uses: ./.github/actions/mutation-tests-changed-files + with: + package-name: '@editorjs/dom-adapters' + working-directory: './packages/dom-adapters' + stryker_dashboard_api_key: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + + - name: Run mutation tests for all files + if: ${{ github.event_name == 'merge_group' }} + uses: ./.github/actions/mutation-tests-all-files + with: + package-name: '@editorjs/dom-adapters' + working-directory: './packages/dom-adapters' + stryker_dashboard_api_key: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build the package + uses: ./.github/actions/build + with: + package-name: '@editorjs/dom-adapters' \ No newline at end of file diff --git a/.github/workflows/model-merge.yml b/.github/workflows/model-merge.yml deleted file mode 100644 index 05c2c877..00000000 --- a/.github/workflows/model-merge.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Merge queue workflow runner for model package -on: - merge_group: - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup - - name: Run ESLint check - run: yarn workspace @editorjs/model lint:ci - - tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup - - name: Run unit tests - uses: ArtiomTr/jest-coverage-report-action@v2 - with: - working-directory: ./packages/model - test-script: yarn workspace @editorjs/model test - package-manager: yarn - - mutation-tests: - runs-on: ubuntu-latest - env: - STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - - uses: ./.github/actions/setup - - - name: Run mutation tests - id: run-mutation-tests - run: yarn workspace @editorjs/model test:mutations --dashboard.version main - - - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup - - name: Build the package - run: yarn workspace @editorjs/model build diff --git a/.github/workflows/model.yml b/.github/workflows/model.yml index 4b42e945..3d4b3c11 100644 --- a/.github/workflows/model.yml +++ b/.github/workflows/model.yml @@ -1,118 +1,55 @@ -name: Model package workflow runner +name: Model check on: - pull_request: + push: + merge_group: jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup - name: Run ESLint check - run: yarn workspace @editorjs/model lint:ci - + uses: ./.github/actions/lint + with: + package-name: '@editorjs/model' + tests: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup + - name: Run unit tests - uses: ArtiomTr/jest-coverage-report-action@v2 + uses: ./.github/actions/unit-tests with: - working-directory: ./packages/model - test-script: yarn test - package-manager: yarn + package-name: '@editorjs/model' + working-directory: './packages/model' mutation-tests: runs-on: ubuntu-latest - env: - STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - name: Setup environment - uses: ./.github/actions/setup - - - name: Get changed files - uses: tj-actions/changed-files@v39.0.0 - id: changed-files + - name: Run mutation tests for changed files + if: ${{ github.event_name == 'push' }} + uses: ./.github/actions/mutation-tests-changed-files with: - files_yaml: | - src: - - 'src/**/*.ts' - - '!src/**/*.spec.ts' - - '!src/**/__mocks__/**' - separator: "','" - path: packages/model - - - name: Run mutation tests - if: steps.changed-files.outputs.src_any_changed == 'true' - id: run-mutation-tests - run: yarn workspace @editorjs/model test:mutations --mutate ${{format('''{0}''', steps.changed-files.outputs.src_all_changed_files)}} - continue-on-error: true + package-name: '@editorjs/model' + working-directory: './packages/model' + stryker_dashboard_api_key: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} - - name: Comment on successful mutation testing - uses: thollander/actions-comment-pull-request@v2 - if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'success' + - name: Run mutation tests for all files + if: ${{ github.event_name == 'merge_group' }} + uses: ./.github/actions/mutation-tests-all-files with: - message: | - ## ✅ Mutation testing passed - - Report: https://dashboard.stryker-mutator.io/reports/github.com/editor-js/document-model/PR-${{ github.event.number }} - -
- Mutated files -
-            ${{ join(fromJson(format('[{0}]', format('''{0}''', steps.changed-files.outputs.src_all_changed_files))), '
') }} -
-
- comment_tag: mutation-tests - - - name: Comment on failed mutation testing - uses: thollander/actions-comment-pull-request@v2 - if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'failure' - with: - message: | - ## ❌ Mutation testing hasn't passed score threshold - - Report: https://dashboard.stryker-mutator.io/reports/github.com/editor-js/document-model/PR-${{ github.event.number }} - -
- Mutated files -
-            ${{ join(fromJson(format('[{0}]', format('''{0}''', steps.changed-files.outputs.src_all_changed_files))), '
') }} -
-
- comment_tag: mutation-tests - - - name: Comment on empty changes - uses: thollander/actions-comment-pull-request@v2 - if: steps.changed-files.outputs.src_any_changed == 'false' - with: - message: | - ## ⏭️ No files to mutate - - comment_tag: mutation-tests - - - if: steps.changed-files.outputs.src_any_changed == 'true' && steps.run-mutation-tests.outcome == 'failure' - run: exit 1 + package-name: '@editorjs/model' + working-directory: './packages/model' + stryker_dashboard_api_key: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-node@v3 - with: - node-version-file: .nvmrc - - uses: ./.github/actions/setup - name: Build the package - run: yarn workspace @editorjs/model build + uses: ./.github/actions/build + with: + package-name: '@editorjs/model' diff --git a/.github/workflows/playground.yml b/.github/workflows/playground.yml new file mode 100644 index 00000000..553a8b69 --- /dev/null +++ b/.github/workflows/playground.yml @@ -0,0 +1,23 @@ +name: Playground check +on: + push: + merge_group: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run ESLint check + uses: ./.github/actions/lint + with: + package-name: '@editorjs/document-playground' + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Build the package + uses: ./.github/actions/build + with: + package-name: '@editorjs/document-playground' \ No newline at end of file diff --git a/packages/dom-adapters/src/caret/CaretAdapter.ts b/packages/dom-adapters/src/caret/CaretAdapter.ts index a758882e..ea1a2252 100644 --- a/packages/dom-adapters/src/caret/CaretAdapter.ts +++ b/packages/dom-adapters/src/caret/CaretAdapter.ts @@ -68,6 +68,7 @@ export class CaretAdapter extends EventTarget { * @param input - input to watch caret change * @param _dataKey - key of data property in block's data that contains input's value */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars -- unused parameter for now public attachInput(input: HTMLElement, _dataKey: string): void { this.#input = input; diff --git a/packages/dom-adapters/src/index.spec.ts b/packages/dom-adapters/src/index.spec.ts new file mode 100644 index 00000000..12fd3a8c --- /dev/null +++ b/packages/dom-adapters/src/index.spec.ts @@ -0,0 +1,5 @@ +describe('Example test', () => { + it('should pass', () => { + expect(true).toBe(true); + }); +}); diff --git a/packages/dom-adapters/src/index.ts b/packages/dom-adapters/src/index.ts index e36e8d1c..53537883 100644 --- a/packages/dom-adapters/src/index.ts +++ b/packages/dom-adapters/src/index.ts @@ -1 +1,2 @@ -export { BlockToolAdapter } from './BlockToolAdapter/index.js'; +export * from './caret/CaretAdapter.js'; +export * from './BlockToolAdapter/index.js'; diff --git a/packages/playground/package.json b/packages/playground/package.json index 64e1afa7..d3e26ba4 100644 --- a/packages/playground/package.json +++ b/packages/playground/package.json @@ -8,6 +8,7 @@ "build": "vue-tsc && vite build", "preview": "vite preview", "lint": "eslint src --ext .ts,.vue", + "lint:ci": "yarn lint --max-warnings 0", "lint:fix": "yarn lint --fix" }, "dependencies": { diff --git a/packages/playground/src/App.vue b/packages/playground/src/App.vue index 2555e1c9..3c1c48fc 100644 --- a/packages/playground/src/App.vue +++ b/packages/playground/src/App.vue @@ -1,7 +1,7 @@