Unverified Commit 4fbd0bd1 authored by Bruno Borges's avatar Bruno Borges Committed by GitHub
Browse files

fix: select musl JDK artifacts on Alpine for five distributions (#1220)

On Alpine, `getPlatformOption()` returned the glibc platform key for
Dragonwell, Corretto, Zulu, Liberica and Liberica NIK, so the action
resolved and installed a glibc JDK that cannot run under musl.

Add a shared `isAlpineLinux()` helper and use it to select each vendor's
musl artifacts:

| distribution | glibc         | musl           |
| ------------ | ------------- | -------------- |
| Dragonwell   | `linux`       | `alpine-linux` |
| Corretto     | `linux`       | `alpine`       |
| Zulu         | `linux_glibc` | `linux_musl`   |
| Liberica     | `linux`       | `linux-musl`   |
| Liberica NIK | `linux`       | `linux-musl`   |

Each key was verified against the vendor's live metadata API or manifest.

There is deliberately no silent fallback to glibc when a vendor has no
musl build for the requested version or architecture: the existing "could
not find a version that satisfies" error fires instead. This matches the
behaviour Temurin and SapMachine already have, and a glibc JDK would not
run on musl anyway.

Co-authored-by: default avatarCopilot App <[email protected]>
Copilot-Session: 74248bb0-72af-41d8-b85d-b0f5836e68db
parent d0e61fe7
Loading
Loading
Loading
Loading
+48
Changes for __tests__/distributors/corretto-installer.test.ts: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import {
  beforeAll,
  afterAll
} from '@jest/globals';
import fs from 'fs';
import type {JavaInstallerOptions} from '../../src/distributions/base-models.js';
import {HttpClient} from '@actions/http-client';

@@ -323,3 +324,50 @@ describe('getAvailableVersions', () => {
    spyGetDownloadArchiveExtension.mockReturnValue(mockedExtension);
  };
});

describe('Corretto getPlatformOption libc selection', () => {
  const originalPlatform = Object.getOwnPropertyDescriptor(
    process,
    'platform'
  ) as PropertyDescriptor;

  const setPlatform = (platform: NodeJS.Platform) =>
    Object.defineProperty(process, 'platform', {
      ...originalPlatform,
      value: platform
    });

  const distribution = new CorrettoDistribution({
    version: '21',
    architecture: 'x64',
    packageType: 'jdk',
    checkLatest: false
  });

  afterEach(() => {
    Object.defineProperty(process, 'platform', originalPlatform);
    jest.restoreAllMocks();
  });

  it('selects the musl artifacts on Alpine', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(true);

    expect(distribution['getPlatformOption']()).toBe('alpine');
  });

  it('selects the glibc artifacts on other Linux runners', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);

    expect(distribution['getPlatformOption']()).toBe('linux');
  });

  it('does not probe for Alpine off Linux', () => {
    setPlatform('darwin');
    const existsSync = jest.spyOn(fs, 'existsSync');

    expect(distribution['getPlatformOption']()).toBe('macos');
    expect(existsSync).not.toHaveBeenCalled();
  });
});
+48
Changes for __tests__/distributors/dragonwell-installer.test.ts: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import {
  beforeAll,
  afterAll
} from '@jest/globals';
import fs from 'fs';
import {HttpClient} from '@actions/http-client';

import manifestData from '../data/dragonwell.json' with {type: 'json'};
@@ -307,3 +308,50 @@ describe('getAvailableVersions', () => {
    });
  });
});

describe('Dragonwell getPlatformOption libc selection', () => {
  const originalPlatform = Object.getOwnPropertyDescriptor(
    process,
    'platform'
  ) as PropertyDescriptor;

  const setPlatform = (platform: NodeJS.Platform) =>
    Object.defineProperty(process, 'platform', {
      ...originalPlatform,
      value: platform
    });

  const distribution = new DragonwellDistribution({
    version: '21',
    architecture: 'x64',
    packageType: 'jdk',
    checkLatest: false
  });

  afterEach(() => {
    Object.defineProperty(process, 'platform', originalPlatform);
    jest.restoreAllMocks();
  });

  it('selects the musl artifacts on Alpine', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(true);

    expect(distribution['getPlatformOption']()).toBe('alpine-linux');
  });

  it('selects the glibc artifacts on other Linux runners', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);

    expect(distribution['getPlatformOption']()).toBe('linux');
  });

  it('does not probe for Alpine off Linux', () => {
    setPlatform('win32');
    const existsSync = jest.spyOn(fs, 'existsSync');

    expect(distribution['getPlatformOption']()).toBe('windows');
    expect(existsSync).not.toHaveBeenCalled();
  });
});
+43
Changes for __tests__/distributors/liberica-installer.test.ts: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import {
  beforeAll,
  afterAll
} from '@jest/globals';
import fs from 'fs';
import type {
  ArchitectureOptions,
  LibericaVersion
@@ -260,6 +261,16 @@ describe('findPackageForDownload', () => {
});

describe('getPlatformOption', () => {
  beforeEach(() => {
    // The linux row below is glibc, so pin the Alpine probe rather than
    // letting it depend on the machine running the suite.
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  const distributions = new LibericaDistributions({
    architecture: 'x64',
    version: '11',
@@ -335,3 +346,35 @@ describe('convertVersionToSemver', () => {
    expect(actual).toEqual(expected);
  });
});

describe('Liberica getPlatformOption libc selection', () => {
  const distributions = new LibericaDistributions({
    architecture: 'x64',
    version: '11',
    packageType: 'jdk',
    checkLatest: false
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  it('selects the musl artifacts on Alpine', () => {
    jest.spyOn(fs, 'existsSync').mockReturnValue(true);

    expect(distributions['getPlatformOption']('linux')).toBe('linux-musl');
  });

  it('selects the glibc artifacts on other Linux runners', () => {
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);

    expect(distributions['getPlatformOption']('linux')).toBe('linux');
  });

  it('does not probe for Alpine off Linux', () => {
    const existsSync = jest.spyOn(fs, 'existsSync');

    expect(distributions['getPlatformOption']('darwin')).toBe('macos');
    expect(existsSync).not.toHaveBeenCalled();
  });
});
+43
Changes for __tests__/distributors/liberica-nik-installer.test.ts: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
import {jest, describe, it, expect, beforeEach, afterEach} from '@jest/globals';
import fs from 'fs';
import type {
  ArchitectureOptions,
  NikVersion
@@ -170,6 +171,16 @@ describe('findPackageForDownload', () => {
});

describe('getPlatformOption', () => {
  beforeEach(() => {
    // The linux row below is glibc, so pin the Alpine probe rather than
    // letting it depend on the machine running the suite.
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  const distributions = new LibericaNikDistributions({
    architecture: 'x64',
    version: '21',
@@ -217,3 +228,35 @@ describe('convertVersionToSemver', () => {
    expect(actual).toEqual(expected);
  });
});

describe('Liberica NIK getPlatformOption libc selection', () => {
  const distributions = new LibericaNikDistributions({
    architecture: 'x64',
    version: '21',
    packageType: 'jdk',
    checkLatest: false
  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  it('selects the musl artifacts on Alpine', () => {
    jest.spyOn(fs, 'existsSync').mockReturnValue(true);

    expect(distributions['getPlatformOption']('linux')).toBe('linux-musl');
  });

  it('selects the glibc artifacts on other Linux runners', () => {
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);

    expect(distributions['getPlatformOption']('linux')).toBe('linux');
  });

  it('does not probe for Alpine off Linux', () => {
    const existsSync = jest.spyOn(fs, 'existsSync');

    expect(distributions['getPlatformOption']('darwin')).toBe('macos');
    expect(existsSync).not.toHaveBeenCalled();
  });
});
+48
Changes for __tests__/distributors/zulu-installer.test.ts: 48 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import {
  beforeAll,
  afterAll
} from '@jest/globals';
import fs from 'fs';
import type {IZuluVersions} from '../../src/distributions/zulu/models.js';
import {HttpClient} from '@actions/http-client';
import os from 'os';
@@ -346,3 +347,50 @@ describe('findPackageForDownload', () => {
    ).rejects.toThrow(/No matching version found for SemVer/);
  });
});

describe('Zulu getPlatformOption libc selection', () => {
  const originalPlatform = Object.getOwnPropertyDescriptor(
    process,
    'platform'
  ) as PropertyDescriptor;

  const setPlatform = (platform: NodeJS.Platform) =>
    Object.defineProperty(process, 'platform', {
      ...originalPlatform,
      value: platform
    });

  const distribution = new ZuluDistribution({
    version: '21',
    architecture: 'x64',
    packageType: 'jdk',
    checkLatest: false
  });

  afterEach(() => {
    Object.defineProperty(process, 'platform', originalPlatform);
    jest.restoreAllMocks();
  });

  it('selects the musl artifacts on Alpine', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(true);

    expect(distribution['getPlatformOption']()).toBe('linux_musl');
  });

  it('selects the glibc artifacts on other Linux runners', () => {
    setPlatform('linux');
    jest.spyOn(fs, 'existsSync').mockReturnValue(false);

    expect(distribution['getPlatformOption']()).toBe('linux_glibc');
  });

  it('does not probe for Alpine off Linux', () => {
    setPlatform('win32');
    const existsSync = jest.spyOn(fs, 'existsSync');

    expect(distribution['getPlatformOption']()).toBe('windows');
    expect(existsSync).not.toHaveBeenCalled();
  });
});
Loading