-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a check in CI/CD environments for `account_id`, `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`. If `account_id` exists in `wrangler.toml` then `CLOUDFLARE_ACCOUNT_ID` is not needed in CI/CD scope. The `CLOUDFLARE_API_TOKEN` is necessary in CI/CD scope and will always error if missing. resolves #827
- Loading branch information
1 parent
277b254
commit a2f1ee7
Showing
5 changed files
with
129 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: Added a check in CI/CD environments for `account_id`, `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`. If `account_id` exists in `wrangler.toml` | ||
then `CLOUDFLARE_ACCOUNT_ID` is not needed in CI/CD scope. The `CLOUDFLARE_API_TOKEN` is necessary in CI/CD scope and will always error if missing. | ||
|
||
resolves #827 |
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,96 @@ | ||
import { mockConsoleMethods } from "./helpers/mock-console"; | ||
import { runInTempDir } from "./helpers/run-in-tmp"; | ||
import { runWrangler } from "./helpers/run-wrangler"; | ||
import writeWranglerToml from "./helpers/write-wrangler-toml"; | ||
|
||
describe("CI", () => { | ||
const ENV_COPY = process.env; | ||
const std = mockConsoleMethods(); | ||
runInTempDir(); | ||
|
||
beforeEach(() => { | ||
process.env = { | ||
...ENV_COPY, | ||
CI: "true", | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = ENV_COPY; | ||
}); | ||
|
||
it("should not throw an error in CI if 'CLOUDFLARE_API_TOKEN' & 'account_id' are in scope", async () => { | ||
writeWranglerToml({ | ||
account_id: "IG-88", | ||
}); | ||
|
||
process.env = { | ||
CLOUDFLARE_API_TOKEN: "123456789", | ||
}; | ||
|
||
await runWrangler().catch((err) => { | ||
expect(err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
it("should not throw an error if 'CLOUDFLARE_ACCOUNT_ID' & 'CLOUDFLARE_API_TOKEN' are in scope", async () => { | ||
process.env = { | ||
CLOUDFLARE_API_TOKEN: "hunter2", | ||
CLOUDFLARE_ACCOUNT_ID: "IG-88", | ||
}; | ||
|
||
await runWrangler().catch((err) => { | ||
expect(err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); | ||
|
||
it("should throw an error in CI if 'account_id' & 'CLOUDFLARE_ACCOUNT_ID' is missing", async () => { | ||
writeWranglerToml({ | ||
account_id: undefined, | ||
}); | ||
|
||
process.env = { | ||
CLOUDFLARE_API_TOKEN: "hunter2", | ||
CLOUDFLARE_ACCOUNT_ID: undefined, | ||
}; | ||
|
||
await runWrangler().catch((err) => { | ||
expect(err).toMatchInlineSnapshot( | ||
`[Error: Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" from CI environment, one is required, please see docs for more info: TBD]` | ||
); | ||
}); | ||
}); | ||
|
||
it("should throw error in CI if 'CLOUDFLARE_API_TOKEN' is missing", async () => { | ||
writeWranglerToml({ | ||
account_id: undefined, | ||
}); | ||
|
||
process.env = { | ||
CLOUDFLARE_API_TOKEN: undefined, | ||
CLOUDFLARE_ACCOUNT_ID: "badwolf", | ||
}; | ||
await runWrangler().catch((err) => { | ||
expect(err).toMatchInlineSnapshot( | ||
`[Error: Missing "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD]` | ||
); | ||
}); | ||
}); | ||
|
||
it("should throw errors in CI if 'CLOUDFLARE_API_TOKEN', 'account_id' & 'CLOUDFLARE_ACCOUNT_ID is missing", async () => { | ||
await runWrangler().catch((err) => { | ||
expect(err).toMatchInlineSnapshot( | ||
`[Error: Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD]` | ||
); | ||
}); | ||
}); | ||
|
||
it("should not throw missing Error in TTY environment", async () => { | ||
process.env = { | ||
...process.env, | ||
CI: "false", | ||
}; | ||
await runWrangler(); | ||
expect(std.err).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); |
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
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