name: Daily Feed Update
on:
  schedule:
    - cron: '0 1 * * *'
  workflow_dispatch:

permissions:
  contents: write

jobs:
  update-feed:
    runs-on: ubuntu-latest
    container:
      image: node:18 
    steps:
      #    - name: Install Dependencies
      #run: |
      #  apt-get update -y && apt-get install -y \
      #    git \
      #    openssh-client \
      #    curl \
      #    ca-certificates

    - name: Checkout repository
      uses: actions/checkout@v4
      with:
        repository: bpmcdevitt/github_poc_collector
        # Use the appropriate ref if you want a specific branch/commit
        # ref: main
        # If you need to use SSH
        ssh-key: ${{ secrets.TOKEN_NAME }}
        # If you have specific known hosts
        ssh-known-hosts: git.mcdevitt.tech
        ssh-port: 3022

    - name: Setup Rust
      run: |
        curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
        source "$HOME/.cargo/env"
        rustup default stable
        rustc --version
        cargo --version

    - name: Cache Cargo dependencies
      run: |
        mkdir -p ~/.cargo/registry
        mkdir -p ~/.cargo/git
        mkdir -p target

    - name: Run recent feed update
      run: |
        source "$HOME/.cargo/env"
        cargo run -- --feed recent

    - name: Commit and push results
      run: |
        git config user.name bpmcdevitt
        git config user.email brendan@mcdevitt.tech
        git add .
        git commit -m "Update recent feed data" || exit 0
        git push