Closed staabm closed 2 years ago
Will try to add a failing test for this case later this week. (Seems easy to test by adding 2 file patterns but only adding 1 dirty file)
Wonder if this could be solved by adding --ignore-errors
to add_options
. Maybe you can give this a try?
- name: Commit changed files
if: "github.event_name == 'repository_dispatch'"
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply phpstan-baseline changes
branch: ${{ github.head_ref }}
file_pattern: '*.neon *dba.cache'
+ add_options: '--ignore-errors'
thx for the fast reply.
Wonder if this could be solved by adding
--ignore-errors
toadd_options
. Maybe you can give this a try?
I tried that and it resulted in the same error:
M composer.json
M phpstan-baseline.neon
Your branch is up to date with 'origin/clxmstaab-patch-1'.
INPUT_ADD_OPTIONS: --ignore-errors
INPUT_FILE_PATTERN: *.neon *dba.cache
fatal: pathspec '*dba.cache' did not match any files
Error: Invalid status code: 128
at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1022:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) {
code: 128
}
Error: Invalid status code: 128
at ChildProcess.<anonymous> (/home/runner/work/_actions/stefanzweifel/git-auto-commit-action/v4/index.js:17:19)
at ChildProcess.emit (events.js:314:20)
at maybeClose (internal/child_process.js:1022:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
I've added 2 tests covering this issue in 571d6b7.
The file pattern I've used: *.foo *.bar
.
What I've discovered:
git-add
. git-add
fails with a fatal error if for atleast 1 file for the given pattern doesn't exist.
example.foo
file, but not a example.bar
file and no *.bar
file exists in the repository.git-add
does not fail, if files for the given pattern already exist in the repository.
example.foo
file, but no example.bar
file. A default.bar
already exists in the repository.We could solve this problem by adding yet another option to this action. Something like a git_add_file_pattern
or add_file_pattern
. If the option exists it takes precedence over file_pattern
, which is also used in git-status
.
But this seems to be very rare edge case. I would like the keep the Action simple and not riddled with solutions for edge cases. :)
For your specific problem, it would probably make sense to add an empty void.dba.cache
file to the repository. The file doesn't have to be updated by a workflow, a file just needs to exist that matches the pattern.
Thx for investigating.
I think I can work arround this problem on my end, without a new option.
Maybe its worth a note in the readme?
Maybe its worth a note in the readme?
Will add a note for this in the README.
@staabm Were you able to find a workaround for this? I have recently encountered the same issue, and was wondering if you were able to get around this with one of the existing parameters.
@erikumhoefer i went with what was suggested above
For your specific problem, it would probably make sense to add an empty void.dba.cache file to the repository. The file doesn't have to be updated by a workflow, a file just needs to exist that matches the pattern.
Hi @stefanzweifel , I've read this thread because I'm facing the same issue. It's not so uncommon to plan for committing files which aren't there yet but might be one day in the context of reusable workflows. When building a set of reusable pipelines then the workflow needs to be thought adaptive. Only sharing my opinion, I bet you'll get the same issue opened again in the future.
Hi @stefanzweifel , I've read this thread because I'm facing the same issue. It's not so uncommon to plan for committing files which aren't there yet but might be one day in the context of reusable workflows. When building a set of reusable pipelines then the workflow needs to be thought adaptive. Only sharing my opinion, I bet you'll get the same issue opened again in the future.
Hi! Yes, + 1.
I'm having the same problem, I'm creating an automatic formatter and sometimes it only contains js and sometimes only css but it throws an error that no such file exists, I would also suggest that there should be some option to handle this kind of case.
Anyway, this little script is very good and easy to use, thanks a lot :)
@Gellipapa @cathex-matt Would you both be able to share your current workflows here? (The exact configuration you're using for git-auto-commit-action
)
I obviously also would like to solve this issue, but after re-reading my proposed solution from a year ago (https://github.com/stefanzweifel/git-auto-commit-action/issues/227#issuecomment-1169075106), I don't think that adding an additional option would really solve the problem.
git-add
would still fail with a fatal error, if a file for a given pattern doesn't exist. Or maybe it's just too early in the morning for me to see the right solution here. Will have to think more about this.
@stefanzweifel Hi! So I solved the problem by selecting the extension of the files in a python script and passing it to filter_pattern. There should be some way to check in the background if such a file currently exists and if not then don't add that file type, but yes it can be quite complicated to fix this error.
name: formatter-prettier
on:
push:
branches: [ main ]
pull_request:
types: [ labeled ]
jobs:
formatter:
name: formatter
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.label.name == 'format') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: "16"
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v37
with:
files: |
**/*.{js,html,css}
!**/*.yml
!**/*.min.js
- name: List all changed files
run: |
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "$file was changed"
done
- name: Get file extensions
if: steps.changed-files.outputs.any_changed == 'true'
id: getext
run: |
import os
files = '${{ steps.changed-files.outputs.all_changed_files }}'.split()
extensions = set('*' + os.path.splitext(file)[1] for file in files)
with open(os.getenv('GITHUB_ENV'), 'a') as f:
f.write(f"CHANGED_EXTENSIONS={' '.join(extensions)}\n")
shell: python
- name: Format changed files with Prettier
if: steps.changed-files.outputs.any_changed == 'true'
run: |
npx prettier --write ${{ steps.changed-files.outputs.all_changed_files }}
- name: Update repo before push
run: |
git pull
- name: Commit changed files and push current branch
if: steps.changed-files.outputs.any_changed == 'true'
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_user_name: ESX GITHUB ACTIONS BOT
commit_user_email: esx-github-actions-bot@users.noreply.github.com
commit_message: :art:Code formatted in ${{ env.CHANGED_EXTENSIONS }} files
file_pattern: ${{ env.CHANGED_EXTENSIONS }}
status_options: '--untracked-files=no'
I also have the same problem, my workflow generates .svg
p and .png
files from .d2
diagram files.
@stefanzweifel Should we keep discussing/motivating a change in this issue, or would you prefer if a new one is opened?
I think having a built-in way to handle this would be much appreciated and useful.
@MPV If it's about a proposal on how to handle these errors in a built-in way, I would say feel free to open a new issue/discussion.
Version of the Action
v4
Describe the bug In a workflow, which sometimes changes x.neon or x.dba.cache files, I am running into the following error:
I am wondering that the pathspec is handled as required files.. we don't generate this files every time.. so I didn't expect this error
To Reproduce .
Expected behavior No error, since the pattern matched at least one of the path specs
Screenshots If applicable, add screenshots to help explain your problem.
Used Workflow
Additional context Add any other context about the problem here.