Skip to content

Commit

Permalink
Merge pull request #32 from kdnutrien/issue-31-preserve-skipped-steps
Browse files Browse the repository at this point in the history
fix(#31): preserve skipped steps to avoid Drone DAG reference errors
  • Loading branch information
microadam authored Sep 29, 2021
2 parents 1a1155e + 455305d commit 4c52173
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,27 @@ app.post('/', bodyParser.json({limit: '50mb'}), async (req, res) => {
}
}

const trimmedSteps = py.steps.filter(s => {
if (!s.when || !s.when.changeset || !s.when.changeset.includes) return true
const transformedSteps = py.steps.map(s => {
if (!s.when || !s.when.changeset || !s.when.changeset.includes) {
return s;
}

const requiredFiles = s.when.changeset.includes
const matchedFiles = glob.match(requiredFiles, filesChanged, { dot: true })
console.log('Matched files for step:', matchedFiles.length, 'Allowed matches:', requiredFiles)
return matchedFiles.length

if (!matchedFiles.length) {
// Add an impossible conditional which guarantees the step gets skipped
s.when = {
...s.when,
event: { exclude: ['*'] },
}
}

return s;
})

return trimmedSteps.length ? yaml.stringify({ ...py, steps: trimmedSteps }) : nullYaml(index)
return transformedSteps.length ? yaml.stringify({ ...py, steps: transformedSteps }) : nullYaml(index)
})

res.json({ Data: finalYamlDocs.join('\n---\n') })
Expand Down

0 comments on commit 4c52173

Please sign in to comment.