Skip to content

Commit

Permalink
fix: Update ciBuildId with jobId (cypress-io#175)
Browse files Browse the repository at this point in the history
When doing action re-run and providing the GH token, we should get an accurate job id
  • Loading branch information
estrada9166 committed Jul 7, 2020
1 parent 2613c73 commit 75bad87
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
27 changes: 17 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5916,6 +5916,12 @@ const getCiBuildId = async () => {
core.debug(`found the branch name ${branch}`)
}

// This will return the complete list of jobs for a run with their steps,
// this should always return data when there are jobs on the workflow.
// Every time the workflow is re-run the jobs length should stay the same
// (because the same amount of jobs were ran) but the id of them should change
// letting us, select the first id as unique id
// https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run
const runsList = await client.request(
'GET /repos/:owner/:repo/actions/runs/:run_id/jobs',
{
Expand All @@ -5925,16 +5931,17 @@ const getCiBuildId = async () => {
}
)

if (runsList && runsList.data) {
// Use the total_count, every time a job is restarted the list has
// the number of jobs including current run and previous runs, every time
// it appends the result.
core.debug(
`fetched run list with ${runsList.data.total_count} records`
)
parallelId = `${GITHUB_RUN_ID}-${runsList.data.total_count}`
if (
runsList &&
runsList.data &&
runsList.data.jobs &&
runsList.data.jobs.length
) {
const jobId = runsList.data.jobs[0].id
core.debug(`fetched run list with jobId ${jobId}`)
parallelId = `${GITHUB_RUN_ID}-${jobId}`
} else {
core.debug('could not get run list')
core.debug('could not get run list data')
}
}

Expand Down Expand Up @@ -24829,7 +24836,7 @@ module.exports = function isExtendable(val) {
/* 482 */
/***/ (function(module) {

module.exports = {"_from":"got","_id":"got@9.6.0","_inBundle":false,"_integrity":"sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==","_location":"/got","_phantomChildren":{"pump":"3.0.0"},"_requested":{"type":"tag","registry":true,"raw":"got","name":"got","escapedName":"got","rawSpec":"","saveSpec":null,"fetchSpec":"latest"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/got/-/got-9.6.0.tgz","_shasum":"edf45e7d67f99545705de1f7bbeeeb121765ed85","_spec":"got","_where":"/Users/gleb/git/github-action","ava":{"concurrency":4},"browser":{"decompress-response":false,"electron":false},"bugs":{"url":"https://github.com/sindresorhus/got/issues"},"bundleDependencies":false,"dependencies":{"@sindresorhus/is":"^0.14.0","@szmarczak/http-timer":"^1.1.2","cacheable-request":"^6.0.0","decompress-response":"^3.3.0","duplexer3":"^0.1.4","get-stream":"^4.1.0","lowercase-keys":"^1.0.1","mimic-response":"^1.0.1","p-cancelable":"^1.0.0","to-readable-stream":"^1.0.0","url-parse-lax":"^3.0.0"},"deprecated":false,"description":"Simplified HTTP requests","devDependencies":{"ava":"^1.1.0","coveralls":"^3.0.0","delay":"^4.1.0","form-data":"^2.3.3","get-port":"^4.0.0","np":"^3.1.0","nyc":"^13.1.0","p-event":"^2.1.0","pem":"^1.13.2","proxyquire":"^2.0.1","sinon":"^7.2.2","slow-stream":"0.0.4","tempfile":"^2.0.0","tempy":"^0.2.1","tough-cookie":"^3.0.0","xo":"^0.24.0"},"engines":{"node":">=8.6"},"files":["source"],"homepage":"https://github.com/sindresorhus/got#readme","keywords":["http","https","get","got","url","uri","request","util","utility","simple","curl","wget","fetch","net","network","electron"],"license":"MIT","main":"source","name":"got","repository":{"type":"git","url":"git+https://github.com/sindresorhus/got.git"},"scripts":{"release":"np","test":"xo && nyc ava"},"version":"9.6.0"};
module.exports = {"_args":[["got@9.6.0","/Users/alejandroestrada/Documents/Code/cypress/github-action"]],"_from":"got@9.6.0","_id":"got@9.6.0","_inBundle":false,"_integrity":"sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==","_location":"/got","_phantomChildren":{"pump":"3.0.0"},"_requested":{"type":"version","registry":true,"raw":"got@9.6.0","name":"got","escapedName":"got","rawSpec":"9.6.0","saveSpec":null,"fetchSpec":"9.6.0"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/got/-/got-9.6.0.tgz","_spec":"9.6.0","_where":"/Users/alejandroestrada/Documents/Code/cypress/github-action","ava":{"concurrency":4},"browser":{"decompress-response":false,"electron":false},"bugs":{"url":"https://github.com/sindresorhus/got/issues"},"dependencies":{"@sindresorhus/is":"^0.14.0","@szmarczak/http-timer":"^1.1.2","cacheable-request":"^6.0.0","decompress-response":"^3.3.0","duplexer3":"^0.1.4","get-stream":"^4.1.0","lowercase-keys":"^1.0.1","mimic-response":"^1.0.1","p-cancelable":"^1.0.0","to-readable-stream":"^1.0.0","url-parse-lax":"^3.0.0"},"description":"Simplified HTTP requests","devDependencies":{"ava":"^1.1.0","coveralls":"^3.0.0","delay":"^4.1.0","form-data":"^2.3.3","get-port":"^4.0.0","np":"^3.1.0","nyc":"^13.1.0","p-event":"^2.1.0","pem":"^1.13.2","proxyquire":"^2.0.1","sinon":"^7.2.2","slow-stream":"0.0.4","tempfile":"^2.0.0","tempy":"^0.2.1","tough-cookie":"^3.0.0","xo":"^0.24.0"},"engines":{"node":">=8.6"},"files":["source"],"homepage":"https://github.com/sindresorhus/got#readme","keywords":["http","https","get","got","url","uri","request","util","utility","simple","curl","wget","fetch","net","network","electron"],"license":"MIT","main":"source","name":"got","repository":{"type":"git","url":"git+https://github.com/sindresorhus/got.git"},"scripts":{"release":"np","test":"xo && nyc ava"},"version":"9.6.0"};

/***/ }),
/* 483 */,
Expand Down
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ const getCiBuildId = async () => {
core.debug(`found the branch name ${branch}`)
}

// This will return the complete list of jobs for a run with their steps,
// this should always return data when there are jobs on the workflow.
// Every time the workflow is re-run the jobs length should stay the same
// (because the same amount of jobs were ran) but the id of them should change
// letting us, select the first id as unique id
// https://docs.github.com/en/rest/reference/actions#list-jobs-for-a-workflow-run
const runsList = await client.request(
'GET /repos/:owner/:repo/actions/runs/:run_id/jobs',
{
Expand All @@ -348,16 +354,17 @@ const getCiBuildId = async () => {
}
)

if (runsList && runsList.data) {
// Use the total_count, every time a job is restarted the list has
// the number of jobs including current run and previous runs, every time
// it appends the result.
core.debug(
`fetched run list with ${runsList.data.total_count} records`
)
parallelId = `${GITHUB_RUN_ID}-${runsList.data.total_count}`
if (
runsList &&
runsList.data &&
runsList.data.jobs &&
runsList.data.jobs.length
) {
const jobId = runsList.data.jobs[0].id
core.debug(`fetched run list with jobId ${jobId}`)
parallelId = `${GITHUB_RUN_ID}-${jobId}`
} else {
core.debug('could not get run list')
core.debug('could not get run list data')
}
}

Expand Down

0 comments on commit 75bad87

Please sign in to comment.