Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add support for returning directory names if all files within the directory has been deleted #1595

Closed
4 tasks done
AliaksandrRyzhou opened this issue Sep 21, 2023 · 10 comments · Fixed by #1597 or #1601
Closed
4 tasks done
Labels
enhancement New feature or request

Comments

@AliaksandrRyzhou
Copy link

AliaksandrRyzhou commented Sep 21, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Does this issue exist in the latest version?

  • I'm using the latest release

Describe the bug?

Inputs files and files_ignore don't work as expected. I want to create different matrixes, depending on all_modified_files and deleted_files.

To Reproduce

I use the following workflow (Inputs files and files_ignore I will add bellow):

name: 'TEST Helm Charts Deployment'
run-name: 'TEST Deployment by @${{ github.actor }}'

on:
  push:
    branches: ["main"]
    paths:
      - 'charts/**'
      - '!charts/*.md'
      - '!charts/**/*.md'
      - '!charts/repos.txt'
env:
  CHARTS_DIRECTORY: "${{ github.workspace }}/charts"

jobs:
  helm-charts:
    runs-on: ubuntu-latest
    name: 'Getting charts for change'
    outputs:
      matrix_upgrade: ${{ steps.set-matrix-upgrade.outputs.matrix_upgrade }}
      matrix_delete: ${{ steps.set-matrix-delete.outputs.matrix_delete }}
    steps:
      - name: Checkout
        uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac
        with:
          fetch-depth: 0

      - name: Get changed directories
        id: changed-files
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

      - name: Get deleted directories
        id: deleted-directories
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

      - id: set-matrix-upgrade
        run: |
          echo "matrix_upgrade={\"charts_upgrade\":${{ steps.changed-files.outputs.all_modified_files }}}" >> "$GITHUB_OUTPUT"

      - id: set-matrix-delete
        run: |
          echo "matrix_delete={\"charts_delete\":${{ steps.deleted-directories.outputs.deleted_files }}}" >> "$GITHUB_OUTPUT"

With this folder structure, it's a content of charts folder :

chart1
chart1/.helmignore
chart1/Chart.yaml
chart1/values.yaml
chart1/charts
chart1/templates
chart1/templates/deployment.yaml
chart1/templates/service.yaml
chart1/templates/serviceaccount.yaml
chart1/templates/ingress.yaml
chart1/templates/NOTES.txt
chart1/templates/_helpers.tpl
chart1/templates/hpa.yaml
chart1/templates/tests
chart1/templates/tests/test-connection.yaml
chart2
chart2/.helmignore
chart2/Chart.yaml
chart2/values.yaml
chart2/charts
chart2/templates
chart2/templates/deployment.yaml
chart2/templates/service.yaml
chart2/templates/serviceaccount.yaml
chart2/templates/ingress.yaml
chart2/templates/NOTES.txt
chart2/templates/_helpers.tpl
chart2/templates/hpa.yaml
chart2/templates/tests
chart2/templates/tests/test-connection.yaml
chart3
chart3/.helmignore
chart3/Chart.yaml
chart3/values.yaml
chart3/charts
chart3/templates
chart3/templates/deployment.yaml
chart3/templates/service.yaml
chart3/templates/serviceaccount.yaml
chart3/templates/ingress.yaml
chart3/templates/NOTES.txt
chart3/templates/_helpers.tpl
chart3/templates/hpa.yaml
chart3/templates/tests
chart3/templates/tests/test-connection.yaml
README.md
repos.txt

What OS are you seeing the problem on?

ubuntu-latest or ubuntu-22.04

Expected behavior?

