I recently built and shipped GitHub Actions workflow for cxgrd. I built it to automate the scanning of project directory by the scan command and blast radius analysis by the check command, on every PR created.
What it does
When ever a PR is created,
- The project dependencies and cxgrd are installed
- The project is scanned with
cxgrd scan -
checkcommand is used to run blast radius analysis and compiler checks - The results (risk level, affected files, changed types ) are posted as a comment to the PR.
The comment is updated on every subsequent run, instead of posting a new comment.
How I built this
The check command already had BlastRadiusAnalyzer being used for posting CI check results to DB and team dashboard. The only thing was to create a --json flag to extract the result in json format and post it as a comment.
The thing I found interesting was, I didn't have to use auth for posting the comment. While I was designing the flow, I came across something new: GITHUB_TOKEN, which Actions inject into every PR, and is scoped to the specific repo, with permissions to comment. So, I just needed to write a small JS script, something like this:
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v4
- run: cxgrd check --json > result.json
- uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const result = JSON.parse(fs.readFileSync('result.json'));
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number, // PR number, auto-available
body: `## CXGRD Blast Radius\n\nRisk: ${result.risk}\n...`
});
inside the .yml file.
Why I built this
I thought, the reason behind low adoption of cxgrd is that the users have to run CLI commands on their own. So I wrapped the core feature inside a CI workflow file.
Maybe this will help cxgrd grow.
Checkout the GitHub Action here.
I am open to any feedback which will help me and my tool grow.
This article was originally published by DEV Community and written by Manan Sharma.
Read original article on DEV Community