feat: Improve build pipeline (#78)

This pull request enhances the `.github/workflows/update-flake.yaml`
file by adding new features and improving the build and validation
process. The key changes include allowing manual triggering, adding a
matrix strategy to run jobs on multiple operating systems, and
implementing steps to handle build and check failures by creating issues
automatically.

Enhancements to build and validation process:

*
[`.github/workflows/update-flake.yaml`](diffhunk://#diff-4a139fc25db101424a99bb7668e55ce5a6a6f32aa9a3ed5838b638a3d14e4a4cR1-R68):
Added `workflow_dispatch` to allow manual triggering of the workflow.
*
[`.github/workflows/update-flake.yaml`](diffhunk://#diff-4a139fc25db101424a99bb7668e55ce5a6a6f32aa9a3ed5838b638a3d14e4a4cR1-R68):
Introduced a matrix strategy to run jobs on both `ubuntu-latest` and
`macos-latest`, and included `fail-fast: false` to continue with other
jobs even if one fails.
*
[`.github/workflows/update-flake.yaml`](diffhunk://#diff-4a139fc25db101424a99bb7668e55ce5a6a6f32aa9a3ed5838b638a3d14e4a4cR1-R68):
Added a step to build and test the configuration, capturing the output
and setting the build status in the environment variables.
*
[`.github/workflows/update-flake.yaml`](diffhunk://#diff-4a139fc25db101424a99bb7668e55ce5a6a6f32aa9a3ed5838b638a3d14e4a4cR1-R68):
Implemented a step to create an issue on build failure, using
`actions/github-script@v7` to post the build output in the issue
description.
*
[`.github/workflows/update-flake.yaml`](diffhunk://#diff-4a139fc25db101424a99bb7668e55ce5a6a6f32aa9a3ed5838b638a3d14e4a4cR77-R120):
Added steps to run checks and create an issue on check failure, similar
to the build failure handling.
This commit is contained in:
Roel de Cort 2025-03-07 12:14:43 +01:00 committed by GitHub
parent 7090b197a7
commit e7b86939a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,18 +1,71 @@
name: Update Flake and Validate Build
on:
schedule:
- cron: "30 00 * * 1"
workflow_dispatch: # Allow manual triggering
jobs:
lockfile:
runs-on: ubuntu-latest
build-and-update:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: false # Continue with other jobs even if one fails
runs-on: ${{ matrix.os }}
steps:
- name: Repository Checkout
uses: actions/checkout@v4
- name: Instal Nix
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v16
- name: Build and Test Configuration
id: build
continue-on-error: true # Continue to next steps even if build fails
run: |
# Run the build and capture output
OUTPUT=$(nix build .# 2>&1)
echo "build_output<<EOF" >> $GITHUB_ENV
echo "$OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Check if build succeeded
if [ $? -eq 0 ]; then
echo "build_status=success" >> $GITHUB_ENV
else
echo "build_status=failure" >> $GITHUB_ENV
fi
- name: Create Issue on Build Failure
if: env.build_status == 'failure'
uses: actions/github-script@v7
with:
script: |
const os = '${{ matrix.os }}';
const buildOutput = process.env.build_output;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.name,
title: `🔨 Build Failed on ${os}`,
body: `Build failed during automated validation on ${os}.
<details>
<summary>Build Output</summary>
\`\`\`
${buildOutput}
\`\`\`
</details>
Please review the build output and fix any issues.`,
labels: ['build-failure', 'bug']
});
- name: Update flake.lock
if: matrix.os == 'ubuntu-latest' && env.build_status == 'success'
uses: DeterminateSystems/update-flake-lock@v24
with:
nix-options: --debug --log-format raw
@ -21,3 +74,47 @@ jobs:
pr-labels: |
dependencies
automated
- name: Run Checks
id: checks
if: env.build_status == 'success'
continue-on-error: true
run: |
# Run the checks and capture output
OUTPUT=$(nix flake check 2>&1)
echo "check_output<<EOF" >> $GITHUB_ENV
echo "$OUTPUT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# Check if checks succeeded
if [ $? -eq 0 ]; then
echo "check_status=success" >> $GITHUB_ENV
else
echo "check_status=failure" >> $GITHUB_ENV
fi
- name: Create Issue on Check Failure
if: env.check_status == 'failure'
uses: actions/github-script@v7
with:
script: |
const os = '${{ matrix.os }}';
const checkOutput = process.env.check_output;
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.name,
title: `⚠️ Checks Failed on ${os}`,
body: `Checks failed during automated validation on ${os}.
<details>
<summary>Check Output</summary>
\`\`\`
${checkOutput}
\`\`\`
</details>
Please review the check output and fix any issues.`,
labels: ['check-failure', 'bug']
});