Skip to content

Commit

Permalink
Change detection using git "three dot" diff (#35)
Browse files Browse the repository at this point in the history
* Rework change detection via `git diff`

Previous implementation performed simple diff between two versions. New implementation fetches on demand more commits to have the merge base between two branches. Now it will detect only changes introduced by branch that was pushed, instead of mixing with changes introduced meanwhile on the base branch.
  • Loading branch information
dorny committed Sep 1, 2020
1 parent 3f84574 commit 81c90cc
Show file tree
Hide file tree
Showing 7 changed files with 379 additions and 252 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: touch add.txt && rm README.md && echo "TEST" > LICENSE && git add -A
- name: configure GIT user
run: git config user.email "john@nowhere.local" && git config user.name "John Doe"
- name: modify working tree
run: touch add.txt && rm README.md && echo "TEST" > LICENSE
- name: commit changes
run: git add -A && git commit -a -m 'testing this action'
- uses: ./
id: filter
with:
Expand Down
17 changes: 5 additions & 12 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import * as git from '../src/git'
import {ExecOptions} from '@actions/exec'
import {ChangeStatus} from '../src/file'

describe('parsing of the git diff-index command', () => {
test('getChangedFiles returns files with correct change status', async () => {
const files = await git.getChangedFiles(git.FETCH_HEAD, (cmd, args, opts) => {
const stdout = opts?.listeners?.stdout
if (stdout) {
stdout(Buffer.from('A\u0000LICENSE\u0000'))
stdout(Buffer.from('M\u0000src/index.ts\u0000'))
stdout(Buffer.from('D\u0000src/main.ts\u0000'))
}
return Promise.resolve(0)
})
describe('parsing output of the git diff command', () => {
test('parseGitDiffOutput returns files with correct change status', async () => {
const files = git.parseGitDiffOutput(
'A\u0000LICENSE\u0000' + 'M\u0000src/index.ts\u0000' + 'D\u0000src/main.ts\u0000'
)
expect(files.length).toBe(3)
expect(files[0].filename).toBe('LICENSE')
expect(files[0].status).toBe(ChangeStatus.Added)
Expand Down
12 changes: 10 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,23 @@ inputs:
required: false
filters:
description: 'Path to the configuration file or YAML string with filters definition'
required: false
required: true
list-files:
description: |
Enables listing of files matching the filter:
'none' - Disables listing of matching files (default).
'json' - Matching files paths are serialized as JSON array.
'shell' - Matching files paths are escaped and space-delimited. Output is usable as command line argument list in linux shell.
required: false
required: true
default: none
initial-fetch-depth:
description: |
How many commits are initially fetched from base branch.
If needed, each subsequent fetch doubles the previously requested number of commits
until the merge-base is found or there are no more commits in the history.
This option takes effect only when changes are detected using git against different base branch.
required: false
default: '10'
runs:
using: 'node12'
main: 'dist/index.js'
Expand Down
Loading

0 comments on commit 81c90cc

Please sign in to comment.