Skip to content

Commit 5f8f226

Browse files
committed
Add mode, finish processing
1 parent 74f112a commit 5f8f226

File tree

15 files changed

+182
-40
lines changed

15 files changed

+182
-40
lines changed

.github/workflows/examples.yml

Lines changed: 99 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,138 @@ on: [push]
44
jobs:
55
# make sure the action works on a clean machines without building
66

7-
## Basic
8-
test_basic_less:
7+
## Additions
8+
test_additions_deleted:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v1
1212
- uses: ./
1313
with:
1414
old: fixtures/file1_basic.txt
15-
new: fixtures/file2_less.txt
15+
new: fixtures/file2_deleted.txt
16+
mode: addition
1617

17-
test_basic_same:
18+
test_additions_same:
1819
runs-on: ubuntu-latest
1920
steps:
2021
- uses: actions/checkout@v1
2122
- uses: ./
2223
with:
2324
old: fixtures/file1_basic.txt
2425
new: fixtures/file3_same.txt
26+
mode: addition
2527

26-
test_basic_more:
28+
test_additions_added:
2729
runs-on: ubuntu-latest
2830
steps:
2931
- uses: actions/checkout@v1
3032
- uses: ./
3133
with:
3234
old: fixtures/file1_basic.txt
33-
new: fixtures/file4_more.txt
35+
new: fixtures/file4_added.txt
36+
mode: addition
3437

35-
test_basic_mixed:
38+
test_additions_mixed:
3639
runs-on: ubuntu-latest
3740
steps:
3841
- uses: actions/checkout@v1
3942
- uses: ./
4043
with:
4144
old: fixtures/file1_basic.txt
4245
new: fixtures/file5_mixed.txt
46+
mode: addition
4347

44-
test_basic_mixed_better:
48+
test_additions_mixed_added:
4549
runs-on: ubuntu-latest
4650
steps:
4751
- uses: actions/checkout@v1
4852
- uses: ./
4953
with:
5054
old: fixtures/file1_basic.txt
51-
new: fixtures/file6_mixed_better.txt
55+
new: fixtures/file6_mixed_added.txt
56+
mode: addition
5257

53-
test_basic_mixed_worse:
58+
test_additions_mixed_deleted:
5459
runs-on: ubuntu-latest
5560
steps:
5661
- uses: actions/checkout@v1
5762
- uses: ./
5863
with:
5964
old: fixtures/file1_basic.txt
60-
new: fixtures/file7_mixed_worse.txt
65+
new: fixtures/file7_mixed_deleted.txt
66+
mode: addition
6167

62-
# Tolerance
63-
test_tolerance_less:
68+
## Deletions
69+
test_deletions_deleted:
6470
runs-on: ubuntu-latest
6571
steps:
6672
- uses: actions/checkout@v1
6773
- uses: ./
6874
with:
6975
old: fixtures/file1_basic.txt
70-
new: fixtures/file2_less.txt
76+
new: fixtures/file2_deleted.txt
77+
mode: deletion
78+
79+
test_deletions_same:
80+
runs-on: ubuntu-latest
81+
steps:
82+
- uses: actions/checkout@v1
83+
- uses: ./
84+
with:
85+
old: fixtures/file1_basic.txt
86+
new: fixtures/file3_same.txt
87+
mode: deletion
88+
89+
test_deletions_added:
90+
runs-on: ubuntu-latest
91+
steps:
92+
- uses: actions/checkout@v1
93+
- uses: ./
94+
with:
95+
old: fixtures/file1_basic.txt
96+
new: fixtures/file4_added.txt
97+
mode: deletion
98+
99+
test_deletions_mixed:
100+
runs-on: ubuntu-latest
101+
steps:
102+
- uses: actions/checkout@v1
103+
- uses: ./
104+
with:
105+
old: fixtures/file1_basic.txt
106+
new: fixtures/file5_mixed.txt
107+
mode: deletion
108+
109+
test_deletions_mixed_added:
110+
runs-on: ubuntu-latest
111+
steps:
112+
- uses: actions/checkout@v1
113+
- uses: ./
114+
with:
115+
old: fixtures/file1_basic.txt
116+
new: fixtures/file6_mixed_added.txt
117+
mode: deletion
118+
119+
test_deletions_mixed_deleted:
120+
runs-on: ubuntu-latest
121+
steps:
122+
- uses: actions/checkout@v1
123+
- uses: ./
124+
with:
125+
old: fixtures/file1_basic.txt
126+
new: fixtures/file7_mixed_deleted.txt
127+
mode: deletion
128+
129+
# Tolerance (Additions)
130+
test_tolerance_deleted:
131+
runs-on: ubuntu-latest
132+
steps:
133+
- uses: actions/checkout@v1
134+
- uses: ./
135+
with:
136+
old: fixtures/file1_basic.txt
137+
new: fixtures/file2_deleted.txt
138+
mode: addition
71139
tolerance: worse
72140

73141
test_tolerance_same:
@@ -78,16 +146,18 @@ jobs:
78146
with:
79147
old: fixtures/file1_basic.txt
80148
new: fixtures/file3_same.txt
149+
mode: addition
81150
tolerance: same
82151