The idea is to get output deleted_files in JSON which contains folders [\"chart1\",\"chart2\",\"chart3\"] only if these folders are deleted at all. It's very important to exclude any deletions and changes inside these folders because if it works wrong my workflow will delete a working chart.

Also, in the second step, I want to get all_modified_files in JSON which contains folders inside of which any changes were. Added, copied, modified, renamed, and deleted files. In this step is very important to not receive a folder if it was deleted at all.

Honestly, I tried about 100 options, with verification at codepen and more successful ones, which are not described bellow because I no longer remember them. The main thing is to get the result so that the deletion matrix contains only folders in the charts directory and only if these folders were deleted themselves. The update matrix received a list of charts in which something was changed but did not receive folders from the root charts directory.

1. This case shows nothing when I change one file within chart1, chart2, and chart3 folders. The same thing if I delete some folder, for example, chart3.

      - name: Get changed directories
        ...
          files: |
            */**/*.*
            */**/.*
            */**/*
          files_ignore: |
            *

      - name: Get deleted directories
        ...
          files: |
            *
          files_ignore: |
            */**/*.*
            */**/.*
            */**/*

Logs
"matrix_upgrade={"charts_upgrade":[]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

2. This case shows nothing when I change one file within chart1, chart2, and chart3 folders. The same thing if I delete some folder, for example, chart3.

      - name: Get changed directories
        ...
          files: |
            **
          files_ignore: |
            *

      - name: Get deleted directories
        ...
          files: |
            **
          files_ignore: |
            *

Logs
"matrix_upgrade={"charts_upgrade":[]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

3. This case shows nothing when I change one file within chart1, chart2, and chart3 folders. The same thing if I delete some folder, for example, chart3.

      - name: Get changed directories
        ...
          files: |
            */**
          files_ignore: |
            **/

      - name: Get deleted directories
        ...
          files_ignore: |
            */**

Logs
"matrix_upgrade={"charts_upgrade":[]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

4. This case shows the correct matrix if we change the files within any folder but if we delete the folder it will show nothing for matrix_delete and will show the changes in matrix_upgrade.

      - name: Get changed directories
        ...
          files: |
            */**/{*,*.*,.*}

      - name: Get deleted directories
        ...
          files_ignore: |
            */**/{*,*.*,.*}

Logs
Files was changed in chart1, chart2, and chart3 folders (correct!):
"matrix_upgrade={"charts_upgrade":["chart3","chart1","chart2"]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

Folder chart3 was deleted (wrong!):
"matrix_upgrade={"charts_upgrade":["chart3"]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

5. This case shows the correct matrix if we change the files within any folder and now, if we delete the folder it will show the deleted folder in matrix_delete and will show the changes in matrix_upgrade.

      - name: Get changed directories
        ...
          files: |
            */**/{*,*.*,.*}

      - name: Get deleted directories
        ...
          files: |
            *

Logs
Files was changed in chart1, chart2, and chart3 folders (correct!):
"matrix_upgrade={"charts_upgrade":["chart3","chart1","chart2"]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":[]}" >> "$GITHUB_OUTPUT"

Folder chart3 was deleted, now we can see the correct matrix for the deletion but also we still see the wrong result for matrix_upgrade (wrong!):
"matrix_upgrade={"charts_upgrade":["chart3"]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":["chart3"]}" >> "$GITHUB_OUTPUT"

I deleted one file in folder chart1 (for matrix_delete result is wrong!):
"matrix_upgrade={"charts_upgrade":["chart1"]}" >> "$GITHUB_OUTPUT"
"matrix_delete={"charts_delete":["chart1"]}" >> "$GITHUB_OUTPUT"

Relevant log output

Log files:

case1.zip

case2.zip

case3.zip

case4-changed-files-in-all-folders.zip

case4-deleted-one folder.zip

case5-changed-files-in-all-folders.zip

case5-deleted-one folder.zip

case5-deleted-one-file-in-chart1-folder.zip

Has all relevant logs been included?

  • I've included all relevant logs

Anything else?

Code of Conduct

  • I agree to follow this project's Code of Conduct
@AliaksandrRyzhou AliaksandrRyzhou added the bug Something isn't working label Sep 21, 2023
@github-actions
Copy link
Contributor

Thanks for reporting this issue, don't forget to star this project if you haven't already to help us reach a wider audience.

