name: Test Manifests

on:
  pull_request:
    types:
    - opened
    - reopened
    paths:
    - 'bucket/**'
  push:
    paths:
    - 'bucket/**'
  workflow_dispatch:

jobs:
  test_powershell5:
    name: Powershell 5
    runs-on: windows-latest
    steps:
    - name: Checkout Bucket
      uses: actions/checkout@main
      with:
        fetch-depth: 2
        path: 'my_bucket'
    - name: Checkout Scoop
      uses: actions/checkout@main
      with:
        repository: ScoopInstaller/Scoop
        ref: v0.3.0 # Pester 4
        path: 'scoop_core'
    - name: Checkout Scoop Main
      uses: actions/checkout@main
      with:
        repository: ScoopInstaller/Main
        path: 'scoop/buckets/main'
    - name: Cache PS Modules
      uses: potatoqualitee/psmodulecache@v5.1
      with:
        modules-to-cache: Pester:4.10.1, PSScriptAnalyzer, BuildHelpers
        shell: powershell
    - name: Cache Helpers
      uses: actions/cache@v3
      with:
        path: scoop_global
        key: ${{ runner.os }}-scoop-global-helpers
    - name: Test Manifests
      shell: powershell
      run: |
        cd .\my_bucket\
        ..\scoop_core\test\bin\test.ps1 -TestPath .
        $result = $LASTEXITCODE
        Write-Host "============ Install Log ============"
        $log = 'Install.log'
        if (Test-Path $log) {
          Get-Content $log -Raw | Write-Host
        }
        exit $result
      env:
        GITHUB_PULL_REQUEST_BASE_SHA: ${{ github.event.pull_request.base.sha }}
        SCOOP_HOME: ${{ github.workspace }}\scoop_core
        SCOOP_GLOBAL: ${{ github.workspace }}\scoop_global
        SCOOP: ${{ github.workspace }}\scoop