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