Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

GIT_DIFF includes all files #127

Closed
peterbe opened this issue Oct 12, 2020 · 5 comments
Closed

GIT_DIFF includes all files #127

peterbe opened this issue Oct 12, 2020 · 5 comments
Assignees

Comments

@peterbe
Copy link
Contributor

peterbe commented Oct 12, 2020

Describe the bug: バグの概要

To Reproduce: 再現手順

Steps to reproduce the behavior:

  1. Go to Bump technote-space/get-diff-action from v3 to v4 mdn/yari#1419
  2. Click on https://github.com/mdn/yari/pull/1419/checks?check_run_id=1240693958
  3. Scroll down to the error
  4. See error

Expected behavior: 期待する動作

Not even run anything because the PR didn't contain any changes to (PREFIX) docs and (SUFFIX) .md or the README.md.

Additional context: 補足

Perhaps I'm misinterpreting the documentation but I was expecting env.GIT_DIFF to be the result of the filtering I do with PREFIX, SUFFIX, and FILES. Not the bare naked git diff of the PR.

Is this regression from v3 or am I just not understanding the documentation for v4??

@technote-space
Copy link
Owner

A destructive change has been made to filter using PATTERNS, instead of prefix and suffix filters, to add a way to exclude certain patterns (#122).

Usage:
https://github.com/technote-space/get-diff-action#usage

The library used to specify the pattern:
https://github.com/isaacs/minimatch#minimatch

e.g.

          SUFFIX_FILTER: .html
          PREFIX_FILTER: files/

          PATTERNS: files/**/*.html

 

          SUFFIX_FILTER: _redirects.txt
          PREFIX_FILTER: files/

          PATTERNS: files/**/_redirects.txt

 

          SUFFIX_FILTER: |
            .png
            .jpeg
            .jpg
            .gif
            .svg
            .webp
          PREFIX_FILTER: files/

          PATTERNS: files/**/*.+(png|jpeg|jpg|gif|svg|webp)

If you don't want to be case insensitive, use the MINIMATCH_OPTION_NOCASE option.

          PATTERNS: files/**/*.+(png|jpeg|jpg|gif|svg|webp)
          MINIMATCH_OPTION_NOCASE: 1

https://github.com/technote-space/get-diff-action/blob/master/action.yml

@peterbe
Copy link
Contributor Author

peterbe commented Oct 12, 2020

Oh my! It helps if I read the changelog. :)
In my defense, this is all I saw when the PR came in from Dependabot:
Screen Shot 2020-10-12 at 3 15 40 PM

By the way, do you know if there's a way to "bail" early in a build? Look at this for example:

  deployer:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - uses: technote-space/get-diff-action@v4
        with:
          PATTERNS: deployer/**

      - name: Install Python
        if: env.GIT_DIFF
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"

      - name: Install Python poetry
        if: env.GIT_DIFF
        uses: dschep/install-poetry-action@v1.3

      - name: Install deployer
        if: env.GIT_DIFF
        run: |
          cd deployer
          poetry install

      - name: Display Python & Poetry version
        if: env.GIT_DIFF
        run: |
          python --version
          poetry --version

      - name: Lint Python code
        if: env.GIT_DIFF
        run: |
          flake8 deployer
          black --check deployer

      - name: Basic run of deployer
        if: env.GIT_DIFF
        run: |
          cd deployer
          poetry run deployer --help

I have to type if: env.GIT_DIFF repeatedly for every step. It'd be cool if I could do this straight from the - uses: technote-space/get-diff-action@v4 step somehow.
But perhaps this is a GitHub Actions workflow thing in general and not exclusive to get-diff-action.

Close this issue?

@technote-space
Copy link
Owner

technote-space commented Oct 13, 2020

I think you can use "outputs" as in the example below.

  check:
    name: Diff check
    runs-on: ubuntu-latest
    outputs:
      diff: ${{ env.GIT_DIFF }}
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v4
        with:
          PATTERNS: deployer/**

  deployer:
    runs-on: ubuntu-latest
    needs: check
    if: needs.check.outputs.diff
    steps:
      - uses: actions/checkout@v2

      - name: Install Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"

      - name: Install Python poetry
        uses: dschep/install-poetry-action@v1.3

      - name: Install deployer
        run: |
          cd deployer
          poetry install

      - name: Display Python & Poetry version
        run: |
          python --version
          poetry --version

      - name: Lint Python code
        run: |
          flake8 deployer
          black --check deployer

      - name: Basic run of deployer
        run: |
          cd deployer
          poetry run deployer --help

https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs

@technote-space
Copy link
Owner

technote-space commented Oct 13, 2020

diff3

diff1

diff2

@peterbe
Copy link
Contributor Author

peterbe commented Oct 13, 2020

I think you can use "outputs" as in the example below.

  check:
    name: Diff check
    runs-on: ubuntu-latest
    outputs:
      diff: ${{ env.GIT_DIFF }}
    steps:
      - uses: actions/checkout@v2
      - uses: technote-space/get-diff-action@v4
        with:
          PATTERNS: deployer/**

  deployer:
    runs-on: ubuntu-latest
    needs: check
    if: needs.check.outputs.diff
    steps:
      - uses: actions/checkout@v2

      - name: Install Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"

      - name: Install Python poetry
        uses: dschep/install-poetry-action@v1.3

      - name: Install deployer
        run: |
          cd deployer
          poetry install

      - name: Display Python & Poetry version
        run: |
          python --version
          poetry --version

      - name: Lint Python code
        run: |
          flake8 deployer
          black --check deployer

      - name: Basic run of deployer
        run: |
          cd deployer
          poetry run deployer --help

https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idoutputs

Thanks for the tip! But it appears that would require doing the - uses: actions/checkout@v2 step twice. And in the parent job it'd be cloned but then just thrown away.
It might not matter if the repo is tiny and perhaps it doesn't matter if the clone is completely shallow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants