Skip to content

Commit

Permalink
add to Ninja catalog releases from https://github.com/ninja-build/nin…
Browse files Browse the repository at this point in the history
…ja/releases which contains v1.12.1
  • Loading branch information
lukka committed Jun 3, 2024
1 parent 38eb670 commit 8aac955
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .latest_ninja_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.11.1
1.12.1
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2020-2021-2022-2023 Luca Cappa
Copyright (c) 2020-2021-2022-2023-2024 Luca Cappa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,5 @@ The software is provided as is, there is no warranty of any kind. All users are
# License
All the content in this repository is licensed under the [MIT License](LICENSE.txt).

Copyright (c) 2020-2021-2022-2023 Luca Cappa
Copyright (c) 2020-2021-2022-2023-2024 Luca Cappa

2 changes: 1 addition & 1 deletion __tests__/action_succeeded.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test('testing get-cmake action success with specific cmake versions', async () =
"3.25.0-rc4", "3.25.0-rc3"]) {
process.env.RUNNER_TEMP = os.tmpdir();
process.env["CUSTOM_CMAKE_VERSION"] = version;
process.env["CUSTOM_NINJA_VERSION"] = '~1.10.0';
process.env["CUSTOM_NINJA_VERSION"] = '~1.12.1';
await getcmake.main();
expect(coreSetFailed).toBeCalledTimes(0);
expect(coreError).toBeCalledTimes(0);
Expand Down
44 changes: 23 additions & 21 deletions __tests__/generate.catalog.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022 Luca Cappa
// Copyright (c) 2022-2024 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT

Expand All @@ -17,7 +17,7 @@ import { restEndpointMethods } from '@octokit/plugin-rest-endpoint-methods';
// 1 hour in milliseconds.
jest.setTimeout(60 * 60 * 1000)

function writeLatestToFile(map: rc.MostRecentReleases, releaseName: string, platform: string, filename: string) {
function writeLatestToFile(map: rc.MostRecentReleases, releaseName: string, platform: string, filename: string): void {
const value = map.get(releaseName)?.get(platform)?.mostRecentVersion?.version;
if (!value)
throw new Error(`Cannot get the '${releaseName}' for ${platform}`);
Expand Down Expand Up @@ -96,26 +96,28 @@ test.only('generate catalog of all CMake and Ninja releases ...', async () => {
writeLatestToFile(cmakeMostRecentRelease, 'latest', process.platform, ".latest_cmake_version");
writeLatestToFile(cmakeMostRecentRelease, 'latestrc', process.platform, ".latestrc_cmake_version");

await octokit.paginate('GET /repos/Kitware/ninja/releases', {
owner: 'Kitware',
repo: 'ninja',
per_page: 30,
},
(response: any) => {
for (const rel of response.data) {
try {
const assets = rel.assets as rc.Asset[];
assets.forEach((t) => t.tag_name = rel.tag_name);
ninjaCollector.track(assets);
for (const path of ['/repos/Kitware/ninja/releases', '/repos/ninja-build/ninja/releases']) {
await octokit.paginate(`GET ${path}`, {
owner: path.split('/')[2],
repo: 'ninja',
per_page: 30,
},
(response: any) => {
for (const rel of response.data) {
try {
const assets = rel.assets as rc.Asset[];
assets.forEach((t) => t.tag_name = rel.tag_name);
ninjaCollector.track(assets);
}
catch (err: any) {
console.log("Warning: " + err);
}
}
catch (err: any) {
console.log("Warning: " + err);
}
}
}).catch((err: any) => {
console.log(`Failure during HTTP download and parsing of Ninja releases: ${err as Error}`);
throw err;
});
}).catch((err: any) => {
console.log(`Failure during HTTP download and parsing of Ninja releases: ${err as Error}`);
throw err;
});
};

console.log(`Found ${Object.keys(ninjaReleasesMap).length} releases: `);
for (const relVersion in ninjaReleasesMap) {
Expand Down
59 changes: 55 additions & 4 deletions dist/index.js

Large diffs are not rendered by default.

37 changes: 33 additions & 4 deletions src/get-cmake.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) 2020-2021-2022-2023-2024 Luca Cappa
// Released under the term specified in file LICENSE.txt

// SPDX short identifier: MIT

import * as cache from '@actions/cache';
Expand All @@ -12,7 +13,6 @@ import { SemVer, maxSatisfying } from 'semver';
import * as catalog from './releases-catalog'
import * as shared from './releases-collector'
import { hashCode } from './utils'
import { platform } from 'os';

const extractFunction: { [key: string]: { (url: string, outputPath: string): Promise<string> } } = {
'.tar.gz': tools.extractTar,
Expand Down Expand Up @@ -185,7 +185,7 @@ export class ToolsGetter {
}
}

private isWindows() : boolean{
private isWindows(): boolean {
return (process.platform === 'win32');
}

Expand All @@ -194,7 +194,7 @@ export class ToolsGetter {
private async fixUpNinjaExeName(ninjaPath: string): Promise<void> {
core.debug(`fixUpNinjaExeName(${ninjaPath})<<<`);
try {
const ninjaExeFileName = this.isWindows() ? 'ninja.exe': 'ninja';
const ninjaExeFileName = this.isWindows() ? 'ninja.exe' : 'ninja';
const files = await fs.readdir(ninjaPath);
for (const file of files) {
core.debug(`Processing: '${file}'.`);
Expand Down Expand Up @@ -306,10 +306,24 @@ export class ToolsGetter {

await core.group("Downloading and extracting Ninja", async () => {
const downloaded = await tools.downloadTool(ninjaPackage.url);
await this.extract(ninjaPackage.dropSuffix, downloaded, outputPath);
await this.extract(ToolsGetter.getArchiveExtension(ninjaPackage.fileName), downloaded, outputPath);
});
}

private static getArchiveExtension(archivePath?: string): string {
if (!archivePath) {
throw new Error(`Invalid archivePath passed to getArchiveExtension()`);
}
const urlLower = archivePath.toLowerCase();
if (urlLower.endsWith('.tar.gz')) {
return '.tar.gz';
} else if (urlLower.endsWith('.zip')) {
return '.zip';
} else {
throw new Error(`Unknown archive extension for '${archivePath}'`);
}
}

private static hashToFakeSemver(hashedKey: number): string {
// Since the key may be negative and needs to drop the sign to work good as
// a major version number, let's ensure an unique version by switching the patch part.
Expand All @@ -318,6 +332,18 @@ export class ToolsGetter {
}
}

function forceExit(exitCode: number) {
// work around for:
// - https://github.com/lukka/get-cmake/issues/136
// - https://github.com/nodejs/node/issues/47228

// Avoid this workaround when running mocked unit tests.
if (process.env.JEST_WORKER_ID)
return;

process.exit(exitCode);
}

export async function main(): Promise<void> {
try {
const cmakeGetter: ToolsGetter = new ToolsGetter(
Expand All @@ -326,6 +352,7 @@ export async function main(): Promise<void> {
await cmakeGetter.run();
core.info('get-cmake action execution succeeded');
process.exitCode = 0;
forceExit(0);
} catch (err) {
const error: Error = err as Error;
if (error?.stack) {
Expand All @@ -334,5 +361,7 @@ export async function main(): Promise<void> {
const errorAsString = (err ?? "undefined error").toString();
core.setFailed(`get-cmake action execution failed: '${errorAsString}'`);
process.exitCode = -1000;

forceExit(-1000);
}
}
2 changes: 1 addition & 1 deletion src/releases-catalog.ts

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion src/releases-collector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Luca Cappa
// Copyright (c) 2022-2023-2024 Luca Cappa
// Released under the term specified in file LICENSE.txt
// SPDX short identifier: MIT

Expand Down Expand Up @@ -78,6 +78,31 @@ export class NinjaFilters {
dropSuffix: '.tar.gz',
suffix: "universal-apple-darwin.tar.gz",
platform: macosPlatform,
}, {
binPath: "",
dropSuffix: 'ninja-linux-aarch64.zip',
suffix: "ninja-linux-aarch64.zip",
platform: linuxArmPlatform,
}, {
binPath: "",
dropSuffix: 'ninja-linux.zip',
suffix: "ninja-linux.zip",
platform: linuxX64Platform,
}, {
binPath: "",
dropSuffix: 'ninja-win.zip',
suffix: "ninja-win.zip",
platform: windowsPlatform,
}, {
binPath: "",
dropSuffix: 'ninja-winarm64.zip',
suffix: "ninja-winarm64.zip",
platform: windowsArmPlatform,
}, {
binPath: "",
dropSuffix: 'ninja-mac.zip',
suffix: "ninja-mac.zip",
platform: macosPlatform,
}];

public static readonly allFilters: ReleaseFilter[] =
Expand Down

0 comments on commit 8aac955

Please sign in to comment.