Skip to content

Commit 50397c4

Browse files
Fix action failing when prevent-changes-to is empty (#3)
* Change README.md to test action * Update README for function input changes * Fix action failing when prevent-changes-to is empty
1 parent 0acc0cb commit 50397c4

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
## [4.1.1] - 2021-08-28
11+
### Fixed
12+
- Action now succeeds when `prevent-changes-to` is omitted/empty
13+
1014
## [4.1.0] - 2021-08-26
1115
### Changed
1216
- Update README.md for function input changes
@@ -49,7 +53,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4953
- @actions/core 1.2.7 → 1.5.0
5054
- @actions/github 4.0.0 → 5.0.0
5155

52-
[Unreleased]: https://github.com/syeutyu/validate-changed-files/compare/v4.1.0...HEAD
56+
[Unreleased]: https://github.com/syeutyu/validate-changed-files/compare/v4.1.1...HEAD
57+
[4.1.1]: https://github.com/syeutyu/validate-changed-files/compare/v4.1.0...v4.1.1
5358
[4.1.0]: https://github.com/syeutyu/validate-changed-files/compare/v4.0.1...v4.1.0
5459
[4.0.1]: https://github.com/syeutyu/validate-changed-files/compare/v4.0.0...v4.0.1
5560
[4.0.0]: https://github.com/syeutyu/validate-changed-files/compare/v3.0.3...v4.0.0

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7428,7 +7428,7 @@ async function main(
74287428
(pattern) => !!changedFiles.find((file) => minimatch(file, pattern))
74297429
);
74307430

7431-
const preventedFileChangedIncluded = preventFileChanges.every(
7431+
const preventedFileChangedIncluded = preventFileChanges.length > 0 && preventFileChanges.every(
74327432
(pattern) => !!changedFiles.find((file) => minimatch(file, pattern))
74337433
);
74347434

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ensure-files-changed",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "Github action to validate changed files on a pull request",
55
"main": "dist/index.js",
66
"scripts": {

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function main(
3535
(pattern) => !!changedFiles.find((file) => minimatch(file, pattern))
3636
);
3737

38-
const preventedFileChangedIncluded = preventFileChanges.every(
38+
const preventedFileChangedIncluded = preventFileChanges.length > 0 && preventFileChanges.every(
3939
(pattern) => !!changedFiles.find((file) => minimatch(file, pattern))
4040
);
4141

test/index.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,58 @@ describe("index.js", () => {
7171

7272
expect(result).to.be.true;
7373
});
74+
75+
it("should succeed if required files changed but files prevented from changes is empty", async () => {
76+
coreMock.expects("setOutput").withArgs("success", true).once();
77+
78+
const result = await main(
79+
context,
80+
{
81+
rest: {
82+
repos: {
83+
compareCommitsWithBasehead: () => ({
84+
data: {
85+
files: [
86+
{ filename: "package.json" },
87+
{ filename: "README.md" },
88+
],
89+
},
90+
}),
91+
},
92+
},
93+
},
94+
["package.json", "*.md"],
95+
undefined
96+
);
97+
98+
expect(result).to.be.true;
99+
});
100+
101+
it("should succeed if files prevented from changing did not change and require file changes is empty", async () => {
102+
coreMock.expects("setOutput").withArgs("success", true).once();
103+
104+
const result = await main(
105+
context,
106+
{
107+
rest: {
108+
repos: {
109+
compareCommitsWithBasehead: () => ({
110+
data: {
111+
files: [
112+
{ filename: "package.json" },
113+
{ filename: "README.md" },
114+
],
115+
},
116+
}),
117+
},
118+
},
119+
},
120+
undefined,
121+
["LICENSE.md"],
122+
);
123+
124+
expect(result).to.be.true;
125+
});
74126
});
75127

76128
describe("failure", () => {

0 commit comments

Comments
 (0)