forked from NixOS/nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
73 additions
and
0 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
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 | ||
}); | ||
} |