Compare commits

...

6 Commits

Author SHA1 Message Date
Cedric Wille 6d304fe599 Fix linter 2023-06-19 16:39:28 -04:00
Cedric Wille 8cf7e029de Add abort of stalled download
There is a known issue with Azure Blob Storage which sometimes causes downloads to stall. This commit adds logic to abort any download that is hanging for more than 2 minutes
2023-06-19 16:21:37 -04:00
Francesco Renzi a6bf8726aa Merge pull request #1430 from actions/add-mask-docs
Update docs for setSecret
2023-05-25 11:17:42 +01:00
Francesco Renzi ae9272d5cb Update docs/commands.md
Co-authored-by: JoannaaKL <joannaakl@github.com>
2023-05-25 11:07:37 +01:00
Francesco Renzi f481b8c8dc Update docs for setSecret 2023-05-25 11:00:25 +01:00
Francesco Renzi 59851786d4 Add tests to ensure secrets are escaped 2023-05-25 10:59:41 +01:00
3 changed files with 56 additions and 3 deletions
+12 -1
View File
@@ -50,7 +50,18 @@ function setSecret(secret: string): void {}
Now, future logs containing BAR will be masked. E.g. running `echo "Hello FOO BAR World"` will now print `Hello FOO **** World`.
**WARNING** The add-mask and setSecret commands only support single line secrets. To register a multiline secrets you must register each line individually otherwise it will not be masked.
**WARNING** The add-mask and setSecret commands only support single-line
secrets or multi-line secrets that have been escaped. `@actions/core`
`setSecret` will escape the string you provide by default. When an escaped
multi-line string is provided the whole string and each of its lines
individually will be masked. For example you can mask `first\nsecond\r\nthird`
using:
```sh
echo "::add-mask::first%0Asecond%0D%0Athird"
```
This will mask `first%0Asecond%0D%0Athird`, `first`, `second` and `third`.
**WARNING** Do **not** mask short values if you can avoid it, it could render your output unreadable (and future steps' output as well).
For example, if you mask the letter `l`, running `echo "Hello FOO BAR World"` will now print `He*********o FOO BAR Wor****d`
+39 -1
View File
@@ -37,9 +37,12 @@ export class DownloadProgress {
segmentSize: number
segmentOffset: number
receivedBytes: number
previouslyReceivedBytes: number
lastTimeOfNewBytes?: number
startTime: number
displayedComplete: boolean
timeoutHandle?: ReturnType<typeof setTimeout>
abortController?: AbortController
constructor(contentLength: number) {
this.contentLength = contentLength
@@ -47,8 +50,11 @@ export class DownloadProgress {
this.segmentSize = 0
this.segmentOffset = 0
this.receivedBytes = 0
this.previouslyReceivedBytes = 0
this.lastTimeOfNewBytes = undefined
this.displayedComplete = false
this.startTime = Date.now()
this.abortController = undefined
}
/**
@@ -62,6 +68,7 @@ export class DownloadProgress {
this.segmentIndex = this.segmentIndex + 1
this.segmentSize = segmentSize
this.receivedBytes = 0
this.previouslyReceivedBytes = 0
core.debug(
`Downloading segment at offset ${this.segmentOffset} with length ${this.segmentSize}...`
@@ -84,6 +91,22 @@ export class DownloadProgress {
return this.segmentOffset + this.receivedBytes
}
setLastTimeOfNewBytes(): void {
this.lastTimeOfNewBytes = Date.now()
}
getLastTimeOfNewBytes(): number | undefined {
return this.lastTimeOfNewBytes
}
setAbortController(abortReference: AbortController): void {
this.abortController = abortReference
}
triggerAbortController(): void {
this.abortController?.abort()
}
/**
* Returns true if the download is complete.
*/
@@ -125,7 +148,21 @@ export class DownloadProgress {
*/
onProgress(): (progress: TransferProgressEvent) => void {
return (progress: TransferProgressEvent) => {
this.setReceivedBytes(progress.loadedBytes)
if (progress.loadedBytes > this.getTransferredBytes()) {
this.setReceivedBytes(progress.loadedBytes)
this.setLastTimeOfNewBytes()
} else {
// if download hanging for more than 2 minutes
if (
this.getLastTimeOfNewBytes() !== undefined &&
Date.now() - this.getLastTimeOfNewBytes()! > 120000
) {
this.triggerAbortController()
throw new Error(
'Aborting cache download as the download has stalled for more than 2 minutes.'
)
}
}
}
}
@@ -252,6 +289,7 @@ export async function downloadCacheStorageSDK(
try {
downloadProgress.startDisplayTimer()
const controller = new AbortController()
downloadProgress.setAbortController(controller)
const abortSignal = controller.signal
while (!downloadProgress.isDone()) {
const segmentStart =
+5 -1
View File
@@ -161,7 +161,11 @@ describe('@actions/core', () => {
it('setSecret produces the correct command', () => {
core.setSecret('secret val')
assertWriteCalls([`::add-mask::secret val${os.EOL}`])
core.setSecret('multi\nline\r\nsecret')
assertWriteCalls([
`::add-mask::secret val${os.EOL}`,
`::add-mask::multi%0Aline%0D%0Asecret${os.EOL}`
])
})
it('prependPath produces the correct commands and sets the env', () => {