All Projects → technote-space → get-diff-action

technote-space / get-diff-action

Licence: MIT license
GitHub Actions to get git diff

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to get-diff-action

Real Time Social Media Mining
DevOps pipeline for Real Time Social/Web Mining
Stars: ✭ 22 (-85.23%)
Mutual labels:  github-actions
cfn-deploy
A useful GitHub Action to help you deploy cloudformation templates
Stars: ✭ 14 (-90.6%)
Mutual labels:  github-actions
DemoApp
An Android template project for fast development and test.
Stars: ✭ 33 (-77.85%)
Mutual labels:  github-actions
review-pdf-generator-action
builds PDF via Re:VIEW and uploads as Artifacts
Stars: ✭ 15 (-89.93%)
Mutual labels:  github-actions
dotnet-format
A GitHub Action to run dotnet-format as part of your workflow
Stars: ✭ 25 (-83.22%)
Mutual labels:  github-actions
zhiiiyang
It is a self-updating personal README showing my latest tweet and reply.
Stars: ✭ 27 (-81.88%)
Mutual labels:  github-actions
iOSDC2020-Talk-Sample
iOSDC 2020「GitHub ActionsでiOSアプリをCIする個人的ベストプラクティス」レギュラートークのサンプルリポジトリ
Stars: ✭ 35 (-76.51%)
Mutual labels:  github-actions
publish-docker-action
GitHub Action used to build, tag and publish docker image to your docker registry
Stars: ✭ 31 (-79.19%)
Mutual labels:  github-actions
portfolio
Site built from fastpages: https://fastpages.fast.ai/. Deployed here 👉
Stars: ✭ 16 (-89.26%)
Mutual labels:  github-actions
ci-skip
CI skip comment
Stars: ✭ 35 (-76.51%)
Mutual labels:  github-actions
action-dotenv-linter
GitHub Action to run dotenv-linter ⚡️
Stars: ✭ 14 (-90.6%)
Mutual labels:  github-actions
actions-NjuHealthReport
Github Actions: 完成每日健康填报打卡,So easy
Stars: ✭ 68 (-54.36%)
Mutual labels:  github-actions
changelog-generator
GitHub Action to generate changelogs, release notes, whatever
Stars: ✭ 95 (-36.24%)
Mutual labels:  github-actions
push-package-action
| Public | GitHub Action to Push a Package to Octopus Deploy
Stars: ✭ 23 (-84.56%)
Mutual labels:  github-actions
actions-js-build
GitHub Actions for running Javascript build tools and committing file changes
Stars: ✭ 46 (-69.13%)
Mutual labels:  github-actions
assign-author
GitHub Actions to assign author to issue or PR
Stars: ✭ 55 (-63.09%)
Mutual labels:  github-actions
verify-linked-issue-action
A GitHub action that verifies your pull request contains a reference to an issue.
Stars: ✭ 18 (-87.92%)
Mutual labels:  github-actions
CodeforcesApiPy
Implementation of https://codeforces.com API
Stars: ✭ 17 (-88.59%)
Mutual labels:  github-actions
setup-graalvm
No description or website provided.
Stars: ✭ 63 (-57.72%)
Mutual labels:  github-actions
mc-publish
GitHub Action that helps you publish your Minecraft mods
Stars: ✭ 76 (-48.99%)
Mutual labels:  github-actions

Get Diff Action

CI Status codecov CodeFactor License: MIT

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

GitHub actions to get git diff.
You can get the differences via env or action output.

Table of Contents

Details

generated with TOC Generator

Screenshots

  1. Example workflow

    Example workflow

  2. Skip

    Skip

Usage

Basic 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@v6
        with:
          PATTERNS: |
            +(src|__tests__)/**/*.ts
            !src/exclude.ts
          FILES: |
            yarn.lock
            .eslintrc
      - name: Install Package dependencies
        run: yarn install
        if: env.GIT_DIFF
      - name: Check code style
        # Check only if there are differences in the source code
        run: yarn lint
        if: env.GIT_DIFF

Details of the patterns that can be specified

Example of matching files

  • src/main.ts
  • src/utils/abc.ts
  • __tests__/test.ts
  • yarn.lock
  • .eslintrc
  • anywhere/yarn.lock

Examples of non-matching files

  • main.ts
  • src/xyz.txt
  • src/exclude.ts

Examples of env

name value
GIT_DIFF 'src/main.ts' 'src/utils/abc.ts' '__tests__/test.ts' 'yarn.lock' '.eslintrc' 'anywhere/yarn.lock'
GIT_DIFF_FILTERED 'src/main.ts' 'src/utils/abc.ts' '__tests__/test.ts'
MATCHED_FILES 'yarn.lock' '.eslintrc' 'anywhere/yarn.lock'

Specify a little more detail

on: pull_request
name: CI
jobs:
  eslint:
    name: ESLint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v6
        with:
          PATTERNS: |
            +(src|__tests__)/**/*.ts
          FILES: |
            yarn.lock
            .eslintrc
      - name: Install Package dependencies
        run: yarn install
        if: env.GIT_DIFF
      - name: Check code style
        # Check only source files with differences
        run: yarn eslint ${{ env.GIT_DIFF_FILTERED }}  # e.g. yarn eslint 'src/main.ts' '__tests__/test.ts'
        if: env.GIT_DIFF && !env.MATCHED_FILES
      - name: Check code style
        # Check only if there are differences in the source code (Run a lint on all files if there are changes to yarn.lock or .eslintrc)
        run: yarn lint
        if: env.GIT_DIFF && env.MATCHED_FILES

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: 'AMRC'

    =>

    git diff ${FROM}...${TO} '--diff-filter=AMRC' --name-only

    =>

    .github/workflows/ci.yml
    __tests__/utils/command.test.ts
    package.json
    src/main.ts
    src/utils/command.ts
    src/docs.md
    yarn.lock
    

    ${FROM}, ${TO}

  2. Filtered by PATTERNS option

    e.g.

    PATTERNS: |
      src/**/*.+(ts|md)
      !src/utils/*

    =>

    src/main.ts
    src/docs.md
    
  3. Filtered by FILES option

    e.g.

    FILES: package.json

    =>

    package.json
    anywhere/package.json
    
  4. 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/docs.md
    
  5. Combined by SEPARATOR option

    e.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/docs.md
    

Outputs

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/docs.md
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. (Available only if GET_FILE_DIFF is true)
If inputs SET_ENV_NAME_INSERTIONS(default: '') is set, an environment variable is set with that name.
100
deletions The number of deletions lines. (Available only if GET_FILE_DIFF is true)
If inputs SET_ENV_NAME_DELETIONS(default: '') is set, an environment variable is set with that name.
100
lines The number of diff lines. (Available only if GET_FILE_DIFF is true)
If inputs SET_ENV_NAME_LINES(default: '') is set, an environment variable is set with that name.
200

Action event details

Target events

eventName action
pull_request opened, reopened, synchronize, closed, ready_for_review
push *

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

Addition

FROM, TO

condition FROM TO
tag push --- ---
pull request pull.base.ref (e.g. main) context.ref (e.g. refs/pull/123/merge)
push (which has related pull request) pull.base.ref (e.g. main) refs/pull/${pull.number}/merge (e.g. refs/pull/123/merge)
context.payload.before = '000...000' default branch (e.g. main) context.payload.after
else context.payload.before context.payload.after

Check only the latest commit differences in a draft Pull Request

on:
  pull_request:
    types: [opened, reopened, synchronize, closed, ready_for_review]

jobs:
  eslint:
    name: ESLint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v6
        with:
          CHECK_ONLY_COMMIT_WHEN_DRAFT: true
      # ...

To get the result in Json format

on: pull_request
name: CI
jobs:
  dump:
    name: Dump
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v6
        with:
          PATTERNS: |
            +(src|__tests__)/**/*.ts
            !src/exclude.ts
          FORMAT: json
      - run: echo '${{ env.GIT_DIFF }}' | jq .

Result:

> Run echo '["yarn.lock"]' | jq .
[
  "yarn.lock"
]

Specify a relative path

GitHub Actions doesn't support working-directory for uses, so you can't run this action separately for monorepo configuration, etc. However, if you specify the RELATIVE option, it will be used as --relative=<RELATIVE> for git diff.

https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---relativeltpathgt

on: pull_request
name: CI
jobs:
  dump:
    name: Dump
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v6
        with:
          PATTERNS: '*.ts'
          RELATIVE: 'src/abc'
      - run: echo ${{ env.GIT_DIFF }}

If the files src/abc/test1.ts, src/abc/test2.ts, src/abc/test3.txt, and src/test4.ts exist, the result will be as follows:

> Run echo 'test1.ts' 'test2.ts'
test1.ts test2.ts

Author

GitHub (Technote)

Blog

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].