Make GitHub actions workflow that builds this branch of corretto 21 (…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Make GitHub actions workflow that builds this branch of corretto 21 ( https://github.com/corretto/corretto-21/tree/lilliput-2 ) for windows. Workflow should be highly optimized. The compilation result must not have .pdb and .map files and must be a release version. It should run every Monday at 8:00 Moscow time zone, at startup it should check the SHA256 of the last commit and the sha256 that corresponded to the commit during the last generation, which should be stored in a variable named LAST_BUILT_SHA. For a more efficient SHA comparison, you can compare SHAs in the Linux runner and then run the windows runner. For a faster getting upstream sha you can use commands. Writing to a variable should not use the PAT token. Because of Cygwin exist already in runner you can just install missing packages instead of doing full Cygwin installation, or you can use MSYS2 if you think it's faster.
name: Build Corretto 21 lilliput-2 for Windows
on:
schedule:
- cron: '0 5 * * 1'
workflow_dispatch:
env:
UPSTREAM_REPO: corretto/corretto-21
UPSTREAM_BRANCH: lilliput-2
GITHUB_VARIABLE_NAME: LAST_BUILT_CORRETTO_LILLIPUT_SHA
CORRETTO_SOURCE_DIR: corretto_source_checkout
CYGWIN_PACKAGES: make,coreutils,diffutils,binutils,zip,unzip,autoconf,automake
jobs:
build_if_new_commits:
runs-on: windows-2025
permissions:
contents: read
actions: read
steps:
# 1. Read the Last Built Upstream SHA from GitHub Repository Variable
- name: Read Last Built Upstream SHA from GitHub Variable
id: read_last_sha
run: |
$sha_from_var = "${{ vars[env.GITHUB_VARIABLE_NAME] || '' }}"
echo "last_sha=$sha_from_var" >> $GITHUB_OUTPUT
Write-Host "Last built upstream SHA read from variable '${{ env.GITHUB_VARIABLE_NAME }}': '$sha_from_var'"
shell: pwsh
# 2. Checkout the upstream repository in one step (shallow clone)
- name: Checkout upstream repository
id: checkout_upstream
uses: actions/checkout@v4
with:
repository: ${{ env.UPSTREAM_REPO }}
ref: ${{ env.UPSTREAM_BRANCH }}
fetch-depth: 1
path: ${{ env.CORRETTO_SOURCE_DIR }}
# 3. Get current upstream SHA from the checked-out repository
- name: Get Current Upstream SHA
id: get_upstream_sha
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$current_sha = (git rev-parse HEAD).Trim()
Write-Host "Current upstream SHA determined for $env.UPSTREAM_BRANCH: '$current_sha'"
echo "sha=$current_sha" >> $env:GITHUB_OUTPUT
shell: pwsh
# 4. Determine if build is needed
- name: Determine if Build is Needed
id: check_build_condition
run: |
$last_sha = "${{ steps.read_last_sha.outputs.last_sha }}"
$current_sha = "${{ steps.get_upstream_sha.outputs.sha }}"
$needs_build_ps_var = "false"
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$needs_build_ps_var = "true"
Write-Host "Manual dispatch (workflow_dispatch): Build is forced."
} elseif ($last_sha -ne $current_sha) {
$needs_build_ps_var = "true"
Write-Host "Upstream SHA has changed (was '$last_sha', now '$current_sha'). Build needed."
} else {
Write-Host "Upstream SHA ('$current_sha') matches last built SHA. No build needed."
}
echo "needs_build=$needs_build_ps_var" >> $env:GITHUB_OUTPUT
shell: pwsh
# 5. Update GitHub Repository Variable with the new SHA (only if build is needed)
- name: Update GitHub Repository Variable with PAT
if: steps.check_build_condition.outputs.needs_build == 'true'
env:
NEW_SHA_TO_SAVE: ${{ steps.get_upstream_sha.outputs.sha }}
GH_TOKEN: ${{ secrets.MY_PAT }}
TARGET_VARIABLE_NAME: LAST_BUILT_CORRETTO_LILLIPUT_SHA
run: |
gh variable set "${TARGET_VARIABLE_NAME}" --body "${NEW_SHA_TO_SAVE}" --repo "${{ github.repository }}"
shell: bash
# 6. Set up Corretto 21 as Bootstrap JDK
- name: Set up Corretto 21 as Bootstrap JDK
if: steps.check_build_condition.outputs.needs_build == 'true'
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
architecture: x64
id: setup_jdk
# 7. Cache Cygwin installation (note: consider additional caches for build artifacts if beneficial)
- name: Cache Cygwin installation
if: steps.check_build_condition.outputs.needs_build == 'true'
id: cache-cygwin
uses: actions/cache@v4
with:
path: C:\cygwin64
key: ${{ runner.os }}-cygwin-packages-${{ hashFiles(env.CYGWIN_PACKAGES) }}
# 8. Install Cygwin with necessary packages (only if not already cached)
- name: Install Cygwin with necessary packages (if not cached)
if: steps.check_build_condition.outputs.needs_build == 'true' && steps.cache-cygwin.outputs.cache-hit != 'true'
run: |
choco install cygwin --params "/InstallDir:C:\cygwin64 /NoAdmin" -y
$cygwinSetupPath = "C:\cygwin64\cygwinsetup.exe"
if (-not (Test-Path $cygwinSetupPath -PathType Leaf)) {
Write-Error "Cygwin setup executable ($cygwinSetupPath) not found!";
exit 1
}
$cygwinMirror = "https://mirrors.kernel.org/sourceware/cygwin/"
Write-Host "Installing Cygwin packages: $env.CYGWIN_PACKAGES"
Start-Process -FilePath $cygwinSetupPath -ArgumentList "-q -s $cygwinMirror -P $env:CYGWIN_PACKAGES" -Wait -NoNewWindow
if ($LASTEXITCODE -ne 0) {
Write-Error "Cygwin setup exited with code $LASTEXITCODE.";
exit $LASTEXITCODE
}
shell: pwsh
# 9. Add Cygwin to PATH
- name: Add Cygwin to PATH
if: steps.check_build_condition.outputs.needs_build == 'true'
run: echo "C:\cygwin64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
shell: pwsh
# 10. Configure Corretto Build using the bootstrap JDK
- name: Configure Corretto Build
if: steps.check_build_condition.outputs.needs_build == 'true'
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$BOOT_JDK_WINDOWS = $env:JAVA_HOME
if (-not $BOOT_JDK_WINDOWS) {
Write-Error "Bootstrap JDK path from JAVA_HOME is empty!";
exit 1
}
# Convert Windows path to Cygwin style
$BOOT_JDK_CYGWIN = (& cygpath --unix $BOOT_JDK_WINDOWS).Trim()
Write-Host "Using Bootstrap JDK (Cygwin path): $BOOT_JDK_CYGWIN"
C:\cygwin64\bin\bash -c "./configure --with-boot-jdk='$BOOT_JDK_CYGWIN' --disable-warnings-as-errors --with-debug-level=release"
shell: pwsh
# 11. Build Corretto using parallel execution (using all available processors)
- name: Build Corretto (make images)
if: steps.check_build_condition.outputs.needs_build == 'true'
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
# Use getconf to fetch the number of processors in Cygwin and run make in parallel.
C:\cygwin64\bin\bash -c "make JOBS=\$(getconf _NPROCESSORS_ONLN) images"
shell: pwsh
# 12. Clean Debug Symbols from JDK Image
- name: Clean Debug Symbols from JDK Image
if: steps.check_build_condition.outputs.needs_build == 'true'
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$jdkImagePath = Get-ChildItem -Path "build\*\images\jdk" -Directory | Select-Object -First 1 -ExpandProperty FullName
if ($jdkImagePath) {
Write-Host "Cleaning *.pdb and *.map files from $jdkImagePath"
Get-ChildItem -Path $jdkImagePath -Recurse -Include "*.pdb", "*.map" | Remove-Item -Force -ErrorAction SilentlyContinue
} else {
Write-Warning "Could not find JDK image directory to clean."
}
shell: pwsh
# 13. Prepare Artifact Structure (extract version info and repackage the build)
- name: Prepare Artifact Structure
if: steps.check_build_condition.outputs.needs_build == 'true'
id: prepare_artifact
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$jdkSourcePath = Get-ChildItem -Path "build\*\images\jdk" -Directory | Select-Object -First 1 -ExpandProperty FullName
if (-not $jdkSourcePath) {
Write-Error "Could not find source JDK image directory";
exit 1
}
$releaseFile = Join-Path $jdkSourcePath "release"
if (-not (Test-Path $releaseFile)) {
Write-Error "Could not find release file at $releaseFile";
exit 1
}
$releaseContent = Get-Content $releaseFile -Raw | ConvertFrom-StringData -Delimiter '='
$javaVersion = $releaseContent.JAVA_VERSION.Trim('"')
if (-not $javaVersion) {
Write-Error "Could not parse JAVA_VERSION from release file";
exit 1
}
Write-Host "Extracted JAVA_VERSION: $javaVersion"
echo "JAVA_VERSION_EXTRACTED=$javaVersion" >> $GITHUB_OUTPUT
$stagingDir = Join-Path $env:GITHUB_WORKSPACE "staging_artifact"
$targetDirName = "corretto-21-lilliput-${javaVersion}"
$fullTargetPathInStaging = Join-Path $stagingDir $targetDirName
if (Test-Path $stagingDir) { Remove-Item -Recurse -Force $stagingDir }
New-Item -ItemType Directory -Path $fullTargetPathInStaging | Out-Null
Move-Item -Path (Join-Path $jdkSourcePath "*") -Destination $fullTargetPathInStaging -Force
shell: pwsh
# 14. Upload Windows JDK Build Artifact
- name: Upload Windows JDK Build Artifact
if: steps.check_build_condition.outputs.needs_build == 'true'
uses: actions/upload-artifact@v4
with:
name: corretto-21-lilliput-${{ steps.prepare_artifact.outputs.JAVA_VERSION_EXTRACTED }}-windows-x64-jdk
path: staging_artifact/
The provided GitHub Actions workflow is already quite detailed and covers most of the requirements you've specified. However, I'll optimize it further based on your needs:
ubuntu-latest to handle SHA comparisons. This avoids unnecessary Windows runner startup costs if no build is needed.GITHUB_OUTPUT and env contexts more efficiently. Since you can't directly update repository variables without a PAT, we'll keep the PAT step but highlight that this is a limitation of GitHub Actions..pdb and .map files and ensure release build: Already covered in your workflow.Here's the refactored workflow:
name: Build Corretto 21 lilliput-2 for Windows
on:
schedule:
# Moscow time is UTC+3; 8:00 MSK = 5:00 UTC
- cron: '0 5 * * 1'
workflow_dispatch:
env:
UPSTREAM_REPO: corretto/corretto-21
UPSTREAM_BRANCH: lilliput-2
GITHUB_VARIABLE_NAME: LAST_BUILT_CORRETTO_LILLIPUT_SHA
CORRETTO_SOURCE_DIR: corretto_source_checkout
# List of Cygwin packages needed
CYGWIN_PACKAGES: make,coreutils,diffutils,binutils,zip,unzip,autoconf,automake
jobs:
check_sha_and_decide_build:
runs-on: ubuntu-latest
outputs:
needs_build: ${{ steps.decide_build.outputs.needs_build }}
current_sha: ${{ steps.get_upstream_sha.outputs.sha }}
steps:
# 1. Read the Last Built Upstream SHA from GitHub Repository Variable
- name: Read Last Built Upstream SHA
id: read_last_sha
env:
LAST_SHA: ${{ vars[env.GITHUB_VARIABLE_NAME] }}
run: |
echo "last_sha=${LAST_SHA:-}" >> $GITHUB_OUTPUT
echo "Last built upstream SHA read from variable '${GITHUB_VARIABLE_NAME}': '${LAST_SHA}'"
# 2. Get current upstream SHA via GitHub CLI (faster than checkout)
- name: Get Current Upstream SHA
id: get_upstream_sha
run: |
current_sha=$(gh api repos/${UPSTREAM_REPO}/commits/${UPSTREAM_BRANCH} --jq '.sha')
echo "sha=$current_sha" >> $GITHUB_OUTPUT
echo "Current upstream SHA for ${UPSTREAM_BRANCH}: '$current_sha'"
# 3. Determine if build is needed
- name: Decide if Build is Needed
id: decide_build
run: |
last_sha="${{ steps.read_last_sha.outputs.last_sha }}"
current_sha="${{ steps.get_upstream_sha.outputs.sha }}"
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
needs_build="true"
echo "Manual dispatch (workflow_dispatch): Build is forced."
elif [[ "$last_sha" != "$current_sha" ]]; then
needs_build="true"
echo "Upstream SHA has changed (was '$last_sha', now '$current_sha'). Build needed."
else
needs_build="false"
echo "Upstream SHA ('$current_sha') matches last built SHA. No build needed."
fi
echo "needs_build=$needs_build" >> $GITHUB_OUTPUT
build_corretto:
needs: check_sha_and_decide_build
if: needs.check_sha_and_decide_build.outputs.needs_build == 'true'
runs-on: windows-2025
permissions:
contents: read
actions: read
env:
NEW_SHA_TO_SAVE: ${{ needs.check_sha_and_decide_build.outputs.current_sha }}
steps:
# 4. Checkout the upstream repository (shallow clone)
- name: Checkout upstream repository
uses: actions/checkout@v4
with:
repository: ${{ env.UPSTREAM_REPO }}
ref: ${{ env.UPSTREAM_BRANCH }}
fetch-depth: 1
path: ${{ env.CORRETTO_SOURCE_DIR }}
# 5. Update GitHub Repository Variable with the new SHA (requires PAT)
- name: Update GitHub Repository Variable with PAT
env:
GH_TOKEN: ${{ secrets.MY_PAT }}
TARGET_VARIABLE_NAME: ${{ env.GITHUB_VARIABLE_NAME }}
run: |
gh variable set "${TARGET_VARIABLE_NAME}" --body "${NEW_SHA_TO_SAVE}" --repo "${{ github.repository }}"
# 6. Set up Corretto 21 as Bootstrap JDK
- name: Set up Corretto 21 as Bootstrap JDK
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
architecture: x64
# 7. Cache Cygwin installation
- name: Cache Cygwin installation
id: cache-cygwin
uses: actions/cache@v4
with:
path: C:\cygwin64
key: ${{ runner.os }}-cygwin-packages-${{ hashFiles(env.CYGWIN_PACKAGES) }}
# 8. Ensure Cygwin has necessary packages (update if cached, install if not)
- name: Install/Update Cygwin Packages
run: |
$cygwinSetupPath = "C:\cygwin64\setup-x86_64.exe"
if (-not (Test-Path $cygwinSetupPath -PathType Leaf)) {
Write-Host "Cygwin not found, installing minimal setup."
Invoke-WebRequest -Uri "https://cygwin.com/setup-x86_64.exe" -OutFile $cygwinSetupPath
}
$cygwinMirror = "https://mirrors.kernel.org/sourceware/cygwin/"
Write-Host "Updating Cygwin packages: $env:CYGWIN_PACKAGES"
Start-Process -FilePath $cygwinSetupPath -ArgumentList "-q -s $cygwinMirror -P $env:CYGWIN_PACKAGES" -Wait -NoNewWindow
if ($LASTEXITCODE -ne 0) {
Write-Error "Cygwin setup exited with code $LASTEXITCODE.";
exit $LASTEXITCODE
}
# 9. Add Cygwin to PATH
- name: Add Cygwin to PATH
run: echo "C:\cygwin64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
# 10. Configure Corretto Build
- name: Configure Corretto Build
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$BOOT_JDK_WINDOWS = $env:JAVA_HOME
if (-not $BOOT_JDK_WINDOWS) {
Write-Error "Bootstrap JDK path from JAVA_HOME is empty!";
exit 1
}
$BOOT_JDK_CYGWIN = (& cygpath --unix $BOOT_JDK_WINDOWS).Trim()
Write-Host "Using Bootstrap JDK (Cygwin path): $BOOT_JDK_CYGWIN"
C:\cygwin64\bin\bash -c "./configure --with-boot-jdk='$BOOT_JDK_CYGWIN' --disable-warnings-as-errors --with-debug-level=release"
# 11. Build Corretto (make images)
- name: Build Corretto (make images)
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
C:\cygwin64\bin\bash -c "make JOBS=\$(getconf _NPROCESSORS_ONLN) images"
# 12. Clean Debug Symbols from JDK Image
- name: Clean Debug Symbols from JDK Image
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$jdkImagePath = Get-ChildItem -Path "build\*\images\jdk" -Directory | Select-Object -First 1 -ExpandProperty FullName
if ($jdkImagePath) {
Write-Host "Cleaning *.pdb and *.map files from $jdkImagePath"
Get-ChildItem -Path $jdkImagePath -Recurse -Include "*.pdb", "*.map" | Remove-Item -Force -ErrorAction SilentlyContinue
} else {
Write-Warning "Could not find JDK image directory to clean."
}
# 13. Prepare Artifact Structure
- name: Prepare Artifact Structure
id: prepare_artifact
working-directory: ${{ env.CORRETTO_SOURCE_DIR }}
run: |
$jdkSourcePath = Get-ChildItem -Path "build\*\images\jdk" -Directory | Select-Object -First 1 -ExpandProperty FullName
if (-not $jdkSourcePath) {
Write-Error "Could not find source JDK image directory";
exit 1
}
$releaseFile = Join-Path $jdkSourcePath "release"
$releaseContent = Get-Content $releaseFile -Raw | ConvertFrom-StringData -Delimiter '='
$javaVersion = $releaseContent.JAVA_VERSION.Trim('"')
echo "JAVA_VERSION_EXTRACTED=$javaVersion" >> $GITHUB_OUTPUT
$stagingDir = Join-Path $env:GITHUB_WORKSPACE "staging_artifact"
$targetDirName = "corretto-21-lilliput-${javaVersion}"
$fullTargetPathInStaging = Join-Path $stagingDir $targetDirName
if (Test-Path $stagingDir) { Remove-Item -Recurse -Force $stagingDir }
New-Item -ItemType Directory -Path $fullTargetPathInStaging | Out-Null
Move-Item -Path (Join-Path $jdkSourcePath "*") -Destination $fullTargetPathInStaging -Force
# 14. Upload Windows JDK Build Artifact
- name: Upload Windows JDK Build Artifact
uses: actions/upload-artifact@v4
with:
name: corretto-21-lilliput-${{ steps.prepare_artifact.outputs.JAVA_VERSION_EXTRACTED }}-windows-x64-jdk
path: staging_artifact/
Key Changes and Optimizations:
check_sha_and_decide_build (ubuntu-latest) checks if a build is needed. If needs_build is true, then build_corretto (windows-2025) runs.gh api to get the latest commit SHA from the upstream repo without checking out the code.C:\cygwin64\setup-x86_64.exe exists.$CYGWIN_PACKAGES).setup-x86_64.exe and installs the minimal Cygwin with required packages.Write-Host for debugging are kept, but unnecessary conditionals were streamlined.--with-debug-level=release and removal of .pdb/.map files.JAVA_VERSION from the release file.Note on PAT: Unfortunately, updating repository variables (like LAST_BUILT_CORRETTO_LILLIPUT_SHA) requires a repo-scoped PAT. GitHub Actions' built-in ${{ secrets.GITHUB_TOKEN }} doesn't have permissions to edit repository variables. Hence, MY_PAT secret is still needed.
Test this workflow by triggering it manually (workflow_dispatch) and monitor the runs. The first run might take longer due to Cygwin package installation, but subsequent runs should be faster thanks to caching.
Moscow Time Zone Scheduling: The cron 0 5 * * 1 correctly translates to 8:00 AM MSK (Moscow Time, UTC+3).
Let me know if any further tweaks are needed!