gitleaks comment test #36
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tests that rely on the committed code, without needing the docker images to be built | |
name: Scan ClimateTrax FE | |
on: [push] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
trivy-scan-code: | |
runs-on: ubuntu-latest | |
timeout-minutes: 60 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Cache Scan Dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/trivy | |
key: ${{ github.workflow }}-${{ github.run_id }} | |
restore-keys: trivy- | |
- name: Run Trivy vulnerability scanner in repo mode | |
uses: aquasecurity/trivy-action@master | |
with: | |
scan-type: fs | |
format: sarif | |
output: trivy-results.sarif | |
exit-code: "0" | |
ignore-unfixed: false | |
severity: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL | |
timeout: 10m0s | |
- name: Upload Trivy scan results as artifact | |
# can't use the Advanced Security feature for the result uploading | |
# as it is only for a public repo or a private repo within GitHub Enterprise | |
uses: actions/upload-artifact@v2 | |
with: | |
name: trivy-results | |
path: trivy-results.sarif | |
install-dev-tools: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '18' # Change this to the Node.js version your project supports | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- run: yarn install --frozen-lockfile --check-files | |
working-directory: ./app | |
husky-checks: | |
needs: install-dev-tools | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Get yarn cache directory path | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- run: yarn install | |
working-directory: ./app | |
- run: npm run lint | |
working-directory: ./app | |
gitleaks: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- uses: gitleaks/gitleaks-action@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE}} | |
continue-on-error: true | |
- name: Upload gitleaks results | |
uses: actions/upload-artifact@v2 | |
if: always() | |
with: | |
name: gitleaks-results | |
path: ./results.sarif | |
gitleaks-comment: | |
runs-on: ubuntu-latest | |
needs: gitleaks | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Download artifact | |
uses: actions/download-artifact@v2 | |
with: | |
name: gitleaks-results.sarif | |
path: ./artifacts | |
- name: Extract leak details | |
id: extract | |
run: | | |
leaks=$(jq '.runs[].results[].message.text' -r ./artifacts/gitleaks-results.sarif) | |
echo "::set-output name=leaks::$leaks" | |
- name: Comment on PR | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const leaks = `${{ steps.extract.outputs.leaks }}`.split('\n'); | |
leaks.forEach(leak => { | |
github.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `🔒 Gitleaks found a potential leak: ${leak}` | |
}); | |
}); |