Pass the Cloudflare account id to wrangler pages deploy explicitly
Pages only honours a discovered wrangler.toml when it declares pages_build_output_dir, which ours can't: the directory differs per language (result/en, result/fr, ...) and is passed positionally. So the account_id in wrangler.toml was read by nobody, and Wrangler fell back to asking the API which accounts the token can see. An account-scoped token lists none - the call succeeds and returns [] - and the deploy died on "Failed to automatically retrieve account IDs", which reads like an expired token but isn't. Source the id from wrangler.toml so it stays the one place it is written down.
73f7684 parent: 4f2eb81 modified
flake.nix +13 -1 | @@ -87,7 +87,7 @@ | ||
| 87 | 87 | type = "app"; |
| 88 | 88 | program = "${pkgs.writeShellApplication { |
| 89 | 89 | name = "mykiwi-blog-deploy"; |
| 90 | - runtimeInputs = [ wrangler pkgs.git ]; | |
| 90 | + runtimeInputs = [ wrangler pkgs.git pkgs.gnused ]; | |
| 91 | 91 | text = '' |
| 92 | 92 | lang="''${1:?usage: nix run .#deploy -- <lang>}" |
| 93 | 93 | root="$(git rev-parse --show-toplevel)" |
| @@ -97,6 +97,18 @@ | ||
| 97 | 97 | # configuration file"), so cd to where wrangler.toml lives and |
| 98 | 98 | # let Wrangler auto-discover it instead. |
| 99 | 99 | cd "$root" |
| 100 | + # ...except Pages only *honours* a discovered wrangler.toml when it | |
| 101 | + # declares pages_build_output_dir, which ours can't: the directory | |
| 102 | + # differs per language (result/en, result/fr, ...) and is passed | |
| 103 | + # positionally below. So the account_id in wrangler.toml is read by | |
| 104 | + # nobody, and Wrangler falls back to asking the API which accounts | |
| 105 | + # the token can see. An account-scoped token lists none - the call | |
| 106 | + # succeeds and returns [] - and the deploy dies on "Failed to | |
| 107 | + # automatically retrieve account IDs", which reads like an expired | |
| 108 | + # token but isn't. Pass the id explicitly, still sourced from | |
| 109 | + # wrangler.toml so it stays the one place it's written down. | |
| 110 | + CLOUDFLARE_ACCOUNT_ID="$(sed -n 's/^account_id *= *"\(.*\)"/\1/p' "$root/wrangler.toml")" | |
| 111 | + export CLOUDFLARE_ACCOUNT_ID | |
| 100 | 112 | wrangler pages deploy "$root/result/$lang" --project-name="$project" --branch=main |
| 101 | 113 | ''; |
| 102 | 114 | }}/bin/mykiwi-blog-deploy"; |
| @@ -87,7 +87,7 @@ | |||
| 87 | type = "app"; | 87 | type = "app"; |
| 88 | program = "${pkgs.writeShellApplication { | 88 | program = "${pkgs.writeShellApplication { |
| 89 | name = "mykiwi-blog-deploy"; | 89 | name = "mykiwi-blog-deploy"; |
| 90 | - runtimeInputs = [ wrangler pkgs.git ]; | 90 | + runtimeInputs = [ wrangler pkgs.git pkgs.gnused ]; |
| 91 | text = '' | 91 | text = '' |
| 92 | lang="''${1:?usage: nix run .#deploy -- <lang>}" | 92 | lang="''${1:?usage: nix run .#deploy -- <lang>}" |
| 93 | root="$(git rev-parse --show-toplevel)" | 93 | root="$(git rev-parse --show-toplevel)" |
| @@ -97,6 +97,18 @@ | |||
| 97 | # configuration file"), so cd to where wrangler.toml lives and | 97 | # configuration file"), so cd to where wrangler.toml lives and |
| 98 | # let Wrangler auto-discover it instead. | 98 | # let Wrangler auto-discover it instead. |
| 99 | cd "$root" | 99 | cd "$root" |
| 100 | + # ...except Pages only *honours* a discovered wrangler.toml when it | ||
| 101 | + # declares pages_build_output_dir, which ours can't: the directory | ||
| 102 | + # differs per language (result/en, result/fr, ...) and is passed | ||
| 103 | + # positionally below. So the account_id in wrangler.toml is read by | ||
| 104 | + # nobody, and Wrangler falls back to asking the API which accounts | ||
| 105 | + # the token can see. An account-scoped token lists none - the call | ||
| 106 | + # succeeds and returns [] - and the deploy dies on "Failed to | ||
| 107 | + # automatically retrieve account IDs", which reads like an expired | ||
| 108 | + # token but isn't. Pass the id explicitly, still sourced from | ||
| 109 | + # wrangler.toml so it stays the one place it's written down. | ||
| 110 | + CLOUDFLARE_ACCOUNT_ID="$(sed -n 's/^account_id *= *"\(.*\)"/\1/p' "$root/wrangler.toml")" | ||
| 111 | + export CLOUDFLARE_ACCOUNT_ID | ||
| 100 | wrangler pages deploy "$root/result/$lang" --project-name="$project" --branch=main | 112 | wrangler pages deploy "$root/result/$lang" --project-name="$project" --branch=main |
| 101 | ''; | 113 | ''; |
| 102 | }}/bin/mykiwi-blog-deploy"; | 114 | }}/bin/mykiwi-blog-deploy"; |