name: Validate local file

on:
  push:
    branches:
      - main
      - releases/*
    paths-ignore:
      - '**.md'
  pull_request:
    paths-ignore:
      - '**.md'

jobs:
  setup-java-local-file-adopt:
    name: Validate installation from local file Adopt
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Download Adopt OpenJDK file
        run: |
          if ($IsLinux) {
            $downloadUrl = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsMacOS) {
            $downloadUrl = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_mac_hotspot_11.0.10_9.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsWindows) {
            $downloadUrl = "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_windows_hotspot_11.0.10_9.zip"
            $localFilename = "java_package.zip"
          }
          echo "LocalFilename=$localFilename" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
          (New-Object System.Net.WebClient).DownloadFile($downloadUrl, "$env:RUNNER_TEMP/$localFilename")
        shell: pwsh
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: 'jdkfile'
          jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
          java-version: '11.0.0-ea'
          architecture: x64
      - name: Verify Java version
        run: bash __tests__/verify-java.sh "11.0.10" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  setup-java-local-file-zulu:
    name: Validate installation from local file Zulu
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Download Zulu OpenJDK file
        run: |
          if ($IsLinux) {
            $downloadUrl = "https://cdn.azul.com/zulu/bin/zulu11.2.3-jdk11.0.1-linux_x64.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsMacOS) {
            $downloadUrl = "https://cdn.azul.com/zulu/bin/zulu11.2.3-jdk11.0.1-macosx_x64.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsWindows) {
            $downloadUrl = "https://cdn.azul.com/zulu/bin/zulu11.45.27-ca-jdk11.0.10-win_x64.zip"
            $localFilename = "java_package.zip"
          }
          echo "LocalFilename=$localFilename" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
          (New-Object System.Net.WebClient).DownloadFile($downloadUrl, "$env:RUNNER_TEMP/$localFilename")
        shell: pwsh
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: 'jdkfile'
          jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
          java-version: '11.0.0-ea'
          architecture: x64
      - name: Verify Java version
        run: bash __tests__/verify-java.sh "11.0" "${{ steps.setup-java.outputs.path }}"
        shell: bash

  setup-java-local-file-temurin:
    name: Validate installation from local file Eclipse Temurin
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Download Eclipse Temurin file
        run: |
          if ($IsLinux) {
            $downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsMacOS) {
            $downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_mac_hotspot_11.0.12_7.tar.gz"
            $localFilename = "java_package.tar.gz"
          } elseif ($IsWindows) {
            $downloadUrl = "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_windows_hotspot_11.0.12_7.zip"
            $localFilename = "java_package.zip"
          }
          echo "LocalFilename=$localFilename" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
          (New-Object System.Net.WebClient).DownloadFile($downloadUrl, "$env:RUNNER_TEMP/$localFilename")
        shell: pwsh
      - name: setup-java
        uses: ./
        id: setup-java
        with:
          distribution: 'jdkfile'
          jdkFile: ${{ runner.temp }}/${{ env.LocalFilename }}
          java-version: '11.0.0-ea'
          architecture: x64
      - name: Verify Java version
        run: bash __tests__/verify-java.sh "11.0.12" "${{ steps.setup-java.outputs.path }}"
        shell: bash
