{"id":15674569,"url":"https://github.com/grantbirki/git-diff-action","last_synced_at":"2025-04-30T07:25:15.379Z","repository":{"id":60076687,"uuid":"537560386","full_name":"GrantBirki/git-diff-action","owner":"GrantBirki","description":"A GitHub Action for gathering the git diff of a pull request in raw or JSON format","archived":false,"fork":false,"pushed_at":"2025-02-18T19:16:54.000Z","size":2144,"stargazers_count":16,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-24T20:17:59.210Z","etag":null,"topics":["actions","automation","git-diff","json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GrantBirki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-16T17:38:08.000Z","updated_at":"2025-02-16T07:01:14.000Z","dependencies_parsed_at":"2023-11-22T20:26:41.639Z","dependency_job_id":"235b8b37-bc84-44f6-b6e1-02782f139e07","html_url":"https://github.com/GrantBirki/git-diff-action","commit_stats":{"total_commits":59,"total_committers":2,"mean_commits":29.5,"dds":"0.016949152542372836","last_synced_commit":"cca15618df9693dd4e31073588d0af78699e27c9"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fgit-diff-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fgit-diff-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fgit-diff-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GrantBirki%2Fgit-diff-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GrantBirki","download_url":"https://codeload.github.com/GrantBirki/git-diff-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251659536,"owners_count":21623068,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actions","automation","git-diff","json"],"created_at":"2024-10-03T15:46:55.734Z","updated_at":"2025-04-30T07:25:15.330Z","avatar_url":"https://github.com/GrantBirki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# git-diff-action 📃\n\n[![test](https://github.com/GrantBirki/git-diff-action/actions/workflows/test.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/test.yml) [![lint](https://github.com/GrantBirki/git-diff-action/actions/workflows/lint.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/lint.yml) [![CodeQL](https://github.com/GrantBirki/git-diff-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/codeql-analysis.yml) [![package-check](https://github.com/GrantBirki/git-diff-action/actions/workflows/package-check.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/package-check.yml) [![sample-workflow](https://github.com/GrantBirki/git-diff-action/actions/workflows/sample-workflow.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/sample-workflow.yml) [![acceptance](https://github.com/GrantBirki/git-diff-action/actions/workflows/acceptance.yml/badge.svg)](https://github.com/GrantBirki/git-diff-action/actions/workflows/acceptance.yml) [![coverage](./badges/coverage.svg)](./badges/coverage.svg)\n\nA GitHub Action for gathering the `git diff` of a pull request in JSON format or standard `git diff` format\n\n## About 💡\n\nA useful Action for grabbing the `git diff` output of a pull request in a machine readable JSON format. This Action can be used in conjunction with other Actions or tools to perform tasks such as:\n\n- Auditing the changes made in a pull request\n- Running subsequent workflows conditionally based on the files, lines, or directories changed in a pull request\n- Send out a signal to reviewers when certain files or even specific lines are changed in a pull request\n\n## Turbo Quickstart ⚡\n\nCheckout the example below to see how you can use this Action in your workflow to get the `git diff` of changes made in the context of a pull request\n\n\u003e All references to `vX.X.X` are places holders and you can find the latest version of this Action under the [Releases](https://github.com/GrantBirki/git-diff/releases) section\n\n```yaml\n      # Checkout the repo\n      - uses: actions/checkout@v4\n        with:\n          fetch-depth: 0 # needed to checkout all branches for this Action to work\n\n      # Check the PR diff using the current branch and the base branch of the PR\n      - uses: GrantBirki/git-diff-action@vX.X.X\n        id: git-diff-action\n        with:\n          json_diff_file_output: diff.json\n          raw_diff_file_output: diff.txt\n          file_output_only: \"true\"\n\n      # Print the diff in JSON format\n      - name: print json diff\n        env:\n          DIFF: ${{ steps.git-diff-action.outputs.json-diff-path }}\n        run: cat $DIFF\n\n      # Print the diff in raw git format\n      - name: print raw diff\n        env:\n          DIFF: ${{ steps.git-diff-action.outputs.raw-diff-path }}\n        run: cat $DIFF\n```\n\n\u003e View the section below to see a more detailed example\n\n## Example 📚\n\nThis is a full workflow example with detailed comments for how you can use this Action\n\n```yaml\nname: sample-workflow\n\n# Run on all pull_request related events\non:\n  pull_request:\n\npermissions:\n  contents: read # this is necessary for the Action to be able to read the contents of the repo\n\njobs:\n  sample:\n    runs-on: ubuntu-latest\n    steps:\n      # Checkout the repo\n      - uses: actions/checkout@v4\n        with:\n          fetch-depth: 0 # needed to checkout all branches for this Action to work\n\n      # Check the PR diff using the current branch and the base branch of the PR\n      - uses: GrantBirki/git-diff-action@vX.X.X\n        id: git-diff-action\n        with:\n          json_diff_file_output: diff.json\n          raw_diff_file_output: diff.txt\n          file_output_only: \"true\"\n\n      # Print the diff in JSON format\n      - name: print json diff\n        env:\n          DIFF: ${{ steps.git-diff-action.outputs.json-diff-path }}\n        run: cat $DIFF\n\n      # Print the diff in raw git format\n      - name: print raw diff\n        env:\n          DIFF: ${{ steps.git-diff-action.outputs.raw-diff-path }}\n        run: cat $DIFF\n```\n\n### JSON Diff Output 📝\n\nExpand the section below to see an example of the JSON diff output\n\n\u003cdetails\u003e\n\u003csummary\u003e JSON Example \u003c/summary\u003e\n\n```json\n{\n    \"type\": \"GitDiff\",\n    \"files\": [\n        {\n            \"type\": \"ChangedFile\",\n            \"chunks\": [\n                {\n                    \"type\": \"Chunk\",\n                    \"toFileRange\": {\n                        \"start\": 12,\n                        \"lines\": 8\n                    },\n                    \"fromFileRange\": {\n                        \"start\": 12,\n                        \"lines\": 6\n                    },\n                    \"changes\": [\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 12,\n                            \"lineAfter\": 12,\n                            \"content\": \"    steps:\"\n                        },\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 13,\n                            \"lineAfter\": 13,\n                            \"content\": \"      # Need to checkout for testing the Action in this repo\"\n                        },\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 14,\n                            \"lineAfter\": 14,\n                            \"content\": \"      - uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3.0.2\"\n                        },\n                        {\n                            \"type\": \"AddedLine\",\n                            \"lineAfter\": 15,\n                            \"content\": \"        with:\"\n                        },\n                        {\n                            \"type\": \"AddedLine\",\n                            \"lineAfter\": 16,\n                            \"content\": \"          fetch-depth: 0 # needed to checkout all branches\"\n                        },\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 15,\n                            \"lineAfter\": 17,\n                            \"content\": \"\"\n                        },\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 16,\n                            \"lineAfter\": 18,\n                            \"content\": \"      # Start check the PR diff\"\n                        },\n                        {\n                            \"type\": \"UnchangedLine\",\n                            \"lineBefore\": 17,\n                            \"lineAfter\": 19,\n                            \"content\": \"      - uses: ./\"\n                        }\n                    ]\n                }\n            ],\n            \"path\": \".github/workflows/sample-workflow.yml\"\n        }\n    ]\n}\n```\n\n\u003c/details\u003e\u003cbr\u003e\n\n\u003e Click [here](example/diff.json) to see an even more detailed example of the JSON diff output\n\n## Inputs 📥\n\n| Input | Required? | Default | Description |\n| ----- | --------- | ------- | ----------- |\n| `base_branch` | yes | `HEAD^1` | The \"base\" or \"target\" branch to use for the git diff |\n| `json_diff_file_output` | no | - | Optionally write the JSON diff output to a file. This is a string to the file path you wish to write to. **highly recommended** |\n| `raw_diff_file_output` | no | - | Optionally write the raw diff output to a file. This is a string to the file path you wish to write to. **highly recommended** |\n| `file_output_only` | no | `\"false\"` | Only use file related outputs and do not print any diffs to console / loggers. **highly recommended** |\n| `search_path` | no | `.` | Optionally limit the scope of the diff operation to a specific sub-path. Useful for limiting scope of the action. |\n| `max_buffer_size` | no | `\"10000000\"` | Maximum output buffer size for call to git binary. Default is 10M, try increasing this value if you have issues with maxBuffer overflow. This value is technically a string but it gets converted to an integer. |\n| `git_options` | no | `\"--no-color --full-index\"` | Additional options to pass to the git binary |\n| `git_diff_file` | no | `\"false\"` | Optionally read the diff from a file instead of running `git diff` |\n\n## Outputs 📤\n\n| Output | Description |\n| ------ | ----------- |\n| `json-diff` | The `git diff` of the pull request in JSON format |\n| `raw-diff` | The raw `git diff` of the pull request |\n| `json-diff-path` | The path to the JSON diff file if `json_diff_file_output` was specified |\n| `raw-diff-path` | The path to the raw diff file if `raw_diff_file_output` was specified |\n\n## `base_branch` Input\n\nThe `base_branch` input is `HEAD^1` by default. This means that the \"base\" or \"target\" branch for the git diff will be the branch that the pull request is targeting. For most use cases, it's best to compare the pull request merge commit against its first parent, which will only show changes that the pull request itself introduces.\n\nThis option can be changed to any valid git ref, such as a branch name, tag name, or commit hash.\n\nAnother common option that can be used in the context of GitHub Actions is `${{ github.event.pull_request.base.sha }}`\n\n## `search_path` Input\n\nThe `search_path` input is `.` by default. This means that the working directory (base of the repository) is in-scope for the git diff command.\n\nIf you want to limit the scope of the `git diff` command you can specify a subfolder, subpath or file glob in it's place. Here are some examples:\n\n```yaml\n# Only look in files called CHANGELOG.md\nsearch_path: '**/CHANGELOG.md'\n\n# Only search in YAML files\nsearch_path: '**/*.yaml'\n\n# Only look in the src/ directory\nsearch_path: src/\n```\n\n## Known Issues\n\nYou should always opt for using the `json_diff_file_output`, `raw_diff_file_output`, and `file_output_only` (set to `\"true\"`) inputs to write the diff output to a file. This is because the diff output can be quite large and can cause issues with the GitHub Actions API.\n\nIf your git diff is too large, you may see an error like this:\n\n```text\nError: An error occurred trying to start process '/usr/bin/bash' with working directory '/home/runner/work/\u003crepo\u003e/\u003cdir\u003e'. Argument list too long\n```\n\nThis is because GitHub Actions can only support argument lists from environment variables up to a certain size. To get around this, it is highly recommended to use the `json_diff_file_output` and `raw_diff_file_output` inputs to write the diff output to a file and then read that file in subsequent steps.\n\nSetting `file_output_only: \"true\"` can also help avoid any sort of memory issues that could occur in GitHub Actions runners if they try to log massive diffs to the console.\n\nThe TL;DR of this section, is that you should really just be using file based outputs to avoid issues that can occur when printing huge amounts of text to the console with Action runners.\n\nHere is an example with the suggested configuration options explicitly set:\n\n```yaml\n- uses: GrantBirki/git-diff-action@vX.X.X\n  id: git-diff-action\n  with:\n    base_branch: HEAD^1 # compare the PR merge commit against its first parent\n    json_diff_file_output: diff.json # write the JSON diff output to a file called 'diff.json'\n    raw_diff_file_output: diff.txt # write the raw diff output to a file called 'diff.txt' (just in case)\n    file_output_only: \"true\" # do not print any diff output to the console (safety first)\n    search_path: '.' # look in the entire repo for changes\n    max_buffer_size: \"1000000\" # the default git diff buffer size, increase if you have issues\n```\n\nNow your configuration is pretty much self-documenting and you can easily see what the Action is doing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantbirki%2Fgit-diff-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrantbirki%2Fgit-diff-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrantbirki%2Fgit-diff-action/lists"}