Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add gitleaks #1

Merged
merged 5 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: gitleaks
on:
pull_request:
push:
branches:
- develop
- main
workflow_dispatch:
schedule:
- cron: "0 4 * * *"
jobs:
scan:
name: gitleaks
runs-on: ubuntu-latest
environment: develop
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: "${{ secrets.GITLEAKS_LICENSE }}"
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ jobs:
run: go install mvdan.cc/[email protected]

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@v0.4.7
run: go install honnef.co/go/tools/cmd/staticcheck@v0.5.1

- name: Install golangci-lint
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0

- name: Lint
run: make lint
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-added-large-files
- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
- id: go-imports
- id: golangci-lint
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.1
hooks:
- id: gitleaks
name: Detect hardcoded secrets
args: ["detect", "--source=."]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ lint:
gofmt -d -s .
gofumpt -d -extra .
staticcheck ./...
golangci-lint run
golangci-lint run --disable=mnd --disable=canonicalheader --disable=testifylint

.PHONY: lt
lt: lint test
Expand Down
42 changes: 42 additions & 0 deletions PRECOMMIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Pre-commit Setup Guide

## Overview

This guide will help you set up `pre-commit` hooks for your project. Pre-commit hooks are useful for automatically running checks before committing code to ensure code quality, security, and consistency.
TechOps has enabled general golang linters and gitleaks which should be enabled on each commit.

## Prerequisites

- Python 3.6 or higher
- `pip` (Python package installer)
- `git` installed and configured

## Installation

To install `pre-commit`, follow these steps:

1. **Install pre-commit**
You can install `pre-commit` using `pip`:

```
pip install pre-commit
```

## Sample Usage
This is a sample run on a basic commit:
```
$ git commit -m "add precommit"
Check Yaml...........................................(no files to check)Skipped
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
Check for added large files..............................................Passed
go fmt...............................................(no files to check)Skipped
go imports...........................................(no files to check)Skipped
golangci-lint........................................(no files to check)Skipped
Detect hardcoded secrets.................................................Passed
```

You can also run `pre-commit` test on all files:
```
pre-commit run --all-files
```
Loading