summaryrefslogtreecommitdiff
path: root/.github/workflows/update-lock.yaml
blob: 58ac2c344008e88089fa77c4be4c1e42941dedce (plain)
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
59
60
61
62
63
64
65
66
67
68
name: Update flake.lock

on:
  schedule:
    # run every saturday
    - cron: "0 0 * * 6"
  workflow_dispatch:

jobs:
  update:
    name: Update
    runs-on: ubuntu-latest

    permissions:
      contents: write
      pull-requests: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@1d96c772d19495a3b5c517cd2bc0cb401ea0529f # v4.1.3

      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@de22e16c4711fca50c816cc9081563429d1cf563 # v10

      - name: Set Git user info
        run: |
          git config user.name 'github-actions[bot]'
          git config user.email 'github-actions[bot]@users.noreply.github.com'

      - name: Create new branch
        id: branch
        run: |
          branch="update-flake-lock"

          echo "branch=$branch" >> "$GITHUB_OUTPUT"
          git switch -c "$branch"

      - name: Update flake inputs
        run: |
            nix flake update \
              --commit-lock-file \
              --commit-lockfile-summary "chore: update flake inputs"

      - name: Update test flake inputs
        run: |
          pushd ./test

          nix flake update \
            --commit-lock-file \
            --commit-lockfile-summary "chore: update test flake inputs"

          popd

      - name: Make PR if needed
        env:
          GH_TOKEN: ${{ github.token }}
          BRANCH: ${{ steps.branch.outputs.branch }}
        run: |
          if ! git diff --color=always --exit-code origin/main; then
            git fetch origin "$BRANCH" || true
            git push --force-with-lease -u origin "$BRANCH"

            gh pr create \
              --base main \
              --head "$BRANCH" \
              --title "chore: update flake inputs" \
              --fill
          fi