Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
file

GitHub Action

Get Diff Action

v1.1.4

Get Diff Action

file

Get Diff Action

GitHub actions to get git diff

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Get Diff Action

uses: technote-space/[email protected]

Learn more about this action in technote-space/get-diff-action

Choose a version

Get Diff Action

CI Status codecov CodeFactor License: MIT

Read this in other languages: English, 日本語.

GitHub actions to get git diff.

Table of Contents

Details

Screenshots

  1. Example workflow
    Example workflow
  2. Skip
    Skip

Usage

on: pull_request
name: CI
jobs:
  eslint:
    name: ESLint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v1
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PREFIX_FILTER: |
            src
            __tests__
          SUFFIX_FILTER: .ts
      - name: Install Package dependencies
        run: yarn install
        if: env.GIT_DIFF
      - name: Check code style
        # Check only the source codes that have differences
        run: yarn eslint ${{ env.GIT_DIFF }}
        if: env.GIT_DIFF

If there is no difference in the source code below, this workflow will skip the code style check

  • src/**/*.ts
  • __tests__/**/*.ts

Behavior

  1. Get git diff

    git diff "${FROM}"${DOT}"${TO}" '--diff-filter=${DIFF_FILTER}' --name-only

    e.g. (default)

    DOT: '...'
    DIFF_FILTER: 'AM'

    =>

    git diff "origin/${GITHUB_BASE_REF}"..."${GITHUB_REF#refs/}" '--diff-filter=AM' --name-only

    =>

    .github/workflows/ci.yml
    __tests__/utils/command.test.ts
    package.json
    src/main.ts
    src/utils/command.ts
    yarn.lock
    
  2. Filtered by PREFIX_FILTER or SUFFIX_FILTER option

    e.g.

    SUFFIX_FILTER: .ts
    PREFIX_FILTER: src/

    =>

    src/main.ts
    src/utils/command.ts
    
  3. Mapped to absolute if ABSOLUTE option is true(default)

    e.g. (default)

    /home/runner/work/my-repo-name/my-repo-name/src/main.ts
    /home/runner/work/my-repo-name/my-repo-name/src/utils/command.ts
    
  4. Combined by SEPARATOR option

    e.g.

    SEPARATOR: ' '

    =>

    /home/runner/work/my-repo-name/my-repo-name/src/main.ts /home/runner/work/my-repo-name/my-repo-name/src/utils/command.ts
    

Outputs

diff

The results of diff file names.
if inputs SET_ENV_NAME is set, an environment variable is set with that name.
default: SET_ENV_NAME=GIT_DIFF

count

The number of diff files.
if inputs SET_ENV_NAME_COUNT is set, an environment variable is set with that name.
default: SET_ENV_NAME_COUNT=

insertions

The number of insertions lines.
if inputs SET_ENV_NAME_INSERTIONS is set, an environment variable is set with that name.
default: SET_ENV_NAME_INSERTIONS=

deletions

The number of deletions lines.
if inputs SET_ENV_NAME_DELETIONS is set, an environment variable is set with that name.
default: SET_ENV_NAME_DELETIONS=

lines

The number of diff lines.
if inputs SET_ENV_NAME_LINES is set, an environment variable is set with that name.
default: SET_ENV_NAME_LINES=

Action event details

Target events

eventName action
pull_request opened, reopened, rerequested, synchronize
push *

If called on any other event, the result will be empty.

Author

GitHub (Technote)
Blog