name: On_Push

on:
  push:
    branches:
      - 'main'
    paths:
      - flake.*
      - src/**/*
      - Cargo.*
      - .forgejo/**/*
      - rust-toolchain.toml

jobs:
  # rust code must be formatted for standardisation
  lint_fmt:
    # build it using teh base nixos system, helps with caching
    runs-on: nix
    steps:
      # get the repo first
      - uses: https://code.forgejo.org/actions/checkout@v4
      - uses: https://forgejo.skynet.ie/Skynet/actions/get_lfs@v3
        with:
          repository: ${{ gitea.repository }}
          ref_name: ${{ gitea.ref_name }}
      - run: nix build .#fmt --verbose

  # clippy is incredibly useful for making yer code better
  lint_clippy:
    # build it using teh base nixos system, helps with caching
    runs-on: nix
    permissions:
      checks: write
    steps:
      # get the repo first
      - uses: https://code.forgejo.org/actions/checkout@v4
      - uses: https://forgejo.skynet.ie/Skynet/actions/get_lfs@v3
        with:
          repository: ${{ gitea.repository }}
          ref_name: ${{ gitea.ref_name }}
      - run: nix build .#clippy --verbose
  
  build:
    # build it using teh base nixos system, helps with caching
    runs-on: nix
    needs: [ lint_fmt, lint_clippy ]
    steps:
      # get the repo first
      - uses: https://code.forgejo.org/actions/checkout@v4
      - uses: https://forgejo.skynet.ie/Skynet/actions/get_lfs@v3
        with:
          repository: ${{ gitea.repository }}
          ref_name: ${{ gitea.ref_name }}
      - name: "Build it locally"
        run: nix build --verbose

  # deploy it upstream
  deploy:
    # runs on teh default docker container
    runs-on: docker
    needs: [ build ]
    steps:
      - name: "Deploy to Skynet"
        uses: https://forgejo.skynet.ie/Skynet/actions/deploy@v3
        with:
          input: 'skynet_discord_bot'
          token: ${{ secrets.API_TOKEN_FORGEJO }}