83-
test_tolerance_more:
152+
test_tolerance_added:
84153
runs-on: ubuntu-latest
85154
steps:
86155
- uses: actions/checkout@v1
87156
- uses: ./
88157
with:
89158
old: fixtures/file1_basic.txt
90-
new: fixtures/file4_more.txt
159+
new: fixtures/file4_added.txt
160+
mode: addition
91161
tolerance: better
92162

93163
test_tolerance_mixed:
@@ -98,26 +168,29 @@ jobs:
98168
with:
99169
old: fixtures/file1_basic.txt
100170
new: fixtures/file5_mixed.txt
171+
mode: addition
101172
tolerance: mixed
102173

103-
test_tolerance_mixed_better:
174+
test_tolerance_mixed_added:
104175
runs-on: ubuntu-latest
105176
steps:
106177
- uses: actions/checkout@v1
107178
- uses: ./
108179
with:
109180
old: fixtures/file1_basic.txt
110-
new: fixtures/file6_mixed_better.txt
181+
new: fixtures/file6_mixed_added.txt
182+
mode: addition
111183
tolerance: mixed-better
112184

113-
test_tolerance_mixed_worse:
185+
test_tolerance_mixed_deleted:
114186
runs-on: ubuntu-latest
115187
steps:
116188
- uses: actions/checkout@v1
117189
- uses: ./
118190
with:
119191
old: fixtures/file1_basic.txt
120-
new: fixtures/file7_mixed_worse.txt
192+
new: fixtures/file7_mixed_deleted.txt
193+
mode: addition
121194
tolerance: mixed-worse
122195

123196
# Outputs
@@ -128,7 +201,8 @@ jobs:
128201
- uses: ./
129202
with:
130203
old: fixtures/file1_basic.txt
131-
new: fixtures/file4_more.txt
204+
new: fixtures/file4_added.txt
205+
mode: addition
132206
output: out.txt
133207
- run: cat out.txt
134208

@@ -139,7 +213,8 @@ jobs:
139213
- uses: ./
140214
with:
141215
old: fixtures/file1_basic.txt
142-
new: fixtures/file4_more.txt
216+
new: fixtures/file4_added.txt
217+
mode: addition
143218
token: ${{ secrets.GITHUB }}
144219
notify_issue: true
145220
notify_check: true
@@ -151,7 +226,8 @@ jobs:
151226
- uses: ./
152227
with:
153228
old: fixtures/file1_basic.txt
154-
new: fixtures/file2_less.txt
229+
new: fixtures/file2_deleted.txt
230+
mode: addition
155231
token: ${{ secrets.GITHUB }}
156232
notify_issue: true
157233
notify_check: true

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This GitHub Action allows you to compare two files based on a tolerance, output
44

55
## Usage
66

7-
The following shows how to compare two files and output the difference to a file.
7+
The following shows how to compare two files, making sure only additions happened, and output the difference to a file.
88

99
```
1010
name: "build-test"
@@ -19,6 +19,7 @@ jobs:
1919
with:
2020
old: file1.txt
2121
new: file2.txt
22+
mode: addition
2223
tolerance: better
2324
output: out.txt
2425
```
@@ -35,9 +36,13 @@ See the [examples workflow](.github/workflows/examples.yml) for more details and
3536

3637
**Required** The second file to compare
3738

39+
### `mode`
40+
41+
**Required** The method used to measure the `tolerance`, can be either `addition` (addition are better) or `deletion` (deletion are better)
42+
3843
### `tolerance`
3944

40-
**Required** The tolerance to check the diff for, can be either `better` (only deletion), `mixed-better` (more deletion than addition), `same` (stay the exact same), `mixed` (same amount of lines but not the same), `mixed-worse` (more addition than deletion) or `worse` (only addition)
45+
**Required** The tolerance to check the diff for, depends on `mode`, can be either (examples given with mode = `deletion`) `better` (only deletion), `mixed-better` (more deletion than addition), `same` (stay the exact same), `mixed` (same amount of lines but not the same), `mixed-worse` (more addition than deletion) or `worse` (only addition)
4146

4247
### `output`
4348

__tests__/main.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import * as path from 'path';
55
// shows how the runner will run a javascript action with env / stdout protocol
66
test('test runs', () => {
77
process.env['INPUT_OLD'] = path.join(__dirname, '..', 'fixtures', 'file1_basic.txt');
8-
process.env['INPUT_NEW'] = path.join(__dirname, '..', 'fixtures', 'file4_more.txt');
8+
process.env['INPUT_NEW'] = path.join(__dirname, '..', 'fixtures', 'file4_added.txt');
99
process.env['INPUT_TOLERANCE'] = 'better';
10+
process.env['INPUT_MODE'] = 'addition';
1011
const ip = path.join(__dirname, '..', 'lib', 'main.js');
1112
const options: cp.ExecSyncOptions = {
1213
env: process.env,

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
new:
1212
description: 'second file to compare'
1313
required: true
14+
mode:
15+
description: 'the mode used to measure the tolerance'
16+
required: true
1417
tolerance:
1518
description: 'the tolerance used to judge if the diff improved'
1619
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)