name: test-game

on: 
  workflow_dispatch:
  pull_request:
    branches:
      - main
    paths:
      - 'games/**.js'

permissions:
  contents: read
  pull-requests: read

jobs:
  test-game:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Log Environment Information
        run: |
          echo "Run started on: $(date)"
          echo "Runner OS: ${{ runner.os }}"
          echo "Workflow Ref: ${{ github.ref }}"
          echo "Base Ref: ${{ github.base_ref }}"
          echo "Head Ref: ${{ github.head_ref }}"
          echo "Event Name: ${{ github.event_name }}"
          echo "Repository: ${{ github.repository }}"

      - name: Get changed files
        id: changed-files
        uses: tj-actions/changed-files@v41.0.1
        with:
          files: |
            games/**.js

      - name: Log Changed Files
        run: |
          echo "Changed Files:"
          echo "${{ steps.changed-files.outputs.all_changed_files }}"

      - name: Setup Deno
        uses: denoland/setup-deno@v1.1.3

      - name: Check Games
        run: deno run --allow-read tests/sprigfuzzy_workflow.js ${{ steps.changed-files.outputs.all_changed_files }}