Skip to content

Commit 4bbd03b

Browse files
committed
add github action to build packages
<!-- ps-id: a0d6b308-c571-44e8-996f-b3a0d4843833 -->
1 parent 9135609 commit 4bbd03b

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: "Build packages"
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
packages:
6+
description: "Comma-separated attributes to build"
7+
type: string
8+
jobs:
9+
test:
10+
strategy:
11+
matrix:
12+
os:
13+
- ubuntu-latest
14+
- macos-latest
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- name: Check out the PR at the test merge commit
18+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
19+
- name: Install Nix
20+
uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
21+
22+
- name: Build package
23+
run: |
24+
nix build -L --impure --expr '{ packages }:
25+
let
26+
pkgs = import ./. {
27+
config = {
28+
allowUnfree = true;
29+
allowInsecurePredicate = x: true;
30+
allowAliases = false;
31+
};
32+
};
33+
lib = pkgs.lib;
34+
packageList = lib.strings.splitString "," packages;
35+
packageAttrs = map (package: lib.splitString "." package) packageList;
36+
pkgsAndTests = map (packageAttr:
37+
let
38+
pkg = lib.attrByPath packageAttr null pkgs;
39+
tests = lib.attrByPath (packageAttr ++ ["tests"]) null pkgs;
40+
evalResult = builtins.tryEval "${pkg}";
41+
in if evalResult.success then [ pkg tests ] else []
42+
) packageAttrs;
43+
in pkgsAndTests' --argstr packages '${{ inputs.packages }}'
44+
45+
- name: Post build status comment if part of a pull request
46+
uses: actions/github-script@4020e461acd7a80762cdfff123a1fde368246fa4
47+
with:
48+
script: |
49+
const { context, github } = require('@actions/github');
50+
const branch = context.ref.replace('refs/heads/', '');
51+
const { data: pulls } = await github.rest.pulls.list({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
head: `${context.repo.owner}:${branch}`
55+
});
56+
const pr = pulls.length > 0 ? pulls[0] : null;
57+
if (pr) {
58+
const status = context.payload.workflow_run.conclusion;
59+
const run_id = context.runId;
60+
const repo = context.repo.repo;
61+
const owner = context.repo.owner;
62+
const build_url = `https://github.com/${owner}/${repo}/actions/runs/${run_id}`;
63+
const packages = context.payload.inputs.packages;
64+
const os = context.runner.os;
65+
const comment = `Build status: ${status}\nOS: ${os}\nPackages: ${packages}\n[Build logs](${build_url})`;
66+
const issue_number = pr.number;
67+
await github.rest.issues.createComment({
68+
owner,
69+
repo,
70+
issue_number,
71+
body: comment
72+
});
73+
}

0 commit comments

Comments
 (0)