From e7b86939a85464dbd808ef87c4da08154c5c71e5 Mon Sep 17 00:00:00 2001 From: Roel de Cort <63876068+dc-tec@users.noreply.github.com> Date: Fri, 7 Mar 2025 12:14:43 +0100 Subject: [PATCH] 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. --- .github/workflows/update-flake.yaml | 103 +++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-flake.yaml b/.github/workflows/update-flake.yaml index 02cdffb..9f64121 100644 --- a/.github/workflows/update-flake.yaml +++ b/.github/workflows/update-flake.yaml @@ -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<> $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}. + +
+ Build Output + + \`\`\` + ${buildOutput} + \`\`\` +
+ + 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<> $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}. + +
+ Check Output + + \`\`\` + ${checkOutput} + \`\`\` +
+ + Please review the check output and fix any issues.`, + labels: ['check-failure', 'bug'] + });