-
-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1160
- Loading branch information
Showing
4 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Env, CISource } from "../ci_source" | ||
import { ensureEnvKeysExist } from "../ci_source_helpers" | ||
|
||
/** | ||
* ### CI Setup | ||
* | ||
* Install dependencies and add a danger step to the custom build scripts. | ||
* See the Xcode Cloud documentation [here](https://developer.apple.com/documentation/xcode/writing-custom-build-scripts) | ||
* | ||
* ### Token Setup | ||
* | ||
* Setup the acesss token (for github `DANGER_GITHUB_API_TOKEN`) environment variable for your workflow. | ||
* See the Xcode Cloud documentation [here](https://developer.apple.com/documentation/xcode/xcode-cloud-workflow-reference#Custom-Environment-Variables) | ||
*/ | ||
export class XcodeCloud implements CISource { | ||
constructor(private readonly env: Env) { } | ||
|
||
get name(): string { | ||
return "Xcode Cloud" | ||
} | ||
|
||
get isCI(): boolean { | ||
const mustHave = ["CI", "CI_XCODEBUILD_ACTION"] | ||
return ( | ||
ensureEnvKeysExist(this.env, mustHave) && | ||
this.env.CI == "TRUE" | ||
) | ||
} | ||
|
||
get isPR(): boolean { | ||
const mustHave = ["CI_PULL_REQUEST_NUMBER", "CI_PULL_REQUEST_TARGET_REPO"] | ||
return ensureEnvKeysExist(this.env, mustHave) | ||
} | ||
|
||
get repoSlug(): string { | ||
return this.env.CI_PULL_REQUEST_TARGET_REPO | ||
} | ||
|
||
get pullRequestID(): string { | ||
return this.env.CI_PULL_REQUEST_NUMBER | ||
} | ||
|
||
get commitHash(): string { | ||
return this.env.CI_COMMIT | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { XcodeCloud } from "../XcodeCloud" | ||
import { getCISourceForEnv } from "../../get_ci_source" | ||
|
||
const correctEnv = { | ||
CI: "TRUE", | ||
CI_XCODEBUILD_ACTION: "build", | ||
CI_PULL_REQUEST_TARGET_REPO: "someone/something", | ||
CI_PULL_REQUEST_NUMBER: "999", | ||
} | ||
|
||
describe("being found when looking for CI", () => { | ||
it("finds XcodeCloud with the right ENV", () => { | ||
const ci = getCISourceForEnv(correctEnv) | ||
expect(ci).toBeInstanceOf(XcodeCloud) | ||
}) | ||
}) | ||
|
||
describe(".isCI", () => { | ||
it("validates when all XcodeCloud environment vars are set", () => { | ||
const xcodeCloud = new XcodeCloud(correctEnv) | ||
expect(xcodeCloud.isCI).toBeTruthy() | ||
}) | ||
|
||
it("does not validate", () => { | ||
const xcodeCloud = new XcodeCloud({}) | ||
expect(xcodeCloud.isCI).toBeFalsy() | ||
}) | ||
}) | ||
|
||
describe(".isPR", () => { | ||
it("validates when all XcodeCloud environment vars are set", () => { | ||
const xcodeCloud = new XcodeCloud(correctEnv) | ||
expect(xcodeCloud.isPR).toBeTruthy() | ||
}) | ||
|
||
it("does not validate outside of XcodeCloud", () => { | ||
const xcodeCloud = new XcodeCloud({}) | ||
expect(xcodeCloud.isPR).toBeFalsy() | ||
}) | ||
|
||
const envs = ["CI_PULL_REQUEST_TARGET_REPO", "CI_PULL_REQUEST_NUMBER"] | ||
envs.forEach((key: string) => { | ||
let env = { | ||
CI_PULL_REQUEST_TARGET_REPO: "someone/something", | ||
CI_PULL_REQUEST_NUMBER: "999", | ||
} | ||
env[key] = null | ||
|
||
it(`does not validate when ${key} is missing`, () => { | ||
const xcodeCloud = new XcodeCloud(env) | ||
expect(xcodeCloud.isPR).toBeFalsy() | ||
}) | ||
}) | ||
}) | ||
|
||
describe(".pullRequestID", () => { | ||
it("pulls it out of the env", () => { | ||
const xcodeCloud = new XcodeCloud({ CI_PULL_REQUEST_NUMBER: "999" }) | ||
expect(xcodeCloud.pullRequestID).toEqual("999") | ||
}) | ||
}) | ||
|
||
describe(".repoSlug", () => { | ||
it("pulls it out of the env", () => { | ||
const xcodeCloud = new XcodeCloud({ CI_PULL_REQUEST_TARGET_REPO: "someone/something" }) | ||
expect(xcodeCloud.repoSlug).toEqual("someone/something") | ||
}) | ||
}) | ||
|
||
describe("commit hash", () => { | ||
it("returns correct commit hash when present", () => { | ||
const env = { | ||
...correctEnv, | ||
CI_COMMIT: "1234abc", | ||
} | ||
const xcodeCloud = new XcodeCloud(env) | ||
expect(xcodeCloud.commitHash).toEqual("1234abc") | ||
}) | ||
|
||
it("returns no commit hash when not present", () => { | ||
const xcodeCloud = new XcodeCloud(correctEnv) | ||
expect(xcodeCloud.commitHash).toBeUndefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters