GitHub Action
Get Diff Action
Read this in other languages: English, 日本語.
GitHub actions to get git diff.
Details
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
-
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
-
Filtered by
PREFIX_FILTER
orSUFFIX_FILTER
optione.g.
SUFFIX_FILTER: .ts PREFIX_FILTER: src/
=>
src/main.ts src/utils/command.ts
-
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
-
Combined by
SEPARATOR
optione.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
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
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=
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=
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=
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=
eventName | action |
---|---|
pull_request | opened, reopened, rerequested, synchronize |
push | * |
If called on any other event, the result will be empty.