Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
10,589 additions
and
62,969 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import * as core from '@actions/core'; | ||
import {getOctokit} from '@actions/github'; | ||
import {retry} from '@octokit/plugin-retry'; | ||
import fs from 'fs'; | ||
|
||
const getCacheApiUrl = (): string => { | ||
const baseUrl: string = process.env['ACTIONS_CACHE_URL'] || ''; | ||
if (!baseUrl) { | ||
throw new Error('Cache Service Url not found, unable to restore cache.'); | ||
} | ||
|
||
const url = `${baseUrl}_apis/artifactcache/caches`; | ||
core.debug(`Resource Url: ${url}`); | ||
return url; | ||
}; | ||
|
||
const getRequestOptions = ( | ||
options?: Record<string, any> | ||
): Record<string, any> => ({ | ||
headers: {'X-GitHub-Api-Version': '2022-11-28', ...options} | ||
}); | ||
|
||
export const uploadFile = async ( | ||
filePath: string, | ||
repoToken: string, | ||
key: string, | ||
version: string | ||
): Promise<void> => { | ||
const resourceUrl = getCacheApiUrl(); | ||
const client = getOctokit(repoToken, undefined, retry); | ||
/* | ||
const fd = fs.openSync(filePath, 'r') | ||
const additionalHeaders = { | ||
// 'Content-Type': 'application/octet-stream', | ||
'X-GitHub-Api-Version': '2022-11-28', | ||
// 'Content-Range': `bytes 0-${size}/*` | ||
}*/ | ||
/* | ||
try { | ||
core.debug('Removing existing state'); | ||
await client.request( | ||
`DELETE ${resourceUrl}?key=${key}`, | ||
getRequestOptions() | ||
); | ||
core.debug('Existing state removed'); | ||
} catch (error) { | ||
if (error.response.status === 404) { | ||
core.debug('No state exists'); | ||
} else { | ||
core.warning(`Eroro: ${error.response.status} ${error.message}`); | ||
} | ||
} | ||
*/ | ||
let responseReserve; | ||
try { | ||
core.info('Store current state'); | ||
core.debug('Reserve cache'); | ||
const cacheSize = fs.statSync(filePath).size; | ||
|
||
const data = { | ||
key, | ||
version, | ||
cacheSize | ||
}; | ||
|
||
const dataSerialized = JSON.stringify(data, null, 2); | ||
|
||
const responseReserve = await client.request( | ||
`POST ${resourceUrl}`, | ||
getRequestOptions({ | ||
headers: { | ||
accept: 'application/json', | ||
'content-type': 'application/json' | ||
}, | ||
data: dataSerialized | ||
//...data | ||
}) | ||
); | ||
|
||
/* | ||
responseReserve = fetch(resourceUrl, { | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json' | ||
}, | ||
body: dataSerialized | ||
}); | ||
*/ | ||
core.debug( | ||
`========> reserve response: ${JSON.stringify(responseReserve)}` | ||
); | ||
} catch (error) { | ||
console.log({error}); | ||
Check failure on line 95 in src/classes/http-client/HttpClient.ts GitHub Actions / Basic validation / build (ubuntu-latest)
Check failure on line 95 in src/classes/http-client/HttpClient.ts GitHub Actions / Basic validation / build (windows-latest)
|
||
core.debug(`========> reserve error: ${JSON.stringify(error)}`); | ||
core.debug( | ||
`========> reserve error response: ${JSON.stringify(responseReserve)}` | ||
); | ||
} | ||
|
||
/* | ||
const uploadChunkResponse = await retryHttpClientResponse( | ||
`uploadChunk (start: ${start}, end: ${end})`, | ||
async () => | ||
httpClient.sendStream( | ||
'PATCH', | ||
resourceUrl, | ||
openStream(), | ||
additionalHeaders | ||
) | ||
) | ||
*/ | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import {IState} from '../interfaces/state'; | ||
import {State} from '../classes/state'; | ||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; | ||
|
||
export class StateService { | ||
static getState(): IState { | ||
return new State(); | ||
static getState(options: IIssuesProcessorOptions): IState { | ||
return new State(options); | ||
} | ||
} |