From 83dcc3a687814f0b11ce95a687016bd7ef245dd6 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Sat, 26 Mar 2022 05:52:41 +0100 Subject: [PATCH] CI: Prevent large files from being added --- .github/workflows/file-size.yml | 33 +++++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 6 ++++-- 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/file-size.yml diff --git a/.github/workflows/file-size.yml b/.github/workflows/file-size.yml new file mode 100644 index 00000000..70eb6563 --- /dev/null +++ b/.github/workflows/file-size.yml @@ -0,0 +1,33 @@ +name: File Size Check + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v18.4 + - name: List all changed files + run: | + # MAXSIZE is 1 MB + MAXSIZE=1000000 + for FILENAME in ${{ steps.changed-files.outputs.all_changed_files }}; do + FILESIZE=$(stat -c%s "$FILENAME") + echo "Size of $FILENAME = $FILESIZE bytes." + if (( FILESIZE > MAXSIZE)); then + echo "$FILENAME is too big. Only $MAXSIZE bytes allowed." + exit 1 + fi + done diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b1e000fa..5d2ff694 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,6 +13,8 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - id: mixed-line-ending + - id: check-added-large-files + args: ['--maxkb=1000'] - repo: https://github.com/pre-commit/mirrors-isort rev: v5.10.1 hooks: @@ -22,7 +24,7 @@ repos: hooks: - id: black - repo: https://github.com/asottile/pyupgrade - rev: v2.31.0 + rev: v2.31.1 hooks: - id: pyupgrade args: [--py37-plus] @@ -30,4 +32,4 @@ repos: rev: v1.12.1 hooks: - id: blacken-docs - additional_dependencies: [black==20.8b1] + additional_dependencies: [black==22.1.0]