-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd11320
commit 847e216
Showing
12 changed files
with
243 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
inputs: let | ||
utils = import ./utils.nix inputs; | ||
x = utils.importer "lib" [ | ||
./github | ||
./mkAction.nix | ||
./mkGitJobsets.nix | ||
./mkProject.nix | ||
./systems.nix | ||
] | ||
x; | ||
in | ||
x.lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
utils: | ||
utils.importer "github" [ | ||
./mkGithubJobsets.nix | ||
./mkGithubProject.nix | ||
./mkGithubStatus.nix | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
utils: {lib}: let | ||
inherit | ||
(lib) | ||
mkAction | ||
; | ||
in { | ||
mkGithubJobsets = { | ||
owner, | ||
repo, | ||
}: | ||
mkAction (system: let | ||
pkgs = utils.pkgs.${system}; | ||
in | ||
pkgs.writeShellApplication { | ||
name = "action"; | ||
runtimeInputs = [ | ||
pkgs.curl | ||
pkgs.gnused | ||
pkgs.jq | ||
]; | ||
text = '' | ||
input=$(cat) | ||
token=$(echo "$input" | jq '.secrets.github_token' -r) | ||
curl -s \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $token" \ | ||
https://api.github.com/repos/${owner}/${repo}/branches \ | ||
-k \ | ||
| jq --arg o "${owner}" --arg r "${repo}" 'map({ key: .name, value: { "flake": ("github:" + $o + "/" + $r + "/" + .name) }}) | from_entries' | ||
''; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
_: {lib}: let | ||
inherit | ||
(lib) | ||
mkProject | ||
; | ||
inherit | ||
(lib.github) | ||
mkGithubJobsets | ||
mkGithubStatus | ||
; | ||
in { | ||
mkGithubProject = { | ||
owner, | ||
repo, | ||
secrets, | ||
title ? repo, | ||
description ? "", | ||
homepage ? "https://github.com/${owner}/${repo}", | ||
}: | ||
mkProject { | ||
meta = {inherit title description homepage;}; | ||
actions = { | ||
jobsets = mkGithubJobsets {inherit owner repo;}; | ||
begin = mkGithubStatus {inherit owner repo;}; | ||
end = mkGithubStatus {inherit owner repo;}; | ||
}; | ||
inherit secrets; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
utils: {lib}: let | ||
inherit | ||
(lib) | ||
mkAction | ||
; | ||
in { | ||
mkGithubStatus = { | ||
owner, | ||
repo, | ||
}: | ||
mkAction (system: let | ||
pkgs = utils.pkgs.${system}; | ||
in | ||
pkgs.writeShellApplication { | ||
name = "action"; | ||
runtimeInputs = [ | ||
pkgs.curl | ||
pkgs.gnused | ||
pkgs.jq | ||
]; | ||
text = '' | ||
input=$(cat) | ||
build=$(echo "$input" | jq '.input.build' -r) | ||
data=$(echo "$input" | jq '.input.data' -r) | ||
evaluation=$(echo "$input" | jq '.input.evaluation' -r) | ||
flake_locked=$(echo "$input" | jq '.input.flake_locked' -r) | ||
job=$(echo "$input" | jq '.input.job' -r) | ||
jobset=$(echo "$input" | jq '.input.jobset' -r) | ||
project=$(echo "$input" | jq '.input.project' -r) | ||
status=$(echo "$input" | jq '.input.status' -r) | ||
token=$(echo "$input" | jq '.secrets.github_token' -r) | ||
rev=$(echo "$flake_locked" | sed 's/github:.*\/.*\/\(.*\)/\1/') | ||
target_url="$(echo "$data" | jq '.url' -r)/builds/$build" | ||
context="Typhon: $job" | ||
description="$project:$jobset:$evaluation:$job" | ||
case $status in | ||
"error") | ||
state="failure" | ||
;; | ||
"pending") | ||
state="pending" | ||
;; | ||
"success") | ||
state="success" | ||
;; | ||
*) | ||
state="error" | ||
;; | ||
esac | ||
curl -s \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $token" \ | ||
"https://api.github.com/repos/${owner}/${repo}/statuses/$rev" \ | ||
-d "{\"state\":\"$state\",\"target_url\":\"$target_url\",\"description\":\"$description\",\"context\":\"$context\"}" \ | ||
-k >&2 | ||
''; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
utils: {lib}: let | ||
inherit | ||
(lib) | ||
systems | ||
; | ||
in { | ||
mkAction = utils.lib.genAttrs systems; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
utils: {lib}: let | ||
inherit | ||
(lib) | ||
mkAction | ||
; | ||
in { | ||
mkGitJobsets = url: | ||
mkAction (system: let | ||
pkgs = utils.pkgs.${system}; | ||
in | ||
pkgs.writeShellApplication { | ||
name = "action"; | ||
runtimeInputs = [ | ||
pkgs.git | ||
pkgs.gnused | ||
pkgs.jq | ||
]; | ||
text = '' | ||
heads=$(git ls-remote --heads ${url} | sed 's/.*refs\/heads\/\(.*\)/\1/') | ||
cmd="" | ||
for head in $heads | ||
do | ||
cmd="$cmd . += {\"$head\": { \"flake\": \"git+${url}?ref=$head\" } } |" | ||
done | ||
array=$(echo "{}" | jq "$cmd .") | ||
echo "$array" | ||
''; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
utils: {lib}: let | ||
inherit | ||
(lib) | ||
systems | ||
; | ||
in { | ||
mkProject = args @ { | ||
actions ? {}, | ||
meta ? {}, | ||
secrets ? null, | ||
}: { | ||
inherit meta; | ||
actions = utils.lib.genAttrs systems ( | ||
system: let | ||
pkgs = utils.pkgs.${system}; | ||
linkAction = name: | ||
if actions ? ${name} && actions.${name} ? ${system} | ||
then "ln -s ${actions.${name}.${system}}/bin/action ${name}" | ||
else ""; | ||
linkSecrets = | ||
if secrets != null | ||
then "ln -s ${secrets} secrets" | ||
else ""; | ||
in | ||
pkgs.runCommand "actions" {} '' | ||
mkdir $out | ||
cd $out | ||
${linkAction "jobsets"} | ||
${linkAction "begin"} | ||
${linkAction "end"} | ||
${linkSecrets} | ||
'' | ||
); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
utils: _: { | ||
systems = utils.inputs.flake-utils.lib.defaultSystems; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
inputs @ {nixpkgs, ...}: let | ||
self = rec { | ||
inherit inputs; | ||
|
||
lib = nixpkgs.lib; | ||
|
||
pkgs = nixpkgs.legacyPackages; | ||
|
||
importer = scope: | ||
lib.foldr | ||
(file: fn: lib: | ||
self.lib.recursiveUpdate | ||
{${scope} = import file self lib;} | ||
(fn lib)) | ||
(_: {}); | ||
}; | ||
in | ||
self |