Skip to content

Commit

Permalink
add github action to build packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 21, 2024
1 parent 98f05bb commit 3bcaef7
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "Build packages"
on:
workflow_dispatch:
inputs:
packages:
description: "Comma-separated attributes to build"
type: string
jobs:
test:
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- name: Check out the PR at the test merge commit
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Nix
uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30

- name: Build package
run: |
nix build -L --impure --expr '{ packages }:
let
pkgs = import ./. {
config = {
allowUnfree = true;
allowInsecurePredicate = x: true;
allowAliases = false;
};
};
lib = pkgs.lib;
packageList = lib.strings.splitString "," packages;
packageAttrs = map (package: lib.splitString "." package) packageList;
pkgsAndTests = map (packageAttr:
let
pkg = lib.attrByPath packageAttr null pkgs;
tests = lib.attrByPath (packageAttr ++ ["tests"]) null pkgs;
evalResult = builtins.tryEval "${pkg}";
in if evalResult.success then [ pkg tests ] else []
) packageAttrs;
in pkgsAndTests' --argstr packages '${{ inputs.packages }}'
- name: Post build status comment if part of a pull request
uses: actions/github-script@4020e461acd7a80762cdfff123a1fde368246fa4
with:
script: |
const { context, github } = require('@actions/github');
const branch = context.ref.replace('refs/heads/', '');
const { data: pulls } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${branch}`
});
const pr = pulls.length > 0 ? pulls[0] : null;
if (pr) {
const status = context.payload.workflow_run.conclusion;
const run_id = context.runId;
const repo = context.repo.repo;
const owner = context.repo.owner;
const build_url = `https://github.com/${owner}/${repo}/actions/runs/${run_id}`;
const packages = context.payload.inputs.packages;
const os = context.runner.os;
const comment = `Build status: ${status}\nOS: ${os}\nPackages: ${packages}\n[Build logs](${build_url})`;
const issue_number = pr.number;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: comment
});
}

0 comments on commit 3bcaef7

Please sign in to comment.