|  | 
| 1 | 1 | --- | 
| 2 |  | -name: "Flake.lock: update Nix dependencies" | 
|  | 2 | +name: "Flake.lock: update Nix dependencies (Verified)" | 
| 3 | 3 | on: | 
| 4 | 4 |   workflow_dispatch: # allows manual triggering | 
| 5 | 5 |   schedule: | 
| 6 |  | -    - cron: "0 0 * * 0" # runs weekly on Sunday at 00:00 | 
|  | 6 | +    - cron: 0 0 * * 0 # runs weekly on Sunday at 00:00 | 
|  | 7 | + | 
|  | 8 | +env: | 
|  | 9 | +  BRANCH: "main" | 
|  | 10 | +  COMMIT_MESSAGE: "chore(lockfile): auto update flake.lock" | 
|  | 11 | +  GIT_NAME: "github-actions[bot]" | 
|  | 12 | +  GIT_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com" | 
| 7 | 13 | 
 | 
| 8 | 14 | jobs: | 
| 9 | 15 |   nix-flake-update: | 
| 10 | 16 |     permissions: | 
| 11 | 17 |       contents: write | 
| 12 | 18 |       id-token: write | 
| 13 | 19 |     runs-on: ubuntu-latest | 
|  | 20 | + | 
| 14 | 21 |     steps: | 
| 15 | 22 |       - name: Checkout repository | 
| 16 | 23 |         uses: actions/checkout@v5 | 
|  | 24 | + | 
| 17 | 25 |       - name: Install Nix | 
| 18 | 26 |         uses: DeterminateSystems/determinate-nix-action@v3 | 
|  | 27 | + | 
| 19 | 28 |       - name: Check Nix flake inputs | 
| 20 | 29 |         uses: DeterminateSystems/flake-checker-action@v12 | 
| 21 | 30 |         with: | 
| 22 | 31 |           ignore-missing-flake-lock: false | 
| 23 | 32 |           fail-mode: true | 
|  | 33 | + | 
| 24 | 34 |       - name: Update flake.lock | 
| 25 | 35 |         run: | | 
| 26 | 36 |           nix flake update | 
| 27 |  | -      - uses: stefanzweifel/git-auto-commit-action@v7 | 
|  | 37 | +
 | 
|  | 38 | +      - name: Detect modified files | 
|  | 39 | +        id: diff | 
|  | 40 | +        shell: bash | 
|  | 41 | +        run: | | 
|  | 42 | +          set -euo pipefail | 
|  | 43 | +          # List modified (tracked) files relative to HEAD. | 
|  | 44 | +          # If you only want specific patterns, add a grep here (e.g., grep -E '(^|/)flake\.lock$'). | 
|  | 45 | +          mapfile -t changed < <(git ls-files -m --full-name) | 
|  | 46 | +
 | 
|  | 47 | +          if [ "${#changed[@]}" -eq 0 ]; then | 
|  | 48 | +            echo "changed=false" >> "$GITHUB_OUTPUT" | 
|  | 49 | +            echo "changed_files=" >> "$GITHUB_OUTPUT" | 
|  | 50 | +            exit 0 | 
|  | 51 | +          fi | 
|  | 52 | +
 | 
|  | 53 | +          # Join into a comma-separated string for downstream steps. | 
|  | 54 | +          IFS=',' read -r -a _ <<< "" | 
|  | 55 | +          changed_csv="$(printf "%s," "${changed[@]}")" | 
|  | 56 | +          changed_csv="${changed_csv%,}" | 
|  | 57 | +
 | 
|  | 58 | +          echo "Changed files:" | 
|  | 59 | +          printf ' - %s\n' "${changed[@]}" | 
|  | 60 | +
 | 
|  | 61 | +          echo "changed=true" >> "$GITHUB_OUTPUT" | 
|  | 62 | +          echo "changed_files=${changed_csv}" >> "$GITHUB_OUTPUT" | 
|  | 63 | +
 | 
|  | 64 | +      - name: Commit via REST Contents API (server-signed → Verified) | 
|  | 65 | +        if: steps.diff.outputs.changed == 'true' | 
|  | 66 | +        uses: actions/github-script@v8 | 
|  | 67 | +        env: | 
|  | 68 | +          CHANGED_FILES: ${{ steps.diff.outputs.changed_files }} | 
| 28 | 69 |         with: | 
| 29 |  | -          commit_message: "chore(lockfile): auto update flake.lock" | 
| 30 |  | -          commit_user_name: "github-actions[bot]" | 
| 31 |  | -          commit_user_email: "32497323+github-actions[bot]@users.noreply.github.com" | 
| 32 |  | -          commit_author: "github-actions[bot] <32497323+github-actions[bot]@users.noreply.github.com>" | 
| 33 |  | -          file_pattern: "flake.lock" | 
|  | 70 | +          script: | | 
|  | 71 | +            const fs = require('fs'); | 
|  | 72 | +            const owner   = context.repo.owner; | 
|  | 73 | +            const repo    = context.repo.repo; | 
|  | 74 | +            const branch  = process.env.BRANCH; | 
|  | 75 | +            const message = process.env.COMMIT_MESSAGE; | 
|  | 76 | +
 | 
|  | 77 | +            const files = (process.env.CHANGED_FILES || '') | 
|  | 78 | +              .split(',') | 
|  | 79 | +              .map(s => s.trim()) | 
|  | 80 | +              .filter(Boolean); | 
|  | 81 | +
 | 
|  | 82 | +            for (const path of files) { | 
|  | 83 | +              const content = fs.readFileSync(path, { encoding: 'base64' }); | 
|  | 84 | +
 | 
|  | 85 | +              // Get existing sha if the file already exists | 
|  | 86 | +              let sha; | 
|  | 87 | +              try { | 
|  | 88 | +                const res = await github.rest.repos.getContent({ owner, repo, path, ref: branch }); | 
|  | 89 | +                if (!Array.isArray(res.data)) sha = res.data.sha; | 
|  | 90 | +              } catch (e) { | 
|  | 91 | +                if (e.status !== 404) throw e; | 
|  | 92 | +              } | 
|  | 93 | +
 | 
|  | 94 | +              // NOTE: author/committer intentionally omitted to allow platform signing | 
|  | 95 | +              const r = await github.rest.repos.createOrUpdateFileContents({ | 
|  | 96 | +                owner, repo, path, branch, | 
|  | 97 | +                message, | 
|  | 98 | +                content, | 
|  | 99 | +                sha | 
|  | 100 | +              }); | 
|  | 101 | +              core.info(`Committed ${path}: ${r.data.commit.sha}`); | 
|  | 102 | +            } | 
0 commit comments