name: Generate Snake

on:
  schedule:
    # every 6 hours
    - cron: "0 */6 * * *"
  
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      # Checkout repository
      - uses: actions/checkout@v3

      # Generate the snake
      - uses: Platane/snk@master
        id: snake-gif
        with:
          github_user_name: bdrtr
          gif_out_path: dist/github-contribution-grid-snake.gif
          svg_out_path: dist/github-contribution-grid-snake.svg

      # Check the status of the build
      - run: git status

      # Push the changes to the correct branch (replace master with main if needed)
      - name: Push changes
        uses: ad-m/github-push-action@v0.6.0
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: main  # Use "main" if your default branch is main
          force: true

      # Deploy to GitHub Pages
      - uses: crazy-max/ghaction-github-pages@v2.1.3
        with:
          target_branch: output
          build_dir: dist
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
