|
| 1 | +{ config, lib, withSystem, ... }: |
| 2 | +let |
| 3 | + inherit (lib) mkOption types optionalAttrs mapAttrs; |
| 4 | + cfg = config.hercules-ci.netlify-deploy; |
| 5 | +in |
| 6 | +{ |
| 7 | + options.hercules-ci.netlify-deploy = mkOption { |
| 8 | + type = (types.attrsOf types.submodule { |
| 9 | + options = { |
| 10 | + enable = lib.mkEnableOption "On-push deployment to Netlify"; |
| 11 | + |
| 12 | + siteId = mkOption { |
| 13 | + type = types.str; |
| 14 | + description = '' |
| 15 | + An opaque identifier assigned by Netlify to the website you wish to deploy. |
| 16 | + See [docs.hercules-ci.com](https://docs.hercules-ci.com/hercules-ci-effects/reference/nix-functions/netlifydeploy/#param-name) on how to get the right siteId for your website from Netlify. |
| 17 | + ''; |
| 18 | + }; |
| 19 | + |
| 20 | + secretName = mkOption { |
| 21 | + type = types.str; |
| 22 | + description = '' |
| 23 | + The secret that will be looked up in [secrets.json](https://docs.hercules-ci.com/hercules-ci-agent/secrets-json). |
| 24 | + This secret must hold the `secretField` field, ith a string value that is a Netlify personal access token. |
| 25 | + ''; |
| 26 | + }; |
| 27 | + |
| 28 | + secretField = mkOption { |
| 29 | + type = types.str; |
| 30 | + default = "token"; |
| 31 | + description = "The name of the field inside the `secretName` secret which holds the Netlify personal access token."; |
| 32 | + }; |
| 33 | + |
| 34 | + content = mkOption { |
| 35 | + type = types.str; |
| 36 | + description = '' |
| 37 | + Path to the site content, also known as the Publish directory. |
| 38 | + This includes files such as netlify.toml, _redirects, and all web resources, like index.html, style sheets, etc. |
| 39 | + You will typically put a derivation here. |
| 40 | + ''; |
| 41 | + }; |
| 42 | + |
| 43 | + productionDeployment = mkOption { |
| 44 | + type = types.bool; |
| 45 | + default = false; |
| 46 | + description = "Whether this should be production deployment."; |
| 47 | + }; |
| 48 | + |
| 49 | + extraDeployArgs = mkOption { |
| 50 | + type = (types.listOf types.str); |
| 51 | + default = [ ]; |
| 52 | + description = "Extra arguments to pass to the netlify deploy invocation."; |
| 53 | + }; |
| 54 | + }; |
| 55 | + }); |
| 56 | + }; |
| 57 | + |
| 58 | + config = { |
| 59 | + herculesCI.onPush.default.outputs.effects = { |
| 60 | + netlify-deploy = mapAttrs |
| 61 | + (name: siteCfg: optionalAttrs (siteCfg.enable) withSystem config.defaultEffectSystem ({ hci-effects, ... }: |
| 62 | + hci-effects.netlifyDeploy { inherit (siteCfg) siteId secretName secretField content productionDeployment extraDeployArgs; } |
| 63 | + )) |
| 64 | + cfg; |
| 65 | + }; |
| 66 | + }; |
| 67 | +} |
0 commit comments