2023-11-20 15:03:58 +00:00
|
|
|
import os from 'os'
|
2025-01-08 17:53:44 +00:00
|
|
|
import {info} from '@actions/core'
|
2023-11-20 15:03:58 +00:00
|
|
|
|
2023-08-10 15:28:41 -04:00
|
|
|
// Used for controlling the highWaterMark value of the zip that is being streamed
|
|
|
|
|
// The same value is used as the chunk size that is use during upload to blob storage
|
|
|
|
|
export function getUploadChunkSize(): number {
|
|
|
|
|
return 8 * 1024 * 1024 // 8 MB Chunks
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 09:23:14 -07:00
|
|
|
export function getRuntimeToken(): string {
|
|
|
|
|
const token = process.env['ACTIONS_RUNTIME_TOKEN']
|
|
|
|
|
if (!token) {
|
2023-08-09 10:30:44 -04:00
|
|
|
throw new Error('Unable to get the ACTIONS_RUNTIME_TOKEN env variable')
|
2023-08-04 09:23:14 -07:00
|
|
|
}
|
|
|
|
|
return token
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getResultsServiceUrl(): string {
|
|
|
|
|
const resultsUrl = process.env['ACTIONS_RESULTS_URL']
|
|
|
|
|
if (!resultsUrl) {
|
2023-08-09 10:30:50 -04:00
|
|
|
throw new Error('Unable to get the ACTIONS_RESULTS_URL env variable')
|
2023-08-04 09:23:14 -07:00
|
|
|
}
|
2023-11-20 18:06:44 +00:00
|
|
|
|
|
|
|
|
return new URL(resultsUrl).origin
|
2023-08-04 09:23:14 -07:00
|
|
|
}
|
2023-08-09 17:42:14 -07:00
|
|
|
|
|
|
|
|
export function isGhes(): boolean {
|
|
|
|
|
const ghUrl = new URL(
|
|
|
|
|
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
|
|
|
)
|
2024-01-30 21:55:50 +00:00
|
|
|
|
|
|
|
|
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
2024-01-31 16:51:04 +00:00
|
|
|
const isGitHubHost = hostname === 'GITHUB.COM'
|
2024-07-03 16:55:53 +00:00
|
|
|
const isGheHost = hostname.endsWith('.GHE.COM')
|
|
|
|
|
const isLocalHost = hostname.endsWith('.LOCALHOST')
|
2024-01-30 21:55:50 +00:00
|
|
|
|
2024-07-03 16:55:53 +00:00
|
|
|
return !isGitHubHost && !isGheHost && !isLocalHost
|
2023-08-09 17:42:14 -07:00
|
|
|
}
|
2023-08-22 11:44:38 -07:00
|
|
|
|
|
|
|
|
export function getGitHubWorkspaceDir(): string {
|
|
|
|
|
const ghWorkspaceDir = process.env['GITHUB_WORKSPACE']
|
|
|
|
|
if (!ghWorkspaceDir) {
|
|
|
|
|
throw new Error('Unable to get the GITHUB_WORKSPACE env variable')
|
|
|
|
|
}
|
|
|
|
|
return ghWorkspaceDir
|
|
|
|
|
}
|
2023-11-20 15:03:58 +00:00
|
|
|
|
2025-02-20 16:55:54 +00:00
|
|
|
// The maximum value of concurrency is 300.
|
|
|
|
|
// This value can be changed with ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY variable.
|
2023-11-20 16:46:08 +00:00
|
|
|
export function getConcurrency(): number {
|
2025-01-08 17:53:44 +00:00
|
|
|
const numCPUs = os.cpus().length
|
|
|
|
|
let concurrencyCap = 32
|
|
|
|
|
|
|
|
|
|
if (numCPUs > 4) {
|
|
|
|
|
const concurrency = 16 * numCPUs
|
|
|
|
|
concurrencyCap = concurrency > 300 ? 300 : concurrency
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-08 20:32:45 +00:00
|
|
|
const concurrencyOverride = process.env['ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY']
|
2025-01-08 17:53:44 +00:00
|
|
|
if (concurrencyOverride) {
|
|
|
|
|
const concurrency = parseInt(concurrencyOverride)
|
2025-01-08 18:14:04 +00:00
|
|
|
if (isNaN(concurrency) || concurrency < 1) {
|
2025-01-08 17:53:44 +00:00
|
|
|
throw new Error(
|
2025-01-08 20:32:45 +00:00
|
|
|
'Invalid value set for ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY env variable'
|
2025-01-08 17:53:44 +00:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (concurrency < concurrencyCap) {
|
2025-02-20 16:55:54 +00:00
|
|
|
info(
|
|
|
|
|
`Set concurrency based on the value set in ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY.`
|
|
|
|
|
)
|
2025-01-08 17:53:44 +00:00
|
|
|
return concurrency
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info(
|
2025-02-20 16:55:54 +00:00
|
|
|
`ACTIONS_ARTIFACT_UPLOAD_CONCURRENCY is higher than the cap of ${concurrencyCap} based on the number of cpus. Set it to the maximum value allowed.`
|
2025-01-08 17:53:44 +00:00
|
|
|
)
|
2025-02-20 16:55:54 +00:00
|
|
|
return concurrencyCap
|
2025-01-08 17:53:44 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-20 16:55:54 +00:00
|
|
|
// default concurrency to 5
|
|
|
|
|
return 5
|
2025-01-08 16:19:09 +00:00
|
|
|
}
|
2023-11-20 15:03:58 +00:00
|
|
|
|
2025-01-08 16:19:09 +00:00
|
|
|
export function getUploadChunkTimeout(): number {
|
2025-01-08 20:32:45 +00:00
|
|
|
const timeoutVar = process.env['ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS']
|
2025-01-08 16:19:09 +00:00
|
|
|
if (!timeoutVar) {
|
|
|
|
|
return 300000 // 5 minutes
|
2023-11-20 15:03:58 +00:00
|
|
|
}
|
|
|
|
|
|
2025-01-08 16:19:09 +00:00
|
|
|
const timeout = parseInt(timeoutVar)
|
|
|
|
|
if (isNaN(timeout)) {
|
2025-01-08 17:53:44 +00:00
|
|
|
throw new Error(
|
2025-01-08 20:32:45 +00:00
|
|
|
'Invalid value set for ACTIONS_ARTIFACT_UPLOAD_TIMEOUT_MS env variable'
|
2025-01-08 17:53:44 +00:00
|
|
|
)
|
2025-01-08 16:19:09 +00:00
|
|
|
}
|
2024-07-23 21:57:39 -04:00
|
|
|
|
2025-01-08 16:19:09 +00:00
|
|
|
return timeout
|
2024-07-23 21:57:39 -04:00
|
|
|
}
|
2025-10-21 09:22:11 -04:00
|
|
|
|
|
|
|
|
// This value can be changed with ACTIONS_ARTIFACT_MAX_ARTIFACT_COUNT variable.
|
|
|
|
|
// Defaults to 1000 as a safeguard for rate limiting.
|
|
|
|
|
export function getMaxArtifactListCount(): number {
|
2025-10-22 11:42:01 -04:00
|
|
|
const maxCountVar =
|
|
|
|
|
process.env['ACTIONS_ARTIFACT_MAX_ARTIFACT_COUNT'] || '1000'
|
2025-10-21 09:22:11 -04:00
|
|
|
|
|
|
|
|
const maxCount = parseInt(maxCountVar)
|
|
|
|
|
if (isNaN(maxCount) || maxCount < 1) {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Invalid value set for ACTIONS_ARTIFACT_MAX_ARTIFACT_COUNT env variable'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return maxCount
|
|
|
|
|
}
|