I want to add a step to check for circular dependencies in our bitbucket pipeline, but I'm struggling to come up with a good way to grab the output to throw an error or not
Here are the bitbucket steps I've tried
- step:
name: Check Circular Dependencies
caches:
- node
image: node:20.10.0
script:
- cd dependency-check
- npm install
- cd ..
- OUTPUT=$(npx madge --circular harmonee-ui/src/App.tsx)
- echo "$OUTPUT"
- if echo "$OUTPUT" | grep -q "No circular dependency found!"; then echo "No circular dependencies found"; else echo "Circular dependencies found!" && exit 1; fi
And I also tried putting the output into a txt and grepping that
- step:
name: Check Circular Dependencies
caches:
- node
image: node:20.10.0
script:
- cd dependency-check
- npm install
- cd ..
- npx madge --circular harmonee-ui/src/App.tsx > dependency_check.txt
- cat dependency_check.txt
- if grep -q "✔ No circular dependency found!" dependency_check.txt; then echo "No circular dependencies found"; else echo "Circular dependencies found!" && exit 1; fi
Madge is working as expected, but I can't seem to grep the output easily in the pipeline. Any ideas on what I'm going wrong here and how to fix it? Better ways to test for circular dependencies in CI are also welcome
script:
block. It looks to me like the ONLY thing that matters in your example is theif ... grep...
last line, nothing above it is relevant to the problem you're asking for help to solve, so just try to get that working on input that looks like whatevernpx madge --circular harmonee-ui/src/App.tsx
outputs and if you run into a problem with that then ask a question about just that.