EndBug / add-and-commit

:octocat: Automatically commit changes made in your workflow run directly to your repo
MIT License
1.15k stars 117 forks source link

Run the action from a different directory #70

Closed xavierfoucrier closed 4 years ago

xavierfoucrier commented 4 years ago

Hi,

I am trying to use this Github Actions to push a VuePress website from a source branch to a master branch. The website is generated using a regular npm run build script and the build outputs to ./docs/.vuepress/dist.

./ here is the root of my repo.

I would like to only push files inside of this directory to the master, not the whole path.

The problem is that currently the action is running git add from the root folder, instead of running it from .docs/.vuepress/dist... resulting in having the full path pushed to the master branch.

As for now Github Actions working-directory can't be used in addition with the uses command, it would be nice to have a directory option to tell the action where to run the git add command.

Here is my worflow:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      (...)
      - name: Commit changes
        uses: EndBug/add-and-commit@master
        with:
          branch: "master"
          add: "docs/.vuepress/dist --force"
          message: "Deploy docs"

Here is a workflow we could have:

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      (...)
      - name: Commit changes
        uses: EndBug/add-and-commit@master
        with:
          branch: "master"
          directory: "docs/.vuepress/dist" <--- the action will run "cd [directory]" command before running
          add: ". --force"
          message: "Deploy docs"

You can have a look at the current VuePress deploy script here: https://vuepress.vuejs.org/guide/deploy.html#github-pages

Thanks for your feedback! :wink:

EndBug commented 4 years ago

I'm not sure if I understand this correctly: what's the difference between adding docs/.vuepress/dist and adding . from that path? Anyway, have you tried using the cwd option?

xavierfoucrier commented 4 years ago

Hi @EndBug,

Thanks for the fast reply :wink:

The problem is that when running the action at the repository root will lead the git add command to push the whole docs/.vuepress/dist path to the repository root.

Here you can see what I mean: https://github.com/mojs/mojs.github.io/tree/2077e38b39b6ea845d8b94eadbbd06144c7a135d

So my repository master branch should finally look like this:

I have read the whole docs, but may be I am missing something...

Does the cwd option change the working directory where the Github Actions run? If yes, this is exactly what I am searching for.

Let me know :smiley:

EndBug commented 4 years ago

Ooooooh, ok sorry, now I get it. I think it would be easier if you moved the files before running my action: you can use something like cp -r docs/.vuepress/dist/. . && rm -r docs

Your workflow would look like this:

steps:
  (...)
  - run: 'cp -r bla bla bla'
  - uses: EndBug/add-and-commit@v5
  (...)
EndBug commented 4 years ago

This way you're running the action when your directory has already the right structure

xavierfoucrier commented 4 years ago

@EndBug Haaaaaa... sounds like a good idea too, I will try that and let you know :smiley: , thx!

xavierfoucrier commented 4 years ago

@EndBug hum.. well, the problem is that using rm -r docs won't be sufficient because I have other files/folders in the root directory :smile: :thinking: , like node_modules. So I have to manage a "static" list of directory here, not appropriate from my point of view.

In addition a step can't run both run and uses keywords, see https://github.com/mojs/mojs.github.io/actions/runs/335569327. But I understand that I have to run two "steps" separately for your solution, but it won't work.

EndBug commented 4 years ago

Well you should have a .gitignore that prevents the unwanted directories from being added: you have to think about how you would add those files if you were just using git from the terminal, the action is only supposed to "Add and Commit" If you set up your project and scripts like you would normally do with git, you'll have no problem using the action.

(I know they can't be used both in the same, I've written the example using two different ones...)

xavierfoucrier commented 4 years ago

Good point, but the problem is that I need to run the add action's option with --force because the docs/.vuepress/dist folder is ignored in the source branch, as it is made to contain "build" stuff and shouldn't be versioned... making node_modules folder pushed when using --force, which is part of the problem.

That's why the VuePress documentation state to "navigate" into the dist build folder.

EndBug commented 4 years ago

The Vue docs say to navigate to that directory only because they're creating a new repo and then pushing to a custom URL, which my action doesn't currently support.

This are your options:

In any of these three ways, there are no changes needed for the action.

xavierfoucrier commented 4 years ago

Fine, I will choose the more appropriate option. Thanks for the fast answers/support anyway!

I am closing the issue :wink:

EndBug commented 4 years ago

Happy to help!