|
| 1 | +name: Coana Guardrail |
| 2 | + |
| 3 | +on: pull_request |
| 4 | + |
| 5 | +jobs: |
| 6 | + guardrail: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + |
| 9 | + steps: |
| 10 | + - name: Checkout the ${{github.base_ref}} branch |
| 11 | + uses: actions/checkout@v4 |
| 12 | + with: |
| 13 | + ref: ${{github.base_ref}} # checkout the base branch (usually master/main). |
| 14 | + |
| 15 | + - name: Fetch the PR branch |
| 16 | + run: | |
| 17 | + git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} --depth=1 |
| 18 | +
|
| 19 | + - name: Get list of changed files relative to the main/master branch |
| 20 | + id: changed-files |
| 21 | + run: | |
| 22 | + echo "all_changed_files=$(git diff --name-only ${{ github.base_ref }} ${{ github.head_ref }} | tr '\n' ' ')" >> $GITHUB_OUTPUT |
| 23 | +
|
| 24 | + - name: Use Node.js 20.x |
| 25 | + uses: actions/setup-node@v4 |
| 26 | + with: |
| 27 | + node-version: 20.x |
| 28 | + |
| 29 | + - name: Run Coana on the ${{github.base_ref}} branch |
| 30 | + run: | |
| 31 | + npx @coana-tech/cli run . \ |
| 32 | + --guardrail-mode \ |
| 33 | + --api-key ${{ secrets.COANA_API_KEY || 'api-key-unavailable' }} \ |
| 34 | + -o /tmp/main-branch \ |
| 35 | + --changed-files ${{ steps.changed-files.outputs.all_changed_files }} \ |
| 36 | + --lightweight-reachability \ |
| 37 | +
|
| 38 | + # Reset file permissions. |
| 39 | + # This is necessary because the Coana CLI may add |
| 40 | + # new files with root ownership since it's using docker. |
| 41 | + # These files will not be deleted by the clean step in checkout |
| 42 | + # if the permissions are not reset. |
| 43 | + - name: Reset file permissions |
| 44 | + run: sudo chown -R $USER:$USER . |
| 45 | + |
| 46 | + - name: Checkout the current branch |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + clean: true |
| 50 | + |
| 51 | + - name: Run Coana on the current branch |
| 52 | + run: | |
| 53 | + npx @coana-tech/cli run . \ |
| 54 | + --guardrail-mode \ |
| 55 | + --api-key ${{ secrets.COANA_API_KEY || 'api-key-unavailable' }} \ |
| 56 | + -o /tmp/current-branch \ |
| 57 | + --changed-files ${{ steps.changed-files.outputs.all_changed_files }} \ |
| 58 | + --lightweight-reachability \ |
| 59 | +
|
| 60 | + - name: Run Report Comparison |
| 61 | + run: | |
| 62 | + npx @coana-tech/cli compare-reports \ |
| 63 | + --api-key ${{ secrets.COANA_API_KEY || 'api-key-unavailable' }} \ |
| 64 | + /tmp/main-branch/coana-report.json \ |
| 65 | + /tmp/current-branch/coana-report.json |
| 66 | + env: |
| 67 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments