Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
aciceri committed May 16, 2023
1 parent 15ff4f6 commit ed30223
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
./flake-modules/herculesCI-helpers.nix
./flake-modules/github-pages.nix
./flake-modules/github-releases
./flake-modules/npm-release
./effects/flake-update/flake-module.nix
];
}
81 changes: 81 additions & 0 deletions flake-modules/npm-release/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{ config, lib, options, withSystem, ... }:
let
inherit (lib) mkOption mkOptionType types;
in
{
options =
{
hercules-ci.npm-release = {
condition = mkOption {
type = types.functionTo types.bool;
description = ''
Condition under which a release is going to be pushed.
This is a function accepting [HerculesCI parameters](https://docs.hercules-ci.com/hercules-ci-agent/evaluation#params-herculesCI)
and returning boolean.
By default, pushing happens if a tag is present.
'';
default = { tag, ... }: tag != null;
defaultText = lib.literalExpression ''
{ tag, ... }: tag != null
'';
};
package = mkOption {
type = types.package;
default = null;
description = ''
Path or derivation which produces a path containing what is going to be pushed.
Must contain a `package.json` file which specifies in a `files` field what files
are going to be pushed.
'';
};
};
};

config =
let
inherit (lib) mkIf mkMerge;
inherit (config) defaultEffectSystem;

cfg = config.hercules-ci.npm-release;
opt = options.hercules-ci.npm-release;
enable = cfg.package != null;
in
{
herculesCI = mkIf enable (herculesCI@{ config, ... }:
let
npm-publish-script = pkgs: pkgs.writeShellApplication {
name = "npm-publish";
runtimeInputs = with pkgs; [ nodePackages.npm ];
text = ''
cd ${cfg.package}
export NODE_AUTH_TOKEN=$token
echo here
echo "$NODE_AUTH_TOKEN"
npm publish
'';
};
deploy = withSystem defaultEffectSystem ({ hci-effects, pkgs, ... }:
hci-effects.modularEffect {
imports = [
../../effects/modules/git-auth-gh.nix
];
secretsMap = {
token = { type = "GitToken"; };
};
git.checkout = {
remote.url = config.repo.remoteHttpUrl;
forgeType = config.repo.forgeType;
};
effectScript = lib.getExe (npm-publish-script pkgs);
}
);
in
{
onPush.default.outputs.effects.npm-release =
lib.optionalAttrs
(cfg.condition herculesCI.config.repo)
deploy;
}
);
};
}

0 comments on commit ed30223

Please sign in to comment.