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

globbing syntax is limited #51

Closed
xxxserxxx opened this issue Mar 7, 2020 · 8 comments · Fixed by #65
Closed

globbing syntax is limited #51

xxxserxxx opened this issue Mar 7, 2020 · 8 comments · Fixed by #65

Comments

@xxxserxxx
Copy link

Version of the Action
v4.1.0

Describe the bug
Maybe this only requires a bit more documentation. However, it's not clear which syntax file_pattern uses, and under what conditions. Is it a bash glob? Or some other language? Why are the asterixes escaped? The bash syntax \{\*\*/PKGBUILD,\*\*/.SRCINFO\} does not work (escaped out so Workflows doesn't complain about the syntax), and neither does \*\*/PKGBUILD \*\*/.SRCINFO or any combination of syntax I've tried. Wrapping the glob in quotes, various permutations of escaping; I've tried several things.

Curiously, I can see globbing working, except it fails somehow when actually doing the git commit. In many cases, I get errors like:

INPUT_BRANCH value: 
M	aur-bin/.SRCINFO
M	aur-bin/PKGBUILD
M	aur/.SRCINFO
M	aur/PKGBUILD
Your branch is up to date with 'origin/master'.
INPUT_FILE_PATTERN: \{\*\*/PKGBUILD,\*\*/.SRCINFO\}
fatal: pathspec '\{\*\*/PKGBUILD,\*\*/.SRCINFO\}' did not match any files

so the log message is actually getting a proper glob list, but it fails in the actual message.

It'd be great to get some documentation about what is legal glob syntax, and maybe another example of non-trivial globbing. In my case, I'm looking for the result of the bash glob pattern:

{**/PKGBUILD,**/.SRCINFO}

To Reproduce
Make a project in github called globtest

mkdir -p dummy/A dummy/B dummy/.github/workflows/
pushd dummy
touch A/x A/y B/x B/y
cat > .github/workflows/dummy.yml <<EOL
name: dummy
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Get version
        shell: bash
        run: echo 1 > A/x ; echo 2 > A/y ; echo 3 > B/x ; echo 4 > B/y
      - uses: stefanzweifel/[email protected]
        with:
            commit_message: Message
            file_pattern: \{\*\*/x,\*\*/y\}
EOL
git init && git add . && git commit -m "X"
git remote add origin [email protected]:stefanzweifel/globtest.git
git push -f origin master
touch me && git commit -a -m "foo" && git push

Expected behavior
All changed files to be committed.

I didn't try any of that blob of steps above, so YMMV. But you get the idea.

@stefanzweifel
Copy link
Owner

Thanks for writing such a detailed issue! I'm grateful when users write such detailed descriptions of their problems.

However, it's not clear which syntax file_pattern uses, and under what conditions. Is it a bash glob? Or some other language? Why are the asterixes escaped?

The syntax used is whatever git uses. In the git-add documentation the option is called pathspec (pathspec documentation).
In their gloassary there's even more information. There, they don't seem to escape the asterix.

It seems, this might be a documentation issue on our side for this Action. However, in #13, when the feature was added, I could successfully test the Action with the src/\*.js pattern.

@xxxserxxx
Copy link
Author

xxxserxxx commented Mar 7, 2020

@stefanzweifel The trivial example does work. Is git being run in a bash instance? Is it making an API call to git, or is it executing a command in some shell environment?

Thanks for the pointers to the pathspec; that does help. Do you know the escaping rules? Is the escaping only for workflows, so the engine doesn't choke on the arguments, or is it for the environment git is running in?

Edit

On the command line, git accepts multiple path specs:

git add a/x b/y c/z

Any idea why this doesn't work in the argument?

file_pattern: a/x b/y

generates a "no file found" error.

@stefanzweifel
Copy link
Owner

Is git being run in a bash instance? Is it making an API call to git, or is it executing a command in some shell environment?

I honestly don't know how to answer that question correctly. All I can tell is that the git-cli is executed on the command line in some shell environment. If you've chosen to run the Workflow on a linux machine, I guess it's bash.

Do you know the escaping rules? Is the escaping only for workflows, so the engine doesn't choke on the arguments, or is it for the environment git is running in?

I don't know the escaping rules, sorry.
Maybe the docs for GitHub Actions can help you further. I highly recommend reading all pages of them.

@cristianpb
Copy link
Contributor

I had the same issue when adding multiple files.

Replacing line https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh#L48

git add "${INPUT_FILE_PATTERN}"

by

git add ${INPUT_FILE_PATTERN}

solves the issue.

Should I made a PR @stefanzweifel ?

@stefanzweifel
Copy link
Owner

@cristianpb That would be great.

@vikyd
Copy link

vikyd commented Feb 3, 2021

Thanks for writing such a detailed issue! I'm grateful when users write such detailed descriptions of their problems.

However, it's not clear which syntax file_pattern uses, and under what conditions. Is it a bash glob? Or some other language? Why are the asterixes escaped?

The syntax used is whatever git uses. In the git-add documentation the option is called pathspec (pathspec documentation).
In their gloassary there's even more information. There, they don't seem to escape the asterix.

It seems, this might be a documentation issue on our side for this Action. However, in #13, when the feature was added, I could successfully test the Action with the src/\*.js pattern.


In my case file_pattern: ./\*.md is not woking. Don't know why.

@stefanzweifel
Copy link
Owner

@vikyd What exactly do you wanna achieve?

To add all changed markdown files use file_pattern: *.md
To only add changed markdown files in subfolders use file_pattern: */*.md.

@cristianpb
Copy link
Contributor

@vikyd you can also just do something custom, like:

      - name: Auto commit
        run: |
          git config --global user.name 'Github Bot'
          git config --global user.email '[email protected]'
          git add *.md
          git commit -m "⬆ Commit markdown files"
          git push origin HEAD:master

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

Successfully merging a pull request may close this issue.

4 participants