Skip to content

Commit

Permalink
react to comment and find revision in task
Browse files Browse the repository at this point in the history
  • Loading branch information
Pacman99 committed Nov 30, 2022
1 parent 637177e commit b91f65a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 71 deletions.
3 changes: 1 addition & 2 deletions nix/cells/automation/library/plutus-benchmark-runner.nix
@@ -1,6 +1,6 @@
{ cell, inputs }:

{ PR_NUMBER, PR_COMMIT_SHA, BENCHMARK_NAME, GITHUB_TOKEN }:
{ PR_NUMBER, BENCHMARK_NAME, GITHUB_TOKEN }:

let
inherit (inputs.cells.plutus.library) pkgs;
Expand All @@ -19,7 +19,6 @@ pkgs.writeShellApplication {
];
text = ''
PR_NUMBER=${PR_NUMBER} \
PR_COMMIT_SHA=${PR_COMMIT_SHA} \
BENCHMARK_NAME=${BENCHMARK_NAME} \
GITHUB_TOKEN=${GITHUB_TOKEN} \
${./plutus-benchmark-runner.sh}
Expand Down
6 changes: 1 addition & 5 deletions nix/cells/automation/library/plutus-benchmark-runner.sh
Expand Up @@ -24,16 +24,12 @@ if [ -z "$PR_NUMBER" ] ; then
echo "[ci-plutus-benchmark]: 'PR_NUMBER' is not set! Exiting"
exit 1
fi
if [ -z "$PR_COMMIT_SHA" ] ; then
echo "[ci-plutus-benchmark]: 'PR_COMMIT_SHA' is not set! Exiting"
exit 1
fi
if [ -z "$BENCHMARK_NAME" ] ; then
echo "[ci-plutus-benchmark]: 'BENCHMARK_NAME' is not set! Exiting"
exit 1
fi

PR_BRANCH_REF=$(git rev-parse --short $PR_COMMIT_SHA)
PR_BRANCH_REF=$(git rev-parse --short HEAD)

echo "[ci-plutus-benchmark]: Processing benchmark comparison for benchmark '$BENCHMARK_NAME' on PR $PR_NUMBER"

Expand Down
25 changes: 15 additions & 10 deletions nix/cells/automation/pipelines.nix
Expand Up @@ -8,6 +8,8 @@
let
inherit (inputs.nixpkgs) lib system;
inherit (inputs.cells) cloud;
inherit (inputs.cells.plutus) library;
inherit (library) pkgs;

common =
{ config
Expand Down Expand Up @@ -46,27 +48,30 @@ in

benchmark = { config, ... }:
let
# Facts here correspond to inputs created by the benchmark action in the cloud cell
facts = config.actionRun.facts;
commentFact = facts.${cloud.library.actions.benchmark.commentInput}.value.github_body;
prFact = facts.${cloud.library.actions.benchmark.prInput}.value.github_body;
fact = config.actionRun.facts.${cloud.library.actions.benchmark.input}.value.github_body;
prNumber = toString fact.issue.number;

prRevision = prFact.pull_request.head.sha;
prRevision = lib.getExe (pkgs.writeScript "get-pr-rev" ''
curl \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/input-output-hk/plutus/pulls/${prNumber} \
| jq -r .base.sha
'');

runner = cell.library.plutus-benchmark-runner {
PR_NUMBER = toString prFact.pull_request.number;
PR_COMMIT_SHA = prRevision;
BENCHMARK_NAME = lib.removePrefix "/benchmark " commentFact.comment.body;
PR_NUMBER = prNumber;
BENCHMARK_NAME = lib.removePrefix "/benchmark " fact.comment.body;
GITHUB_TOKEN = "/secrets/cicero/github/token";
};
in
{
# Not importing common, github preset is not needed here
# Not importing commn module defined above, because we don't need the github preset
preset.nix.enable = true;
preset.git.clone = {
enable = true;
remote = "https://github.com/input-output-hk/plutus";
ref = prRevision;
# Tullia has some magic to get the revision when given a script like this
ref.outPath = prRevision;
};
command.text = "${runner}/bin/plutus-benchmark-runner";
nomad.templates = [
Expand Down
58 changes: 6 additions & 52 deletions nix/cells/cloud/actions.nix
@@ -1,7 +1,7 @@
{ cell
, inputs
}: {
/* "plutus/ci" = {
"plutus/ci" = {
task = "ci";
io = ''
// This is a CUE expression that defines what events trigger a new run of this action.
Expand All @@ -18,66 +18,20 @@
{ #lib.io.github_pr, github, #target_default: false },
]
'';
};*/
};

"plutus/benchmark" = {
task = "benchmark";
io = ''
// Two inputs need to match: PR sync event & issue comment creation event
// WIP: Currently inlining lib.io.github_pr_comment
// #lib.io.github_pr_comment &
//
{
#input: string | *"GitHub PR comment to \(#repo)"
#prInput: string | *"GitHub PR to \(#repo)"
#repo: =~"^[^/]+/[^/]+$"
#comment: string
_prRepo: #repo
let pr = {
#lib.io.github_pr
#input: #prInput
#repo: _prRepo
inputs: _final_inputs
}
_final_inputs: inputs
inputs: {
pr.inputs
"\(#input)": match: {
github_event: "issue_comment"
github_body: {
action: "created"
repository: full_name: #repo
issue: pull_request: {}
comment: body: =~#comment
}
}
}
let _body = inputs["\(#input)"].value.github_body
_repo: _body.repository.full_name
_comment: _body.comment.body
_number: _body.issue.number
#target: "zeme-iohk/benchmarking"
#input: "${cell.library.actions.benchmark.commentInput}"
#prInput: "${cell.library.actions.benchmark.prInput}"
#lib.io.github_pr_comment & {
#input: "${cell.library.actions.benchmark.input}"
#repo: "input-output-hk/plutus"
#comment: "^/benchmark .+"
}
'';
};

/*"plutus/publish-documents" = {
"plutus/publish-documents" = {
task = "publish-documents";
io = ''
let push = {
Expand All @@ -97,6 +51,6 @@
}
}
'';
};*/
};

}
3 changes: 1 addition & 2 deletions nix/cells/cloud/library.nix
Expand Up @@ -3,8 +3,7 @@
}: {
actions = {
ci.input = "GitHub event";
benchmark.commentInput = "GitHub comment";
benchmark.prInput = "GitHub pr";
benchmark.input = "GitHub comment";
documents.input = "GitHub push";
};
}

0 comments on commit b91f65a

Please sign in to comment.