Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change detection using git "three dot" diff #35

Merged
merged 17 commits into from
Sep 1, 2020
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