From 251074d1c2e9c30215ec8279d8d2b21a3186c08f Mon Sep 17 00:00:00 2001 From: Thomas Carmet <8408330+tcarmet@users.noreply.github.com> Date: Mon, 6 Nov 2023 09:44:23 -0800 Subject: [PATCH] PTFE-1063 reusable workflow to disallow the merge of large files (#52) --- .github/workflows/lfs-warning.yaml | 38 ++++++++++++++++++++++++++++ .github/workflows/tests.yaml | 6 ++++- docs/lfs-warning.md | 40 ++++++++++++++++++++++++++++++ mkdocs.yml | 1 + 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/lfs-warning.yaml create mode 100644 docs/lfs-warning.md diff --git a/.github/workflows/lfs-warning.yaml b/.github/workflows/lfs-warning.yaml new file mode 100644 index 0000000..974e4ad --- /dev/null +++ b/.github/workflows/lfs-warning.yaml @@ -0,0 +1,38 @@ +--- + +# This workflow is a reusable workflow meant to be called on pull_request events. +# The goal is to check the files in the pull request to make sure they respect the file size limit. +# If the file size limit is exceeded, and the file has not been commited via git lfs, then +# the workflow will fail, a label will be added to the pull request along with a comment. + +name: lfs-warning + +on: + workflow_call: + inputs: + filesizelimit: + description: 'The file size limit' + required: false + default: 1MB + type: string + labelname: + description: 'The label name' + required: false + default: bug + type: string + +permissions: + pull-requests: write + contents: read + +jobs: + lfs-warning: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: lfs warning + uses: ppremk/lfs-warning@v3.2 + with: + filesizelimit: ${{ inputs.filesizelimit }} + labelName: ${{ inputs.labelname }} diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e12485a..b017b65 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,9 +1,10 @@ -on: push +on: pull_request permissions: packages: write contents: read security-events: write + pull-requests: write jobs: docker-build: @@ -17,3 +18,6 @@ jobs: uses: ./.github/workflows/trivy.yaml with: name: '/test' + + lfs-warning: + uses: ./.github/workflows/lfs-warning.yaml diff --git a/docs/lfs-warning.md b/docs/lfs-warning.md new file mode 100644 index 0000000..6bad095 --- /dev/null +++ b/docs/lfs-warning.md @@ -0,0 +1,40 @@ +# Git LFS warning + +The `lfs-warning.yaml` workflow will check if the files committed +in a pull request are properly tracked by Git LFS when needed. + +## Usage + +This workflow can be called as a job in any workflow that needs, +for example: + +```yaml +# my-workflow.yaml +on: pull_request + +jobs: + lfs-warning: + uses: scality/workflows/.github/workflows/lfs-warning.yaml@v1 +``` + +## Inputs + +Additional inputs to modify the default behavior of the workflow. + +| Name | Description | Default | +| --------------- | ------------------------------------------ | ------- | +| `filesizelimit` | Maximum file size before warning | `1MB` | +| `labelname` | Label name to use when a warning is issued | `bug` | + +```yaml +# my-workflow.yaml + +on: pull_request + +jobs: + lfs-warning: + uses: scality/workflows/.github/workflows/lfs-warning.yaml@v1 + with: + filesizelimit: 10MB + labelname: 'my-label' +``` diff --git a/mkdocs.yml b/mkdocs.yml index c30f289..4215ddc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -41,6 +41,7 @@ nav: - Home: index.md - Docker build: docker-build.md - Trivy: trivy.md +- Git LFS warning: lfs-warning.md - Known issues: known-issues.md markdown_extensions: