-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfilters.ts
More file actions
85 lines (70 loc) · 3.06 KB
/
filters.ts
File metadata and controls
85 lines (70 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import * as ghCore from "@actions/core";
import { getOS, getArch } from "./utils";
import { InstallableClient } from "./types";
import { canExtract } from "./unzip";
type ClientFilterFunc = ((filename: string) => boolean);
export function filterClients(clientFiles: string[], filterFuncs: ClientFilterFunc[]): string[] {
let filteredClientFiles = clientFiles;
for (const filterFunc of filterFuncs) {
if (filteredClientFiles.length <= 1) {
ghCore.debug(`${filteredClientFiles.length} clients remaining; skipping ${filterFunc.name}.`);
continue; // remaining filters will also be skipped.
}
filteredClientFiles = filteredClientFiles.filter(filterFunc);
ghCore.debug(`After ${filterFunc.name}, ${filteredClientFiles.length} files remain.`);
}
return filteredClientFiles;
}
/* eslint-disable no-invalid-this */
/**
* For the ocp executables, the openshift client and installer executables are mixed into one directory.
* @param this The name of the client executable.
*/
export function filterByExecutable(this: InstallableClient, filename: string): boolean {
if (this === "oc") {
// oc is short for openshift-client, which is what the files are named.
return filename.includes("openshift-client");
}
return filename.includes(this);
}
/**
* For the ocp executables, there are two copies of each - one versioned, one not.
* @param this The version of the client executable to do a substring match on.
*/
export function filterByVersioned(this: string, filename: string): boolean {
return filename.includes(this);
}
export function filterByOS(filename: string): boolean {
// changing file name to lower case, as some files also have OS written in upper case letters
const fileNameLowercase = filename.toLowerCase();
const os = getOS();
if (os === "macos") {
return fileNameLowercase.includes("mac") || fileNameLowercase.includes("darwin");
}
if (os === "windows") {
return fileNameLowercase.includes("win") && !fileNameLowercase.includes("darwin");
}
return fileNameLowercase.includes("linux");
}
const ALL_ARCH_IDENTIFIERS = [ "amd64", "x86_64", "64bit", "arm64", "aarch64", "ppc64le", "s390x" ];
function hasNoArchIndicator(fileNameLowercase: string): boolean {
return ALL_ARCH_IDENTIFIERS.every((id) => !fileNameLowercase.includes(id));
}
export function filterByArch(filename: string): boolean {
const fileNameLowercase = filename.toLowerCase();
const arch = getArch();
if (arch === "arm64") {
return fileNameLowercase.includes(arch) || fileNameLowercase.includes("aarch64");
}
if (arch === "amd64") {
return fileNameLowercase.includes(arch) || fileNameLowercase.includes("64bit")
|| fileNameLowercase.includes("x86_64") || hasNoArchIndicator(fileNameLowercase);
}
return fileNameLowercase.includes(arch);
}
export function filterByZipped(filename: string): boolean {
return canExtract(filename);
}
export function filterByNotZipped(filename: string): boolean {
return !canExtract(filename);
}