{"id":13484902,"url":"https://github.com/technote-space/get-diff-action","last_synced_at":"2025-03-27T16:31:35.797Z","repository":{"id":37001187,"uuid":"234274258","full_name":"technote-space/get-diff-action","owner":"technote-space","description":"GitHub Actions to get git diff","archived":true,"fork":false,"pushed_at":"2023-11-24T14:07:09.000Z","size":9368,"stargazers_count":191,"open_issues_count":8,"forks_count":27,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-26T23:39:00.276Z","etag":null,"topics":["github-actions"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/technote-space.png","metadata":{"files":{"readme":"README.ja.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"custom":"https://paypal.me/technote0space"}},"created_at":"2020-01-16T08:43:59.000Z","updated_at":"2025-03-25T14:05:35.000Z","dependencies_parsed_at":"2023-02-12T07:46:01.834Z","dependency_job_id":"6c9dfb7a-a5d8-445f-89fb-f1375d000122","html_url":"https://github.com/technote-space/get-diff-action","commit_stats":{"total_commits":655,"total_committers":3,"mean_commits":"218.33333333333334","dds":0.4106870229007633,"last_synced_commit":"eb3a04b9acda766a323ce182c0cb06e991d57326"},"previous_names":[],"tags_count":195,"template":false,"template_full_name":"technote-space/gh-actions-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fget-diff-action","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fget-diff-action/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fget-diff-action/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technote-space%2Fget-diff-action/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/technote-space","download_url":"https://codeload.github.com/technote-space/get-diff-action/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245882456,"owners_count":20687891,"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":["github-actions"],"created_at":"2024-07-31T17:01:38.238Z","updated_at":"2025-03-27T16:31:35.412Z","avatar_url":"https://github.com/technote-space.png","language":"TypeScript","funding_links":["https://paypal.me/technote0space"],"categories":["TypeScript"],"sub_categories":[],"readme":"# Get Diff Action\n\n[![CI Status](https://github.com/technote-space/get-diff-action/workflows/CI/badge.svg)](https://github.com/technote-space/get-diff-action/actions)\n[![codecov](https://codecov.io/gh/technote-space/get-diff-action/branch/main/graph/badge.svg)](https://codecov.io/gh/technote-space/get-diff-action)\n[![CodeFactor](https://www.codefactor.io/repository/github/technote-space/get-diff-action/badge)](https://www.codefactor.io/repository/github/technote-space/get-diff-action)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/technote-space/get-diff-action/blob/main/LICENSE)\n\n*Read this in other languages: [English](README.md), [日本語](README.ja.md).*\n\nこれは `git diff` を取得するための GitHub Actions です。  \nenv または actionsの出力 から差分を得ることができます。\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\u003cdetails\u003e\n\u003csummary\u003eDetails\u003c/summary\u003e\n\n- [スクリーンショット](#%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%B7%E3%83%A7%E3%83%83%E3%83%88)\n- [使用方法](#%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95)\n  - [マッチするファイルの例](#%E3%83%9E%E3%83%83%E3%83%81%E3%81%99%E3%82%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E4%BE%8B)\n  - [マッチしないファイルの例](#%E3%83%9E%E3%83%83%E3%83%81%E3%81%97%E3%81%AA%E3%81%84%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E4%BE%8B)\n  - [envの例](#env%E3%81%AE%E4%BE%8B)\n- [動作](#%E5%8B%95%E4%BD%9C)\n- [出力](#%E5%87%BA%E5%8A%9B)\n- [Action イベント詳細](#action-%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E8%A9%B3%E7%B4%B0)\n  - [対象イベント](#%E5%AF%BE%E8%B1%A1%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88)\n- [補足](#%E8%A3%9C%E8%B6%B3)\n  - [FROM, TO](#from-to)\n  - [下書きのプルリクエストで最新コミット差分のみをチェックする場合](#%E4%B8%8B%E6%9B%B8%E3%81%8D%E3%81%AE%E3%83%97%E3%83%AB%E3%83%AA%E3%82%AF%E3%82%A8%E3%82%B9%E3%83%88%E3%81%A7%E6%9C%80%E6%96%B0%E3%82%B3%E3%83%9F%E3%83%83%E3%83%88%E5%B7%AE%E5%88%86%E3%81%AE%E3%81%BF%E3%82%92%E3%83%81%E3%82%A7%E3%83%83%E3%82%AF%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88)\n  - [Json形式で結果を取得する場合](#json%E5%BD%A2%E5%BC%8F%E3%81%A7%E7%B5%90%E6%9E%9C%E3%82%92%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88)\n  - [相対パスを指定](#%E7%9B%B8%E5%AF%BE%E3%83%91%E3%82%B9%E3%82%92%E6%8C%87%E5%AE%9A)\n- [Author](#author)\n\n*generated with [TOC Generator](https://github.com/technote-space/toc-generator)*\n\n\u003c/details\u003e\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## スクリーンショット\n1. Workflow の例\n\n   ![Example workflow](https://raw.githubusercontent.com/technote-space/get-diff-action/images/workflow.png)\n1. スキップ\n\n   ![Skip](https://raw.githubusercontent.com/technote-space/get-diff-action/images/skip.png)\n\n## 使用方法\n基本的な使い方\n```yaml\non: pull_request\nname: CI\njobs:\n  eslint:\n    name: ESLint\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: technote-space/get-diff-action@v6\n        with:\n          PATTERNS: |\n            +(src|__tests__)/**/*.ts\n            !src/exclude.ts\n          FILES: |\n            yarn.lock\n            .eslintrc\n      - name: Install Package dependencies\n        run: yarn install\n        if: env.GIT_DIFF\n      - name: Check code style\n        # 差分がある場合だけチェック\n        run: yarn eslint ${{ env.GIT_DIFF }}\n        if: env.GIT_DIFF\n```\n\n[指定可能なパターンの詳細](https://github.com/isaacs/minimatch#minimatch)\n\n### マッチするファイルの例\n- `src/main.ts`\n- `src/utils/abc.ts`\n- `__tests__/test.ts`\n- `yarn.lock`\n- `.eslintrc`\n- `anywhere/yarn.lock`\n\n### マッチしないファイルの例\n- `main.ts`\n- `src/xyz.txt`\n- `src/exclude.ts`\n\n### envの例\n| name | value |\n|:---|:---|\n| `GIT_DIFF` |`'src/main.ts' 'src/utils/abc.ts' '__tests__/test.ts' 'yarn.lock' '.eslintrc' 'anywhere/yarn.lock'` |\n| `GIT_DIFF_FILTERED` | `'src/main.ts' 'src/utils/abc.ts' '__tests__/test.ts'` |\n| `MATCHED_FILES` | `'yarn.lock' '.eslintrc' 'anywhere/yarn.lock'` |\n\nもう少し細かく動作を指定\n```yaml\non: pull_request\nname: CI\njobs:\n  eslint:\n    name: ESLint\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: technote-space/get-diff-action@v6\n        with:\n          PATTERNS: |\n            +(src|__tests__)/**/*.ts\n          FILES: |\n            yarn.lock\n            .eslintrc\n      - name: Install Package dependencies\n        run: yarn install\n        if: env.GIT_DIFF\n      - name: Check code style\n        # 差分があるソースファイルだけチェック\n        run: yarn eslint ${{ env.GIT_DIFF_FILTERED }}  # e.g. yarn eslint 'src/main.ts' '__tests__/test.ts'\n        if: env.GIT_DIFF \u0026\u0026 !env.MATCHED_FILES\n      - name: Check code style\n        # 差分がある場合だけチェック (yarn.lock か .eslintrc に変更があった場合はすべてでlintを実行)\n        run: yarn lint\n        if: env.GIT_DIFF \u0026\u0026 env.MATCHED_FILES\n```\n\n以下のソースコードに差分がない場合、この Workflow はコードのスタイルチェックをスキップします。\n- `src/**/*.ts`\n- `__tests__/**/*.ts`\n\n## 動作\n1. `git diff` を取得\n\n   ```shell script\n   git diff ${FROM}${DOT}${TO} '--diff-filter=${DIFF_FILTER}' --name-only\n   ```\n\n   例：(default)\n   ```yaml\n   DOT: '...'\n   DIFF_FILTER: 'AMRC'\n   ```\n   =\u003e\n   ```shell script\n   git diff ${FROM}...${TO} '--diff-filter=AMRC' --name-only\n   ```\n   =\u003e\n   ```\n   .github/workflows/ci.yml\n   __tests__/utils/command.test.ts\n   package.json\n   src/main.ts\n   src/utils/command.ts\n   src/docs.md\n   yarn.lock\n   ```\n   \n   [${FROM}, ${TO}](#from-to)\n\n1. `PATTERNS` オプションによるフィルタ\n\n   例：\n   ```yaml\n   PATTERNS: |\n     src/**/*.+(ts|md)\n     !src/utils/*\n   ```\n   =\u003e\n   ```\n   src/main.ts\n   src/docs.md\n   ```\n\n1. `FILES` オプションによるフィルタ\n\n   e.g.\n   ```yaml\n   FILES: package.json\n   ```\n   =\u003e\n   ```\n   package.json\n   anywhere/package.json\n   ```\n\n1. `ABSOLUTE` オプションがtrue場合に絶対パスに変換 (default: false)\n\n   例：\n   ```\n   /home/runner/work/my-repo-name/my-repo-name/src/main.ts\n   /home/runner/work/my-repo-name/my-repo-name/src/docs.md\n   ```\n\n1. `SEPARATOR` オプションの値で結合\n\n   例：(default: false)\n   ```yaml\n   SEPARATOR: ' '\n   ```\n   =\u003e\n   ```\n   /home/runner/work/my-repo-name/my-repo-name/src/main.ts /home/runner/work/my-repo-name/my-repo-name/src/docs.md\n   ```\n\n## 出力\n| name | description | e.g. |\n|:---|:---|:---|\n| diff | 差分のあるファイルの結果\u003cbr\u003e`SET_ENV_NAME`(default: `GIT_DIFF`) が設定されている場合、その名前で環境変数が設定されます | `src/main.ts src/docs.md` |\n| count | 差分のあるファイル数\u003cbr\u003e`SET_ENV_NAME_COUNT`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |\n| insertions | 追加された行数 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)\u003cbr\u003e`SET_ENV_NAME_INSERTIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |\n| deletions | 削除された行数 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)\u003cbr\u003e`SET_ENV_NAME_DELETIONS`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `100` |\n| lines | 追加された行数と削除された行数の和 (`GET_FILE_DIFF` が `true` の場合のみ利用可能)\u003cbr\u003e`SET_ENV_NAME_LINES`(default: `''`) が設定されている場合、その名前で環境変数が設定されます | `200` |\n\n## Action イベント詳細\n### 対象イベント\n| eventName | action |\n|:---|:---|\n| pull_request | opened, reopened, synchronize, closed, ready_for_review |\n| push | * |\n\nもしこれ以外のイベントで呼ばれた場合、結果は空になります。\n\n## 補足\n### FROM, TO\n| condition | FROM | TO |\n|:---|:---|:---|\n| tag push | --- | --- |\n| pull request | pull.base.ref (e.g. main) | context.ref (e.g. refs/pull/123/merge) |\n| push (has related pull request) | pull.base.ref (e.g. main) | `refs/pull/${pull.number}/merge` (e.g. refs/pull/123/merge) |\n| context.payload.before = '000...000' | default branch (e.g. main) | context.payload.after |\n| else | context.payload.before | context.payload.after |\n\n### 下書きのプルリクエストで最新コミット差分のみをチェックする場合\n```yaml\non:\n  pull_request:\n    types: [opened, reopened, synchronize, closed, ready_for_review]\n\njobs:\n  eslint:\n    name: ESLint\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: technote-space/get-diff-action@v6\n        with:\n          CHECK_ONLY_COMMIT_WHEN_DRAFT: true\n      # ...\n```\n\n### Json形式で結果を取得する場合\n```yaml\non: pull_request\nname: CI\njobs:\n  dump:\n    name: Dump\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: technote-space/get-diff-action@v6\n        with:\n          PATTERNS: |\n            +(src|__tests__)/**/*.ts\n            !src/exclude.ts\n          FORMAT: json\n      - run: echo '${{ env.GIT_DIFF }}' | jq .\n```\n\nResult:\n```shell\n\u003e Run echo '[\"yarn.lock\"]' | jq .\n[\n  \"yarn.lock\"\n]\n```\n\n### 相対パスを指定\n\nGitHub Actions は `uses` に `working-directory` を指定できないため、モノレポ構成などで個別に実行したい場合に対応できませんが、`RELATIVE` オプションを指定すると `git diff` の `--relative=\u003cRELATIVE\u003e` として使用されます。\n\nhttps://git-scm.com/docs/git-diff#Documentation/git-diff.txt---relativeltpathgt\n\n```yaml\non: pull_request\nname: CI\njobs:\n  dump:\n    name: Dump\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v2\n      - uses: technote-space/get-diff-action@v6\n        with:\n          PATTERNS: '*.ts'\n          RELATIVE: 'src/abc'\n      - run: echo ${{ env.GIT_DIFF }}\n```\n\n`src/abc/test1.ts`, `src/abc/test2.ts`, `src/abc/test3.txt`, `src/test4.ts` のファイルがある場合、結果は以下のようになります。\n\n```shell\n\u003e Run echo 'test1.ts' 'test2.ts'\ntest1.ts test2.ts\n```\n\n## Author\n[GitHub (Technote)](https://github.com/technote-space)\n\n[Blog](https://technote.space)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnote-space%2Fget-diff-action","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnote-space%2Fget-diff-action","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnote-space%2Fget-diff-action/lists"}