Below is an example GitHub Actions workflow (YAML file) that meets your requirements. This workflow is manually triggered (“workflow_dispatch”) and accepts inputs for the branch/commit to build, a boolean to optionally add
--disable-warnings-as-errors, a choice for the debug level, boot JDK provider/version, extra flags, and an artifact name (which—if left empty—is computed as “(repo name)-(branch)-windows‑x64”). The job runs on a Windows runner, installs Cygwin via Chocolatey (if needed) and then invokes the build via Cygwin’s bash. Finally it uploads the built artifact.
Place the following file (for example as .github/workflows/build-jdk-windows.yml) in your repository:
name: Build Java JDK for Windows x64
on:
workflow_dispatch:
inputs:
# Input: branch/tag/commit to build.
branch:
description: 'Branch name, tag, or commit SHA to build'
required: false
default: 'master'
# Checkbox input (true/false as string) for adding --disable-warnings-as-errors.
disable_warnings_as_errors:
description: 'Add "--disable-warnings-as-errors" to configure flags (true/false)'
required: false
default: 'false'
# Choice input for build debug level.
debug_level:
description: 'Build debug level'
required: false
default: 'release'
type: choice
options:
- release
- optimized
- fastdebug
- slowdebug
# Input for Boot JDK provider.
boot_jdk_provider:
description: 'Boot JDK provider'
required: false
default: 'Adoptium'
# Input for Boot JDK version.
boot_jdk_version:
description: 'Boot JDK version'
required: false
default: '21'
# Optional extra configure flags.
extra_configure_flags:
description: 'Extra flags to pass to the configure script'
required: false
default: ''
# Build artifact name. (Leave empty to use the computed default.)
artifact_name:
description: 'Build artifact name; leave empty to default to (repo name)-(branch)-windows-x64'
required: false
default: ''
jobs:
build:
name: Build JDK on Windows using Cygwin
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.branch }}
- name: Ensure Chocolatey is available
shell: powershell
run: |
if (-not (Get-Command choco -ErrorAction SilentlyContinue)) {
Write-Error "Chocolatey is not installed on this runner."
exit 1
} else {
Write-Output "Chocolatey is available."
}
- name: Install Cygwin (if not already installed)
shell: powershell
run: |
# Attempt to install Cygwin via Chocolatey.
# (This may skip if Cygwin is already installed on the runner.)
choco install cygwin -y
Write-Output "Cygwin installation attempted (or already installed)."
- name: Compute Artifact Name
id: artifactname
shell: pwsh
run: |
# If the user did not provide an artifact name, compute the default.
if ("${{ github.event.inputs.artifact_name }}" -eq "") {
# Extract only the repository name portion (drop owner).
$repo = "${{ github.repository }}"
if ($repo -match '.*/(.*)$') {
$repoName = $matches[1]
} else {
$repoName = $repo
}
$artifact = "$repoName-${{ github.event.inputs.branch }}-windows-x64"
}
else {
$artifact = "${{ github.event.inputs.artifact_name }}"
}
Write-Host "Computed Artifact Name: $artifact"
echo "::set-output name=artifact::$artifact"
- name: Build the JDK using Cygwin
shell: powershell
env:
# Pass inputs as environment variables for easier access.
BUILD_BRANCH: ${{ github.event.inputs.branch }}
DEBUG_LEVEL: ${{ github.event.inputs.debug_level }}
BOOT_JDK_PROVIDER: ${{ github.event.inputs.boot_jdk_provider }}
BOOT_JDK_VERSION: ${{ github.event.inputs.boot_jdk_version }}
EXTRA_FLAGS: ${{ github.event.inputs.extra_configure_flags }}
DISABLE_WARNINGS: ${{ github.event.inputs.disable_warnings_as_errors }}
run: |
Write-Host "Starting build for branch $env:BUILD_BRANCH"
# Compose the configure flags.
$configureFlags = "--with-debug-level=$env:DEBUG_LEVEL --boot-jdk-provider=$env:BOOT_JDK_PROVIDER --boot-jdk-version=$env:BOOT_JDK_VERSION $env:EXTRA_FLAGS"
if ($env:DISABLE_WARNINGS -eq "true") {
$configureFlags += " --disable-warnings-as-errors"
}
Write-Host "Configure flags: $configureFlags"
# Assume that your repository includes the OpenJDK build scripts and
# that building with Cygwin requires invoking the Cygwin bash.
# Adjust the path to Cygwin's bash if needed.
$cygwinBash = "C:\cygwin64\bin\bash.exe"
if (-Not (Test-Path $cygwinBash)) {
Write-Error "Cygwin bash not found at $cygwinBash"
exit 1
}
# Run the configure script under Cygwin.
Write-Host "Running ./configure with flags"
& $cygwinBash -c "./configure $configureFlags" || (Write-Error "Configure failed" ; exit 1)
# Run the build (make images) under Cygwin.
Write-Host "Running make images"
& $cygwinBash -c "make images" || (Write-Error "Build failed" ; exit 1)
# Assume that the built artifact (e.g. a ZIP or installer) is placed in a known location.
# For demonstration, we assume the artifact is generated as "build/windows-x64jdk.tar.gz"
Write-Host "Build finished. Artifact should be available in the expected output directory."
- name: Upload Build Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.artifactname.outputs.artifact }}
# Change the artifact path below to match where your build outputs are located.
path: build/windows-x64jdk.*
Explanation
-
Trigger & Inputs:
- The workflow is triggered manually via the Workflow Dispatch event.
- It prompts for the branch/commit/ tag, a boolean input (as a string) to add
--disable-warnings-as-errors, the build debug level (with preset options), boot JDK provider/version, any extra configure flags, and the artifact name.
- If no artifact name is provided, the step named Compute Artifact Name calculates a default using the repository name and branch.
-
Checkout & Environment:
- The Checkout code step checks out the specified branch/commit.
- The job then verifies that Chocolatey is available and tries to install Cygwin (if not already installed). Adjustments may be necessary if your runner already has Cygwin or you use an alternative installation method.
-
Building with Cygwin:
- The Build the JDK using Cygwin step assembles the configure flags (including the optional flag if chosen) and invokes the build process via Cygwin’s bash (assumed at
C:\cygwin64\bin\bash.exe).
- Modify the commands as needed to match your actual build process.
-
Artifact Upload:
- Finally, the artifact is uploaded using
actions/upload-artifact. Adjust the file path (build/windows-x64jdk.*) to wherever your build places the output artifact.
Feel free to tailor the commands and paths to your project’s exact build process and directory structure.