Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Effect to push NPM releases #134

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
);
};
}