Here's a GitHub Actions workflow that meets your requirements for building a JDK for Windows x64 using Cygwin, with configurable inputs and artifact upload:
name: Build JDK for Windows x64
on:
workflow_dispatch:
inputs:
ref:
description: 'Branch name, tag, or commit SHA'
required: true
default: 'master'
type: string
disable_warnings_as_errors:
description: 'Add --disable-warnings-as-errors to configure flags'
required: false
default: false
type: boolean
build_debug_level:
description: 'Build debug level'
required: true
default: 'release'
type: choice
options:
- release
- optimized
- fastdebug
- slowdebug
- product
boot_jdk_provider:
description: 'Boot JDK provider'
required: true
default: 'Adoptium'
type: string
boot_jdk_version:
description: 'Boot JDK version'
required: true
default: '21'
type: string
extra_configure_flags:
description: 'Extra configure flags (optional)'
required: false
default: ''
type: string
artifact_name:
description: 'Artifact name'
required: true
default: '${{ github.repository }}-${{ inputs.ref }}-windows-x64'
type: string
push:
branches:
- main
- master
paths:
- '**'
jobs:
build:
runs-on: windows-latest
env:
REF: ${{ inputs.ref || github.ref_name }}
DISABLE_WARNINGS_AS_ERRORS: ${{ inputs.disable_warnings_as_errors }}
BUILD_DEBUG_LEVEL: ${{ inputs.build_debug_level || 'release' }}
BOOT_JDK_PROVIDER: ${{ inputs.boot_jdk_provider || 'Adoptium' }}
BOOT_JDK_VERSION: ${{ inputs.boot_jdk_version || '21' }}
EXTRA_CONFIGURE_FLAGS: ${{ inputs.extra_configure_flags || '' }}
ARTIFACT_NAME: ${{ inputs.artifact_name || format('{0}-{1}-windows-x64', github.repository, inputs.ref || github.ref_name) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
fetch-depth: 0
- name: Set up Cygwin
run: |
# Install Cygwin with required packages
$cygwinSetup = "cygwin-setup-x86_64.exe"
Invoke-WebRequest -Uri "https://cygwin.com/$cygwinSetup" -OutFile $cygwinSetup
Start-Process -Wait -NoNewWindow -FilePath ".\$cygwinSetup" -ArgumentList "--quiet-mode --packages autoconf,make,zip,unzip,gcc-core,gcc-g++,binutils,libffi-devel,libcrypt-devel,libiconv-devel,libicu-devel,zlib-devel,ca-certificates"
- name: Set up Boot JDK
run: |
$bootJdkUrl = "https://api.adoptium.net/v3/binary/latest/${{ env.BOOT_JDK_VERSION }}/ga/windows/x64/jdk/hotspot/normal/${{ env.BOOT_JDK_PROVIDER }}?contentType=application/zip"
$bootJdkZip = "bootjdk.zip"
Invoke-WebRequest -Uri $bootJdkUrl -OutFile $bootJdkZip
Expand-Archive -Path $bootJdkZip -DestinationPath bootjdk
$bootJdkPath = (Get-ChildItem -Path bootjdk -Directory -Recurse | Select-Object -First 1).FullName
echo "BOOT_JDK_HOME=$bootJdkPath" >> $env:GITHUB_ENV
- name: Configure and build JDK
shell: bash
run: |
# Set up Cygwin environment
export CYGWIN_HOME="C:\cygwin64"
export PATH="$CYGWIN_HOME\bin:$PATH"
# Prepare configure flags
CONFIGURE_FLAGS="--openjdk-target=x86_64-unknown-cygwin --with-boot-jdk=$BOOT_JDK_HOME --with-build-jdk=$BOOT_JDK_HOME --with-debug-level=$BUILD_DEBUG_LEVEL"
if [ "$DISABLE_WARNINGS_AS_ERRORS" = "true" ]; then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS --disable-warnings-as-errors"
fi
if [ -n "$EXTRA_CONFIGURE_FLAGS" ]; then
CONFIGURE_FLAGS="$CONFIGURE_FLAGS $EXTRA_CONFIGURE_FLAGS"
fi
# Configure and build
bash configure $CONFIGURE_FLAGS
make images -j $(nproc)
- name: Archive build results
run: |
$buildDir = (Get-ChildItem -Path "build" -Directory | Where-Object { $_.Name -like "*windows-x86_64*" } | Select-Object -First 1).FullName
$artifactPath = "${{ env.ARTIFACT_NAME }}.zip"
Compress-Archive -Path "$buildDir\images\jdk" -DestinationPath $artifactPath
echo "ARTIFACT_PATH=$artifactPath" >> $env:GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}
Key Features:
-
Workflow Triggers:
- Manual trigger with all the inputs you requested
- Automatic trigger on push to main/master branches
-
Configurable Inputs:
- Branch/tag/commit SHA (default: 'master')
- Checkbox for
--disable-warnings-as-errors flag
- Build debug level selection (default: 'release')
- Boot JDK provider (default: 'Adoptium')
- Boot JDK version (default: '21')
- Extra configure flags (optional)
- Artifact name (default: repo-branch-windows-x64)
-
Build Process:
- Installs Cygwin with required packages
- Downloads and sets up the Boot JDK
- Configures and builds the JDK with the specified options
- Packages the build results into a zip file
-
Artifact Handling:
- Creates a zip archive of the built JDK
- Uploads it as a workflow artifact with the specified name
Notes:
- The workflow assumes you're building OpenJDK (uses standard configure flags)
- The Boot JDK is downloaded from Adoptium's API by default
- Cygwin is installed with all the necessary packages for JDK building
- The artifact name defaults to
repo-name-branch-windows-x64 but can be customized
You may need to adjust some paths or package names depending on your specific JDK repository structure or requirements.