Skip to content

Commit 77d7e65

Browse files
authored
add script to rerun workflow a specific number of times (#6689)
1 parent 62f875d commit 77d7e65

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

scripts/rerun.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict'
2+
3+
// Example to rerun the Serverless workflow 30 times on the current branch:
4+
// GITHUB_TOKEN=$(ddtool auth github token) WORKFLOW=Serverless node scripts/rerun
5+
6+
const { execSync } = require('child_process')
7+
8+
const {
9+
ATTEMPTS = 30,
10+
BRANCH,
11+
INTERVAL = 600,
12+
WORKFLOW
13+
} = process.env
14+
15+
function rerun (current = 1) {
16+
const branch = BRANCH || execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
17+
const result = execSync(`gh run ls -b ${branch} -w ${WORKFLOW}`).toString()
18+
const id = result.match(/\d{11}/)[0]
19+
20+
execSync(`gh run rerun ${id} --repo DataDog/dd-trace-js || exit 0`)
21+
22+
if (current >= ATTEMPTS) return
23+
24+
setTimeout(() => rerun(current + 1), INTERVAL * 1000)
25+
}
26+
27+
rerun()

0 commit comments

Comments
 (0)