Skip to content

Commit

Permalink
Add Snyk IAC PR GitHub Action
Browse files Browse the repository at this point in the history
  • Loading branch information
alamorre committed Dec 12, 2023
1 parent 5d3a06d commit afdc6a4
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/snyk-iac-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Snyk IaC PR Diff Scan

on:
pull_request:
branches: [master]

jobs:
snyk-pipeline:
runs-on: ubuntu-latest
name: Snyk IaC PR Diff Scan
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
steps:
# 1. Checkout base ref branch
- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}

- name: Download Snyk
run: |
wget -O snyk https://static.snyk.io/cli/latest/snyk-linux
chmod +x ./snyk
mv ./snyk /usr/local/bin/
- name: Authenticate Snyk
run: snyk auth ${SNYK_TOKEN}

- name: Run Snyk IaC Test
run: snyk iac test --json > ${{ github.workspace }}/snyk_iac_baseline.json
continue-on-error: true

- uses: actions/upload-artifact@v3
with:
name: snyk_iac_baseline
path: ${{ github.workspace }}/snyk_iac_baseline.json

# 2. Checkout PR branch
- uses: actions/checkout@v3

- name: Authenticate Snyk
run: snyk auth ${SNYK_TOKEN}

- name: Download snyk-diff Binary
run: |
cd "${{ github.workspace }}/.github"
curl -LJO https://github.com/snyk-playground/cx-tools/raw/main/snyk-pr-diff/bin/snyk-pr-diff-amd64-linux
- name: Run IaC Test
run: |
sleep 10s
snyk iac test --json > ${{ github.workspace }}/snyk_iac_pr.json || true
continue-on-error: true

- uses: actions/upload-artifact@v3
with:
name: snyk_iac_pr
path: ${{ github.workspace }}/snyk_iac_pr.json

- uses: actions/download-artifact@v3
with:
name: snyk_iac_baseline

# 3. Run the delta-check
- name: Run IaC PR check!
run: |
chmod +x "${{ github.workspace }}/.github/snyk-pr-diff-amd64-linux"
${{ github.workspace }}/.github/snyk-pr-diff-amd64-linux iac ${{ github.workspace }}/snyk_iac_baseline.json ${{ github.workspace }}/snyk_iac_pr.json
- name: Debugging
run: |
ls -l "${{ github.workspace }}/.github/"
ls "${{ github.workspace }}/.github/workflows"

0 comments on commit afdc6a4

Please sign in to comment.