-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADSECGH-61: add pre commit configuration and workflow (#97)
* feat: added gitignore for .venv python environment * feat: added configuration for pre-commit * ci: made sure tests only run on pre-push * ci: added ci for pre-commit on workflow or PRs
- Loading branch information
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Pre-commit checks | ||
|
||
on: | ||
pull_request: | ||
types: [opened, edited, reopened, synchronize] | ||
branches: | ||
- main | ||
workflow_call: | ||
inputs: | ||
mark_as_draft: | ||
required: false | ||
type: boolean | ||
description: Mark PR as draft if checks fail | ||
default: false | ||
skip_hooks: | ||
required: false | ||
type: string | ||
description: Comma separated list of pre-commit hook ids to skip | ||
default: '' | ||
|
||
env: | ||
MARK_AS_DRAFT: ${{ github.event.inputs.mark_as_draft }} | ||
|
||
jobs: | ||
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup python | ||
uses: actions/setup-python@v5 | ||
|
||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Get changed files | ||
id: changed-files | ||
env: | ||
GITHUB_BASE_REF: ${{ github.base_ref }} | ||
GITHUB_HEAD_REF: ${{ github.head_ref }} | ||
run: | | ||
FILES=$(git diff --name-only "origin/$GITHUB_BASE_REF" "origin/$GITHUB_HEAD_REF" | awk '{printf("\"%s\" ",$0)} END { printf "\n" }') | ||
echo "files=$FILES" >> "$GITHUB_OUTPUT" | ||
- uses: pre-commit/[email protected] | ||
env: | ||
SKIP: ${{ inputs.skip_hooks }} | ||
with: | ||
extra_args: --files ${{ steps.changed-files.outputs.files }} | ||
|
||
- name: Mark as draft | ||
if: failure() && env.MARK_AS_DRAFT | ||
uses: voiceflow/draft-pr@latest | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/.idea | ||
/results | ||
/.vs | ||
/.venv | ||
packages | ||
AdSecGH/bin | ||
AdSecGH/obj | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
default_stages: [pre-commit] | ||
|
||
repos: | ||
- repo: local | ||
hooks: | ||
|
||
- id: dotnet-build | ||
name: Build | ||
entry: msbuild /p:AppxBundlePlatforms="x64" /p:AppxBundle=Always /p:UapAppxPackageBuildMode=StoreUpload /m /nr:false | ||
language: system | ||
pass_filenames: false | ||
stages: [pre-push] | ||
always_run: true | ||
|
||
- id: dotnet-format | ||
name: Format | ||
entry: dotnet format --exclude-diagnostics --verify-no-changes --verbosity diagnostic AdSecGH.sln | ||
language: system | ||
pass_filenames: false | ||
always_run: true | ||
|
||
- id: dotnet-test-coverage | ||
name: Run dotnet tests with coverage | ||
entry: powershell.exe -NoProfile -ExecutionPolicy Bypass -File coverage.ps1 | ||
stages: [pre-push] | ||
language: system | ||
|
||
- repo: https://github.com/commitizen-tools/commitizen | ||
rev: v3.13.0 | ||
hooks: | ||
- id: commitizen | ||
stages: [commit-msg] | ||
|
||
# this should go last since it will fix line endings broken by other tools | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-case-conflict | ||
- id: check-yaml | ||
- id: check-ast | ||
- id: check-merge-conflict | ||
- id: double-quote-string-fixer | ||
- id: trailing-whitespace | ||
exclude: .github | ||
args: [--markdown-linebreak-ext=md] | ||
- id: end-of-file-fixer |
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