Install Java on Windows CI #28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: pull_request | |
| permissions: | |
| contents: read | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| jobs: | |
| tests: | |
| name: Test | |
| uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main | |
| with: | |
| enable_windows_checks: true | |
| windows_swift_versions: '["nightly-main"]' | |
| windows_pre_build_command: | | |
| $jdkVersion = "21" | |
| $msiUrl = "https://aka.ms/download-jdk/microsoft-jdk-$jdkVersion-windows-x64.msi" | |
| $installerPath = "$env:TEMP\microsoft-jdk-$jdkVersion.msi" | |
| $jdkInstallDir = "C:\Program Files\Microsoft\jdk-$jdkVersion" | |
| # Download the MSI | |
| Write-Host "Downloading Microsoft OpenJDK $jdkVersion..." | |
| Invoke-WebRequest -Uri $msiUrl -OutFile $installerPath | |
| # Install silently | |
| Write-Host "Installing Microsoft OpenJDK $jdkVersion..." | |
| Start-Process msiexec.exe -ArgumentList "/i `"$installerPath`" /quiet /norestart INSTALLDIR=`"$jdkInstallDir`"" -Wait -NoNewWindow | |
| # Set JAVA_HOME (system-wide, requires admin) | |
| Write-Host "Setting JAVA_HOME..." | |
| [System.Environment]::SetEnvironmentVariable("JAVA_HOME", $jdkInstallDir, [System.EnvironmentVariableTarget]::Machine) | |
| # Add to system PATH if not already present | |
| $currentPath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine) | |
| if ($currentPath -notlike "*$jdkInstallDir\bin*") { | |
| [System.Environment]::SetEnvironmentVariable("PATH", "$currentPath;$jdkInstallDir\bin", [System.EnvironmentVariableTarget]::Machine) | |
| Write-Host "Added JDK bin to system PATH." | |
| } | |
| # Refresh current session | |
| $env:JAVA_HOME = $jdkInstallDir | |
| $env:PATH = "$env:PATH;$jdkInstallDir\bin" | |
| # Verify | |
| Write-Host "`nVerifying installation..." | |
| & "$jdkInstallDir\bin\java.exe" -version | |
| Write-Host "`nDone! JAVA_HOME = $env:JAVA_HOME" | |
| # Clean up installer | |
| Remove-Item $installerPath -Force | |
| Get-ChildItem Env: | |
| enable_macos_checks: true | |
| macos_pre_build_command: brew install openjdk | |
| enable_ios_checks: false | |
| enable_linux_checks: true | |
| linux_os_versions: '["amazonlinux2", "bookworm", "noble", "jammy", "rhel-ubi9"]' | |
| linux_exclude_swift_versions: "[{\"swift_version\": \"5.9\"}, {\"swift_version\": \"5.10\"}]" | |
| linux_pre_build_command: | | |
| if command -v apt-get >/dev/null 2>&1 ; then # bookworm, noble, jammy | |
| if command -v sudo &> /dev/null && [ "$EUID" -ne 0 ]; then | |
| sudo apt-get update -y | |
| sudo apt-get install -y default-jdk | |
| else | |
| apt-get update -y | |
| apt-get install -y default-jdk | |
| fi | |
| elif command -v yum >/dev/null 2>&1 ; then # amazonlinux2, rhel-ubi9 | |
| yum update -y | |
| yum install -y java-devel | |
| fi | |
| enable_android_sdk_build: true | |
| enable_android_sdk_checks: true | |
| soundness: | |
| uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main | |
| with: | |
| api_breakage_check_enabled: false | |
| format_check_enabled: true | |
| license_header_check_project_name: Swift.org | |
| docs_check_enabled: false | |
| test-swift: | |
| name: Test (Swift) (${{ matrix.os_version }} swift:${{ matrix.swift_version }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| swift_version: ['6.1.3', '6.2', 'nightly-6.3', 'nightly'] | |
| os_version: ['jammy'] | |
| container: | |
| image: ${{ (contains(matrix.swift_version, 'nightly') && 'swiftlang/swift') || 'swift' }}:${{ matrix.swift_version }}-${{ matrix.os_version }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Prepare CI Environment | |
| uses: ./.github/actions/prepare_env | |
| - name: Swift Build | |
| run: swift build | |
| - name: Swift Test | |
| run: swift test | |
| linkage-test: | |
| name: Linkage test (jammy swift:6.2) | |
| runs-on: ubuntu-latest | |
| container: | |
| image: swift:6.2-jammy | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Prepare CI Environment | |
| uses: ./.github/actions/prepare_env | |
| - name: Run linkage test | |
| run: ./scripts/run-linkage-test.sh | |
| env: | |
| JAVA_HOME: ${{ env.JAVA_HOME }} |