-
Notifications
You must be signed in to change notification settings - Fork 716
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 1adc237
Showing
8 changed files
with
146 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { mockConsoleMethods } from "./helpers/mock-console"; | ||
import { useMockIsTTY } from "./helpers/mock-istty"; | ||
import { runInTempDir } from "./helpers/run-in-tmp"; | ||
import { runWrangler } from "./helpers/run-wrangler"; | ||
import writeWranglerToml from "./helpers/write-wrangler-toml"; | ||
|
||
const ENV_COPY = process.env; | ||
mockConsoleMethods(); | ||
runInTempDir(); | ||
|
||
afterEach(() => { | ||
process.env = ENV_COPY; | ||
}); | ||
|
||
describe("CI", () => { | ||
const { setIsTTY } = useMockIsTTY(); | ||
setIsTTY(false); | ||
|
||
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
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,33 @@ | ||
import { readConfig } from "./config"; | ||
|
||
/** | ||
* Inside a CI/CD environment, you want to check if all the required variables are in scope | ||
* and if not, throw a helpful error message with missing variables and documentation link. | ||
*/ | ||
export function ciCheck() { | ||
if (process.stdout.isTTY) { | ||
const config = readConfig(undefined, {}); | ||
|
||
if ( | ||
!process.env.CLOUDFLARE_API_TOKEN && | ||
!config.account_id && | ||
!process.env.CLOUDFLARE_ACCOUNT_ID | ||
) { | ||
throw new Error( | ||
`Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD` | ||
); | ||
} | ||
|
||
if (!process.env.CLOUDFLARE_API_TOKEN) { | ||
throw new Error( | ||
`Missing "CLOUDFLARE_API_TOKEN" from CI environment, please see docs for more info: TBD` | ||
); | ||
} | ||
|
||
if (!config.account_id && !process.env.CLOUDFLARE_ACCOUNT_ID) { | ||
throw new Error( | ||
`Missing "account_id" from "wrangler.toml" and "CLOUDFLARE_ACCOUNT_ID" from CI environment, one is required, 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