-
-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (56 loc) · 2.76 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Based on:
# https://github.com/cuties-social/cuties-social-nixfiles/blob/14593a3014c32ce121529009d8d6564e45dd7e99/.github/workflows/build.yml
name: Build
on:
pull_request:
workflow_dispatch:
defaults:
run:
shell: bash -euo pipefail {0}
jobs:
build:
env:
HOST: framework
PR_JOB_SUMMARY: pr-job-summary
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e # v9
- name: Set up cache
uses: DeterminateSystems/magic-nix-cache-action@8a218f9e264e9c3803c9a1ee1c30d8e4ab55be63 # v2
- name: Run flake check
run: |
CHECK_OUTPUT="${RUNNER_TEMP}/flake-check-output"
nix flake check --no-build | tee "$CHECK_OUTPUT"
[[ -s $CHECK_OUTPUT ]] || echo "No issues found by 'nix flake check'." > "$CHECK_OUTPUT"
echo -e "## Flake check\n\`\`\`\n$(<$CHECK_OUTPUT)\n\`\`\`" | tee -a "$GITHUB_STEP_SUMMARY" "${RUNNER_TEMP}/${PR_JOB_SUMMARY}" >/dev/null
- name: Build
run: |
OUT_PATH="$(nix build .#nixosConfigurations.${HOST}.config.system.build.toplevel --print-out-paths)"
echo -e "\x1b[32;1mSuccessfully built .#nixosConfigurations.${HOST}\x1b[0m"
echo -e "## Build ${HOST}\n\`$OUT_PATH\`" | tee -a "$GITHUB_STEP_SUMMARY" "${RUNNER_TEMP}/${PR_JOB_SUMMARY}" >/dev/null
- name: Diff closures
if: github.event_name == 'pull_request'
run: |
HOST_DRV="nixosConfigurations.${HOST}.config.system.build.toplevel"
PREV_FLAKE="github:${GITHUB_REPOSITORY}"
NEXT_FLAKE="."
DIFF_OUTPUT="${RUNNER_TEMP}/nix-store-diff-closures-output"
nix store diff-closures "${PREV_FLAKE}#${HOST_DRV}" "${NEXT_FLAKE}#${HOST_DRV}" | tee "$DIFF_OUTPUT"
[[ -s "$DIFF_OUTPUT" ]] && sed -i 's/\x1b\[[0-9;]*m//g' "$DIFF_OUTPUT" || echo "No changes found" | tee "$DIFF_OUTPUT"
echo -e "## Closures difference\n\`\`\`\n$(<$DIFF_OUTPUT)\n\`\`\`" | tee -a "$GITHUB_STEP_SUMMARY" "${RUNNER_TEMP}/${PR_JOB_SUMMARY}" >/dev/null
- name: Add job summary to PR
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: github.event_name == 'pull_request'
with:
script: |
const { readFile } = require('node:fs/promises')
const comment = require('.github/scripts/comment')
const header = '# ${{ env.HOST }}'
const body = await readFile('${{ runner.temp }}/${{ env.PR_JOB_SUMMARY }}', { encoding: 'utf8' })
await comment({ github, context, header, body })