You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
GitHub Action
Get Diff Action
v1.2.8
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:
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
phpmd:
name: PHPMD
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: .php
SEPARATOR: ','
- name: Install composer
run: composer install
if: steps.git_diff.outputs.diff
- name: Check code style
# Check only the source codes that have differences
run: vendor/bin/phpmd ${{ steps.git_diff.outputs.diff }} ansi phpmd.xml
if: steps.git_diff.outputs.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 ${FROM}...${TO} '--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: false)e.g.
/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. (default)
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
name | description | e.g. |
---|---|---|
diff | The results of diff file names. If inputs SET_ENV_NAME (default: GIT_DIFF ) is set, an environment variable is set with that name. |
src/main.ts src/utils/command.ts |
count | The number of diff files. If inputs SET_ENV_NAME_COUNT (default: '' ) is set, an environment variable is set with that name. |
100 |
insertions | The number of insertions lines. If inputs SET_ENV_NAME_INSERTIONS (default: '' ) is set, an environment variable is set with that name. |
100 |
deletions | The number of deletions lines. If inputs SET_ENV_NAME_DELETIONS (default: '' ) is set, an environment variable is set with that name. |
100 |
lines | The number of diff lines. If inputs SET_ENV_NAME_LINES (default: '' ) is set, an environment variable is set with that name. |
200 |
eventName | action |
---|---|
pull_request | opened, reopened, synchronize, closed |
push | * |
If called on any other event, the result will be empty.
condition | FROM | TO |
---|---|---|
tag push | --- | --- |
pull request | pull.base.ref (e.g. master) | context.ref (e.g. refs/pull/123/merge) |
push (has related pull request) | pull.base.ref (e.g. master) | refs/pull/${pull.number}/merge (e.g. refs/pull/123/merge) |
context.payload.before = '000...000' | default branch (e.g. master) | context.payload.after |
else | context.payload.before | context.payload.after |