Skip to content

Commit 3a290f0

Browse files
authored
Merge pull request #1 from duckduckgo/xcodeproj
Task URL: https://app.asana.com/0/1203301625297703/1203780951670808/f Since this makes sense only for macOS Browser for now, the check verifies repo name, and only performs any action for "macos-browser”.
2 parents 8df4677 + 1343c5c commit 3a290f0

File tree

2 files changed

+133
-2
lines changed

2 files changed

+133
-2
lines changed

org/allPRs.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {warn, danger} from "danger"
1+
import {fail, warn, danger} from "danger"
22

33
export const prSize = async () => {
44
// Warn when there is a big PR
@@ -16,8 +16,29 @@ export const internalLink = async () => {
1616
}
1717
}
1818

19+
export const xcodeprojConfiguration = async () => {
20+
if (danger.github.thisPR.repo == "macos-browser") {
21+
const projectFile = "DuckDuckGo.xcodeproj/project.pbxproj";
22+
if (danger.git.modified_files.includes(projectFile)) {
23+
let diff = await danger.git.diffForFile(projectFile);
24+
let addedLines = diff?.added.split(/\n/);
25+
// The regex is equal to:
26+
// * plus sign
27+
// * 1 or more tabulation keys
28+
// * an identifier (key) consisting of capital letters, underscores and digits,
29+
// * a space and an equality sign
30+
// * arbitrary number of any characters (the value can be empty)
31+
// * a semicolon
32+
if (addedLines?.find(value => /^\+\t+[A-Z_0-9]* =.*;$/i.test(value))) {
33+
fail("No configuration is allowed inside Xcode project file - use xcconfig files instead.");
34+
}
35+
}
36+
}
37+
}
38+
1939
// Default run
2040
export default async () => {
2141
await prSize()
2242
await internalLink()
23-
}
43+
await xcodeprojConfiguration()
44+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
jest.mock("danger", () => jest.fn())
2+
import danger from 'danger'
3+
const dm = danger as any;
4+
5+
import { xcodeprojConfiguration } from '../org/allPRs'
6+
7+
beforeEach(() => {
8+
dm.addedLines = ""
9+
dm.fail = jest.fn().mockReturnValue(true);
10+
11+
dm.danger = {
12+
git: {
13+
diffForFile: async (_filename) => {
14+
return { added: dm.addedLines }
15+
},
16+
modified_files: [
17+
"DuckDuckGo.xcodeproj/project.pbxproj"
18+
]
19+
},
20+
github: {
21+
pr: {
22+
additions: 200,
23+
deletions: 10
24+
},
25+
thisPR: {
26+
repo: "macos-browser"
27+
}
28+
},
29+
}
30+
})
31+
32+
describe("Xcode project file configuration checks", () => {
33+
it("does not fail with no changes to project file", async () => {
34+
dm.danger.git.modified_files = []
35+
36+
await xcodeprojConfiguration()
37+
38+
expect(dm.fail).not.toHaveBeenCalled()
39+
})
40+
41+
it("does not fail with no diff in project file", async () => {
42+
dm.danger.git.diffForFile = async (_filename) => {}
43+
44+
await xcodeprojConfiguration()
45+
46+
expect(dm.fail).not.toHaveBeenCalled()
47+
})
48+
49+
it("does not fail with no additions", async () => {
50+
await xcodeprojConfiguration()
51+
52+
expect(dm.fail).not.toHaveBeenCalled()
53+
})
54+
55+
it("does not fail with added source file", async () => {
56+
dm.addedLines = `
57+
+ 372C27BE297AD5C200C758EB /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372C27BD297AD5C200C758EB /* Test.swift */; };
58+
+ 372C27BD297AD5C200C758EB /* Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; };
59+
+ 372C27BD297AD5C200C758EB /* Test.swift */,
60+
+ 372C27BE297AD5C200C758EB /* Test.swift in Sources */,
61+
`
62+
63+
await xcodeprojConfiguration()
64+
65+
expect(dm.fail).not.toHaveBeenCalled()
66+
})
67+
68+
it("fails with added configuration", async () => {
69+
dm.addedLines = `
70+
+ ALLOW_TARGET_PLATFORM_SPECIALIZATION = YES;
71+
`
72+
73+
await xcodeprojConfiguration()
74+
75+
expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.")
76+
})
77+
78+
it("fails with added configuration with empty value", async () => {
79+
dm.addedLines = `
80+
+ CODE_SIGN_IDENTITY = ;
81+
`
82+
83+
await xcodeprojConfiguration()
84+
85+
expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.")
86+
})
87+
88+
it("fails with added configuration with key containing digits", async () => {
89+
dm.addedLines = `
90+
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES_ERROR;
91+
`
92+
93+
await xcodeprojConfiguration()
94+
95+
expect(dm.fail).toHaveBeenCalledWith("No configuration is allowed inside Xcode project file - use xcconfig files instead.")
96+
})
97+
98+
it("does not fail with added cofiguration in non-macos app repo", async () => {
99+
dm.danger.github.thisPR.repo = "iOS"
100+
dm.addedLines = `
101+
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES_ERROR;
102+
`
103+
104+
await xcodeprojConfiguration()
105+
106+
expect(dm.fail).not.toHaveBeenCalled()
107+
})
108+
})
109+
110+

0 commit comments

Comments
 (0)