# Copyright 2024 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Update Nix Flake

on:
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * 0' # Weekly on Sundays

permissions:
  contents: write
  pull-requests: write

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  update-flake:
    name: Update flake.lock
    runs-on: ubuntu-latest
    timeout-minutes: 45
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Install Nix
        uses: DeterminateSystems/determinate-nix-action@v3

      - name: Check Nix flake inputs
        uses: DeterminateSystems/flake-checker-action@v12

      - name: Update flake.lock
        id: update
        uses: DeterminateSystems/update-flake-lock@main
        with:
          git-author-name: houseme
          git-author-email: housemecn@gmail.com
          git-committer-name: houseme
          git-committer-email: housemecn@gmail.com
          pr-title: "chore(deps): update flake.lock"
          pr-labels: |
            dependencies
            nix
            automated
          commit-msg: "chore(deps): update flake.lock"
          pr-reviewers: houseme, overtrue, majinghe
          token: ${{ secrets.FLAKE_UPDATE_TOKEN }}

      - name: Log PR details
        if: steps.update.outputs.pull-request-number
        run: |
          echo "Pull Request created: ${{ steps.update.outputs.pull-request-number }}"