@AliaksandrRyzhou AliaksandrRyzhou changed the title [BUG] <title> Inputs files and files_ignore don't work as expected Sep 21, 2023
@jackton1
Copy link
Member

jackton1 commented Sep 21, 2023

Hi @AliaksandrRyzhou, is there a reason you are changing the default repository location by setting?

path: ${{ env.CHARTS_DIRECTORY }}

@jackton1
Copy link
Member

jackton1 commented Sep 21, 2023

I’ll also point out that you don’t need two different steps to detect deleted and changed files.

      - name: Get changed directories
        id: changed-files
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

# Not required
      - name: Get deleted directories
        id: deleted-directories
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

@AliaksandrRyzhou
Copy link
Author

Hi @AliaksandrRyzhou, is there a reason you are changing the default repository location by setting?

path: ${{ env.CHARTS_DIRECTORY }}

Hi @jackton1, yes. I have to monitor only this folder and receive the folder names from it. To be fair I tried to change path on one level up but it didn't work as well either and I'm not sure that I can create this approach (generate matrix) if I get folders with "dir_names_max_depth: 2"

@AliaksandrRyzhou
Copy link
Author

I’ll also point out that you don’t need two different steps to detect deleted and changed files.

      - name: Get changed directories
        id: changed-files
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

# Not required
      - name: Get deleted directories
        id: deleted-directories
        uses: tj-actions/changed-files@v39
        with:
          dir_names: true
          dir_names_max_depth: 1
          dir_names_exclude_current_dir: true
          path: ${{ env.CHARTS_DIRECTORY }}
          json: true
          output_renamed_files_as_deleted_and_added: true
          quotepath: false

I know that I can get it in one step but in this case, I can't make restrictions where I'd like to see changes with options files and files_ignore. I want to get all_modified_files which includes deleted files as well.

@jackton1
Copy link
Member

The directory output is based on the files in the folder when you use the files and files_ignore inputs and it’s also global so you can’t use ** as patterns to ignore the files within all folders.

@jackton1
Copy link
Member

This would be a feature request as opposed to a bug since you mentioned that you only want to consider deletion of the entire folder as the requirement to return and of the directories themselves.

And the second case of not considering a deletion of the folder when returning a list of the modified directories.

@AliaksandrRyzhou
Copy link
Author

The directory output is based on the files in the folder when you use the files and files_ignore inputs and it’s also global so you can’t use ** as patterns to ignore the files within all folders.

Do you mean files and files_ignore inputs work globally? Not inside a folder that we defined using path?

@jackton1
Copy link
Member

jackton1 commented Sep 21, 2023

I mean the path input is completely independent of the files and files_ignore input.

The path controls where to find the repository i.e. the working directory

All patterns that are provided via the files and files_ignore input, filter paths that are within the working directory i.e. everything under charts if it's the working directory.

@jackton1 jackton1 added enhancement New feature or request and removed bug Something isn't working labels Sep 21, 2023
@jackton1 jackton1 changed the title Inputs files and files_ignore don't work as expected [Feature]: Add support for returning directory names if all files within the directory has been deleted Sep 21, 2023
@jackton1
Copy link
Member

jackton1 commented Sep 21, 2023

First step

The idea is to get output deleted_files in JSON which contains folders ["chart1","chart2","chart3"] only if these folders are deleted at all. It's very important to exclude any deletions and changes inside these folders because if it works wrong my workflow will delete a working chart.

Second step

Also, in the second step, I want to get all_modified_files in JSON which contains folders inside of which any changes were. Added, copied, modified, renamed, and deleted files. In this step is very important to not receive a folder if it was deleted at all.

@AliaksandrRyzhou In the case of the second step you don't need to set the files or files_ignore as the default behaviour is to return any directory with added, copied, modified, renamed, and deleted files.

The first step in this case needs to be a new option to only return the directory name if all files within the folder have been deleted as opposed to if any file within the folder was deleted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants