From ccf918f6c8c8571b3ddd16dcb1358fc6c68081da Mon Sep 17 00:00:00 2001 From: Daniil Samoylov Date: Wed, 11 Sep 2024 17:38:22 +1200 Subject: [PATCH] Extend output with change status counts --- .github/filters.yml | 2 +- .github/workflows/build.yml | 31 +-- .../workflows/pull-request-verification.yml | 194 +++++++++++------- __tests__/filter.test.ts | 4 + src/main.ts | 5 + 5 files changed, 143 insertions(+), 93 deletions(-) diff --git a/.github/filters.yml b/.github/filters.yml index 078e6508..33fa9f45 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -1,4 +1,4 @@ error: - not_existing_path/**/* any: - - "**/*" \ No newline at end of file + - '**/*' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a291144d..0087ac5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ -name: "Build" +name: 'Build' on: push: - paths-ignore: [ '*.md' ] + paths-ignore: ['*.md'] branches: - master @@ -12,20 +12,21 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: volta-cli/action@v4 - - run: | - pnpm install - pnpm run all + - uses: actions/checkout@v4 + - uses: volta-cli/action@v4 + - run: | + pnpm install + pnpm run all self-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: ./ - id: filter - with: - filters: '.github/filters.yml' - - name: filter-test - if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' - run: exit 1 + - uses: actions/checkout@v4 + - uses: ./ + id: filter + with: + filters: '.github/filters.yml' + + - name: filter-test + if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' + run: exit 1 diff --git a/.github/workflows/pull-request-verification.yml b/.github/workflows/pull-request-verification.yml index 8480cf93..2018ba32 100644 --- a/.github/workflows/pull-request-verification.yml +++ b/.github/workflows/pull-request-verification.yml @@ -1,7 +1,7 @@ -name: "Pull Request Verification" +name: 'Pull Request Verification' on: pull_request: - paths-ignore: [ '*.md' ] + paths-ignore: ['*.md'] branches: - master - '**' @@ -13,102 +13,142 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Need history for changelog generation - - uses: volta-cli/action@v4 - - run: | - pnpm i - pnpm run all - # We need to make sure the checked-in `index.mjs` actually matches what we expect it to be. - - name: Compare the expected and actual dist/ directories - run: | - if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" - git diff - exit 1 - fi + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Need history for changelog generation + - uses: volta-cli/action@v4 + - run: | + pnpm i + pnpm run all + # We need to make sure the checked-in `index.mjs` actually matches what we expect it to be. + - name: Compare the expected and actual dist/ directories + run: | + if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then + echo "Detected uncommitted changes after build. See status below:" + git diff + exit 1 + fi test-inline: runs-on: ubuntu-latest permissions: pull-requests: read steps: - - uses: actions/checkout@v4 - - uses: ./ - id: filter - with: - filters: | - error: - - not_existing_path/**/* - any: - - "**/*" - - name: filter-test - if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' - run: exit 1 - - name: changes-test - if: contains(fromJSON(steps.filter.outputs.changes), 'error') || !contains(fromJSON(steps.filter.outputs.changes), 'any') - run: exit 1 + - uses: actions/checkout@v4 + + - uses: ./ + id: filter + with: + filters: | + error: + - not_existing_path/**/* + any: + - "**/*" + + - name: Dump output + env: + OUTPUT: ${{ toJson(steps.filter.outputs) }} + run: echo "$OUTPUT" + + - name: filter-test + if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' + run: exit 1 + - name: changes-test + if: contains(fromJSON(steps.filter.outputs.changes), 'error') || !contains(fromJSON(steps.filter.outputs.changes), 'any') + run: exit 1 test-external: runs-on: ubuntu-latest permissions: pull-requests: read steps: - - uses: actions/checkout@v4 - - uses: ./ - id: filter - with: - filters: '.github/filters.yml' - - name: filter-test - if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' - run: exit 1 + - uses: actions/checkout@v4 + + - uses: ./ + id: filter + with: + filters: '.github/filters.yml' + + - name: Dump output + env: + OUTPUT: ${{ toJson(steps.filter.outputs) }} + run: echo "$OUTPUT" + + - name: filter-test + if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' + run: exit 1 test-without-token: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: ./ - id: filter - with: - token: '' - filters: '.github/filters.yml' - - name: filter-test - if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' - run: exit 1 + - uses: actions/checkout@v4 + + - uses: ./ + id: filter + with: + token: '' + filters: '.github/filters.yml' + + - name: Dump output + env: + OUTPUT: ${{ toJson(steps.filter.outputs) }} + run: echo "$OUTPUT" + + - name: filter-test + if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' + run: exit 1 test-wd-without-token: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - with: - path: somewhere - - uses: ./somewhere - id: filter - with: - token: '' - working-directory: somewhere - filters: '.github/filters.yml' - - name: filter-test - if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' - run: exit 1 + - uses: actions/checkout@v4 + with: + path: somewhere + + - uses: ./somewhere + id: filter + with: + token: '' + working-directory: somewhere + filters: '.github/filters.yml' + + - name: Dump output + env: + OUTPUT: ${{ toJson(steps.filter.outputs) }} + run: echo "$OUTPUT" + + - name: filter-test + if: steps.filter.outputs.any != 'true' || steps.filter.outputs.error == 'true' + run: exit 1 test-local-changes: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - run: echo "NEW FILE" > local - - run: git add local - - uses: ./ - id: filter - with: - base: HEAD - filters: | - local: - - local - - name: filter-test - if: steps.filter.outputs.local != 'true' - run: exit 1 - - name: count-test - if: steps.filter.outputs.local_count != 1 - run: exit 1 + - uses: actions/checkout@v4 + - run: echo "NEW FILE" > local + - run: git add local + + - uses: ./ + id: filter + with: + base: HEAD + filters: | + local: + - local + + - name: Dump output + env: + OUTPUT: ${{ toJson(steps.filter.outputs) }} + run: echo "$OUTPUT" + + - name: filter-test + if: steps.filter.outputs.local != 'true' + run: exit 1 + + - name: count-test + if: steps.filter.outputs.local_count != 1 + run: exit 1 + + - name: added-test + if: steps.filter.outputs.local_added != 1 + run: exit 1 diff --git a/__tests__/filter.test.ts b/__tests__/filter.test.ts index add807ae..e3654a3e 100644 --- a/__tests__/filter.test.ts +++ b/__tests__/filter.test.ts @@ -135,19 +135,23 @@ describe('matching tests', () => { src: - 'src/**/*.ts' - '!src/**/*.test.ts' + - 'src/special_test/tests/*.test.ts' ` const filter = new Filter(yaml) const jsFiles = modified(['src/app/module/file.js']) const tsFiles = modified(['src/app/module/file.ts']) const tsTestFiles = modified(['src/app/module/file.test.ts']) + const overriddenTestFiles = modified(['src/special_test/tests/file.test.ts']) const jsMatch = filter.match(jsFiles) const tsMatch = filter.match(tsFiles) const tsTestMatch = filter.match(tsTestFiles) + const overiddenTestMatch = filter.match(overriddenTestFiles) expect(jsMatch.src).toEqual([]) expect(tsMatch.src).toEqual(tsFiles) expect(tsTestMatch.src).toEqual([]) + expect(overiddenTestMatch.src).toEqual(overriddenTestFiles) }) test('matches path based on rules included using YAML anchor', () => { diff --git a/src/main.ts b/src/main.ts index 7142fde6..ab7babca 100644 --- a/src/main.ts +++ b/src/main.ts @@ -242,6 +242,11 @@ function exportResults(results: FilterResults, format: ExportFormat): void { core.setOutput(key, value) core.setOutput(`${key}_count`, files.length) + + for (const status of Object.values(ChangeStatus)) { + core.setOutput(`${key}_${status.toLocaleLowerCase()}`, files.filter(x => x.status === status).length) + } + if (format !== 'none') { const filesValue = serializeExport(files, format) core.setOutput(`${key}_files`, filesValue)