-
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_ACC…
…OUNT_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
0c582be
commit 06f5e6d
Showing
6 changed files
with
137 additions
and
3 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,91 @@ | ||
import ci from "ci-info"; | ||
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"; | ||
|
||
const std = mockConsoleMethods(); | ||
void std; // Keeps the console quiet | ||
runInTempDir(); | ||
|
||
const ENV_COPY = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.mock("ci-info"); | ||
(ci.isCI as jest.Mocked<boolean>) = true; | ||
}); | ||
|
||
afterEach(() => { | ||
process.env = ENV_COPY; | ||
}); | ||
|
||
afterAll(() => { | ||
jest.unmock("ci-info"); | ||
}); | ||
|
||
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]` | ||
); | ||
}); | ||
}); |
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