Skip to content

Commit

Permalink
Extend output with change status counts
Browse files Browse the repository at this point in the history
  • Loading branch information
Obi-Dann committed Sep 11, 2024
1 parent 298e00d commit ccf918f
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/filters.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error:
- not_existing_path/**/*
any:
- "**/*"
- '**/*'
31 changes: 16 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Build"
name: 'Build'
on:
push:
paths-ignore: [ '*.md' ]
paths-ignore: ['*.md']
branches:
- master

Expand All @@ -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
194 changes: 117 additions & 77 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Pull Request Verification"
name: 'Pull Request Verification'
on:
pull_request:
paths-ignore: [ '*.md' ]
paths-ignore: ['*.md']
branches:
- master
- '**'
Expand All @@ -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
4 changes: 4 additions & 0 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ccf918f

Please sign in to comment.