name: update-flake-lock
run-name: ${{ github.actor }} - update-flake-lock
on:
 schedule:
   - cron: '0 0 * * *'
   # “At 00:00 daily."

jobs:
  update-flake-lock:
    runs-on: ubuntu
    container: 
      image: ubuntu:23.10
    steps:
    - name:  "Setup Runner"
      run: |
        apt update -y
        apt install git nodejs nix-bin -y
        git config --global user.email "${{github.actor}}"
        git config --global user.name "Albert J. Copeland"
    - uses: actions/checkout@v3
    - name: "Directory Structure"
      run: | 
        ls ${{ github.workspace }}/*
    - name: "Git Info"
      run: |
        git -C ${{ github.workspace }} status
        git -C ${{ github.workspace }} log
        git -C ${{ github.workspace }} diff
    - name: "Runner:  Node Info"
      run: |
        id
        uname -a
        hostname
        cat /etc/os-release
    - name: "Nix Version"
      run:  | 
        nix --version
    - name: "Nix Flake Update"
      run: | 
        echo "Running Nix Flake Update"
        cd /workspace/albert/nix
        nix --extra-experimental-features "nix-command flakes" flake update
        echo "Git Diff:"
        git diff
    - name: "Commit and Upload"
      run: | 
        git commit -am "[ACTIONS] Flake Update (`date +%Y-%m-%d`)"
        git push 
    - if: success()
      uses:  https://git.sysctl.io/actions/gotify-action@master
      with:
        gotify_api_base: '${{ secrets.GOTIFY_URL }}'
        gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}'
        notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] NixOS Flake Updated'
        notification_message: 'Build completed successfully.'
    - if: failure()
      uses:  https://git.sysctl.io/actions/gotify-action@master
      with:
        gotify_api_base: '${{ secrets.GOTIFY_URL }}'
        gotify_app_token: '${{ secrets.GOTIFY_TOKEN }}'
        notification_title: '[ ${{ github.repository }}: ${{ github.workflow }} ] Build Failed'
        notification_message: 'Your build has failed.  Check Forgejo.'
      name:  "Send Notification"