CircleCI

Last updated
version: 2.1
orbs:
node: circleci/node@5.2.0
jobs:
sast-autofixer:
docker:
- image: cimg/base:stable
steps:
- checkout
# Installing Node.js 18
- node/install:
node-version: '18'
- run:
name: "Prepare Environment for SAST and Mobb Steps"
command: |
# Extract the GitHub repo URL
GITHUBURL=$(echo $CIRCLE_REPOSITORY_URL | sed 's/^git@github.com:/https:\/\/github.com\//;s/\.git$//')
echo "Extracted GitHub URL: $GITHUBURL"
echo "export GITHUBURL="$GITHUBURL"" >> $BASH_ENV
- run:
name: "SAST scan"
command: |
# Replace this step with your own SAST scanner
npx snyk auth $SNYK_API_KEY
npx snyk code test --sarif-file-output=report.json
- run:
name: "Mobb Autofixer"
command: |
# Run Mobb Autofixer against the report.json file generated in the previous step with Snyk SAST scan
MOBBURL=$(npx mobbdev@latest analyze -f report.json -r $GITHUBURL --ref $CIRCLE_BRANCH --api-key $MOBB_API_KEY --ci)
echo "Mobb URL: $MOBBURL"
# Store the Mobb URL in a html file and save it as a CircleCI artifact
echo "<html><body><a href="$MOBBURL">Click here for the Mobb URL</a></body></html>" > mobburl.html
# (Optional Step) Publish the Mobb URL back to GitHub PR page. The script can be found in https://github.com/antonychiu2/mobb-circleci-integration/tree/main/.circleci
./.circleci/update_github_status.sh \
"$GITHUB_PAT_SECRET" \
"$CIRCLE_USERNAME" \
"$CIRCLE_PROJECT_REPONAME" \
"$CIRCLE_SHA1" \
"success" \
"$MOBBURL" \
"Click on \\\"Details\\\" to access the Mobb Fix Link" \
"Mobb Fix Link"
when: on_fail
- store_artifacts:
path: mobburl.html
destination: /MobbURL
- store_artifacts:
path: report.json
destination: /Snyk Report
# Orchestrate jobs using workflows
workflows:
test-workflow:
jobs:
- sast-autofixer