Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions scripts/rerun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

// Example to rerun the Serverless workflow 30 times on the current branch:
// GITHUB_TOKEN=$(ddtool auth github token) WORKFLOW=Serverless node scripts/rerun

const { execSync } = require('child_process')

const {
ATTEMPTS = 30,
BRANCH,
INTERVAL = 600,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why repeating should wait for 10 minutes by default. Is there a specific reason for that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All our workflows take less than 10 minutes, and you can't rerun a running workflow.

WORKFLOW
} = process.env

function rerun (current = 1) {
const branch = BRANCH || execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
const result = execSync(`gh run ls -b ${branch} -w ${WORKFLOW}`).toString()
const id = result.match(/\d{11}/)[0]

execSync(`gh run rerun ${id} --repo DataDog/dd-trace-js || exit 0`)

if (current >= ATTEMPTS) return

setTimeout(() => rerun(current + 1), INTERVAL * 1000)
}

rerun()