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

option to commit .github files #163

Closed
pawsong opened this issue Mar 17, 2020 · 39 comments
Closed

option to commit .github files #163

pawsong opened this issue Mar 17, 2020 · 39 comments
Assignees
Labels

Comments

@pawsong
Copy link

pawsong commented Mar 17, 2020

Thank you for sharing this good project :)

Is your feature request related to a problem? Please describe.
In some use cases, we want to commit .github workflow files so that we can trigger actions on gh-pages branch.

Describe the solution you'd like
An option to determine if .github files to commit or not.

Describe alternatives you've considered
I made a commit to disable .github filtering, but I know this is a temporary workaround.

specup@9cb1a7c

@peaceiris
Copy link
Owner

peaceiris commented Mar 17, 2020

Adding a new option exclude_files may be a good solution. I will think about the details.

  • .git should be always included in exclude_files.
  • Default: .git .github
  • When we set the option: .git file1 file2 ...
- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    exclude_files: |
      .env
      .nvmrc
  • Why we should not add the .github to the gh-pages branch by default?

@peaceiris peaceiris added the enhancement New feature or request label Mar 17, 2020
@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

If .git should be always excluded, then how about excluding .git regardless of exclude_files option?

Then default value of exclude_files would be .github.

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

Setting default value of exclude_files to .github or .git .github... both options look reasonable to me.

@peaceiris
Copy link
Owner

Yes. We can exclude .git from a publish directory regardless of the exclude_files and define .github as a default value of the exclude_files option.

inputs:
  exclude_files:
    description: 'Set files to exclude from a publish directory.'
    required: false
    default: '.github'

@peaceiris
Copy link
Owner

peaceiris commented Mar 17, 2020

To mean that the option has files or directories, we should probably call it exclude_assets.

inputs:
  exclude_assets:
    description: 'Set files or directories to exclude from a publish directory.'
    required: false
    default: '.github'

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

How to exclude only files under .git directory? Possibly we can set exclude_assets to false or empty string ('').

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    exclude_assets: false

Using false looks prettier for me.

@peaceiris
Copy link
Owner

Some users can have files that are named false or true, so I think empty is better.

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

I agree with you. Using empty string is better.

@Legion2
Copy link

Legion2 commented Mar 17, 2020

Why not excluding all files and directories starting with . by default. Because they are considered invisible.

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

Excluding all dot files will be a breaking change for existing users.

@Legion2
Copy link

Legion2 commented Mar 17, 2020

But else we have to discuss what is excluded by default. There are many dot files like the .gitignore you don't need to deploy to github pages. The simplest solution is to never deploy the root of the git repo, because it contains many configuration files.

@peaceiris
Copy link
Owner

For example, users who are using Static Site Generators (not GitHub Pages built-in Jekyll) need .nojekyll file.

@Legion2 See this case. Some users set publish_dir: ./ and others set a git submodule to publish_dir. So we should not exclude all dotfiles by default.

@Legion2
Copy link

Legion2 commented Mar 17, 2020

OK, but why should .github be excluded by default?

@pawsong
Copy link
Author

pawsong commented Mar 17, 2020

@Legion2 The reason is described here

#163 (comment)

Some users use publish_dir: ./ in there source code branch

@Legion2
Copy link

Legion2 commented Mar 17, 2020

OK now I understand. When .github is not excluded, it will trigger some workflows on the github pages branch and that should not happen.

@peaceiris peaceiris pinned this issue Mar 17, 2020
@corollari
Copy link
Contributor

If you end up going with some variation of exclude_assets I'd propose adding a warning or something to the readme explaining why .github is excluded by default, as the reason is not trivial.

@peaceiris
Copy link
Owner

If you end up going with some variation of exclude_assets I'd propose adding a warning or something to the readme explaining why .github is excluded by default, as the reason is not trivial.

Yes! We need a friendly description of the option.

It is probably useful to enable regular expression for the exclude_assets option. I will work on this issue on the weekend.

@github-actions

This comment has been minimized.

@Lucas-C

This comment has been minimized.

@peaceiris

This comment has been minimized.

@Lucas-C

This comment has been minimized.

@peaceiris

This comment has been minimized.

@radames
Copy link

radames commented Jun 24, 2020

forget my last message, I'm using @pawsong specup/actions-gh-pages@master temporary fix! thanks

@radames
Copy link

radames commented Jun 24, 2020

also just realize I could merge the steps of my action and didn't need to have another YAML on gh-pages branch! thanks But I can see that having you feature to selective exclude_files is a great way to go! rather than hardcode filtering .github thanks

@peaceiris
Copy link
Owner

Thank you for your feedback!

@peaceiris

This comment has been minimized.

@peaceiris peaceiris pinned this issue Jul 25, 2020
@Legion2
Copy link

Legion2 commented Jul 25, 2020

The @actions/glob package can be used to handle the glob patterns. It supports different patterns to include and exclude files https://github.com/actions/toolkit/tree/master/packages/glob#patterns.

@diauweb
Copy link

diauweb commented Jul 25, 2020

v3.7.0-5 is working for me now

@peaceiris
Copy link
Owner

peaceiris commented Jul 25, 2020

The beta v3.7.0-6 has been released. exclude_assets supports glob patterns.

Could someone test this?

The exclude_assets option has .github by default.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-6
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    # exclude_assets: ''  # Set empty to deploy .github
    # exclude_assets: 'exclude-file1,exclude-file2'  # Split multi files or directory with comma
    exclude_assets: '.github,exclude-file.txt,exclude-dir/**.txt'

@ericleong
Copy link

I am using peaceiris/actions-gh-pages@v3.7.0-8. I noticed a couple issues:

.git

Accidentally including .git in exclude_assets will cause the action to fail because git won't be able to commit the change:

[INFO] Keep existing files
[INFO] chdir /home/runner/actions_github_pages_1597182186809
[INFO] prepare publishing assets
...
[INFO] skip .git
[INFO] copy .github
...
[INFO] delete excluded assets
...
[INFO] delete /home/runner/actions_github_pages_1597182186809/.git
[INFO] delete /home/runner/actions_github_pages_1597182186809/.git/HEAD
[INFO] delete /home/runner/actions_github_pages_1597182186809/.git/config
...
[INFO] Created /home/runner/actions_github_pages_1597182186809/.nojekyll
[endgroup]
[group]Setup Git config
[command]/usr/bin/git remote rm origin
9343996Z fatal: not a git repository (or any of the parent directories): .git
[INFO] The process '/usr/bin/git' failed with exit code 128
[command]/usr/bin/git remote add origin ***github.com/ericleong/zoomwall.js.git
9440914Z fatal: not a git repository (or any of the parent directories): .git
[error]Action failed with "The process '/usr/bin/git' failed with exit code 128"

I am not very familiar with YAML so I also forgot to quote the exclude_assets parameter in the above example. In any case, an overly greedy glob like .* will include .git, so even though .git is not copied to the destination, it's still deleted.

Comma-delimiting

string.split(',') won't work for globs that have commas, like **/*.{js,ts}. A library like split-string could be used to split a list of quoted strings that have delimiters in them.

Personally I would rather have the list of files be separated by spaces because that is the shell convention:

exclude_assets: '.github "exclude file.txt" exclude-dir/**.{md,txt}'

Another idea is to use a YAML list:

exclude_assets: 
  - '.github'
  - 'exclude file.txt'
  - 'exclude-dir/**.{md,txt}'

@peaceiris
Copy link
Owner

peaceiris commented Aug 12, 2020

Thank you for the report and suggestion.

Enhancement

Accidentally including .git in exclude_assets

In any case, an overly greedy glob like .* will include .git, so even though .git is not copied to the destination, it's still deleted.

Since this action always ignores .git by default, we do not need to set .git to exclude_assets. (You can find the message [INFO] skip .git in your log.) But we need to ignore the case that a user sets .git to exclude_assets or an overly greedy glob like .*.

Supporting a pattern **/*.{js,ts}

**/*.{js,ts}

Currently, this action depends on toolkit/packages/glob for expanding a glob pattern and it does not support this case **/*.{js,ts} I will find an alternative.

toolkit/packages/glob

Patterns *, ?, [...], ** (globstar) are supported.

Runners does not support a YAML list

Another idea is to use a YAML list:

exclude_assets: 
  - '.github'
  - 'exclude file.txt'
  - 'exclude-dir/**.{md,txt}'

Unfortunately, the GitHub Actions runner does not support a YAML list in a with:.

@Lucide
Copy link

Lucide commented Aug 21, 2020

Good job This feature can be extremely useful for anyone who doesn't have an easy way to do out-of-source builds, I wanted to try it out but I'm encountering issues:
With publish_dir: . and exclude_assets: ".github,*.md,*.json,scss,ts" I get:

[INFO] prepare publishing assets
  [INFO] skip .git
  [INFO] copy .github
  [INFO] copy .gitignore
  [INFO] copy LICENSE
  [INFO] copy README.md
  [INFO] copy assets
  [INFO] copy build <-it's here tho. not present in the gh-pages branch
  [INFO] copy index.html
  [INFO] copy node_modules
  [INFO] copy package-lock.json
  [INFO] copy package.json
  [INFO] copy scss
  [INFO] copy ts
  [INFO] copy tsconfig.json
  [INFO] delete excluded assets
  [INFO] delete /home/runner/actions_github_pages_1598048531527/.github
  [INFO] delete /home/runner/actions_github_pages_1598048531527/README.md
  [INFO] delete /home/runner/actions_github_pages_1598048531527/package-lock.json
  [INFO] delete /home/runner/actions_github_pages_1598048531527/package.json
  [INFO] delete /home/runner/actions_github_pages_1598048531527/scss
  [INFO] delete /home/runner/actions_github_pages_1598048531527/scss/_defaults.scss
  [INFO] delete /home/runner/actions_github_pages_1598048531527/ts
  [INFO] delete /home/runner/actions_github_pages_1598048531527/ts/@types
  ##[error]Action failed with "ENOENT: no such file or directory, scandir '/home/runner/actions_github_pages_1598048531527/ts/@types'"

The error is inconsistent, it didn't occur previously, then I deleted the gh-pages branch because the action kept trying to recreate it, and now it fails regularly. I also have a build-time generated /build/ directory that gets always ignored?

@peaceiris
Copy link
Owner

Currently, I do not know why it fails to locate @types dir. Anyway, the following will work as a workaround.

- name: Build
  run: | 
    npm run build
    rm -rf ts

I also have a build-time generated /build/ directory that gets always ignored?

Your .gitignore has /build/. Git just follows this setting, the gh-pages branch is also a Git repository. See also #445.

@Lucide
Copy link

Lucide commented Aug 22, 2020

Ohh, embarrassing! must have deleted it from the list without noticing.
After fixing that, the problem above went away too

@kurtbruns
Copy link

First off, love the action.

However, I ran into trouble using exclude_assets for my use case. I'm trying to ignore files in the publish_dir/posts directory with the same file extension. I tried a variety of patterns, including the two below, but the files are still being committed to the gh-pages branch.

exclude_assets: "posts/**.jpg"
exclude_assets: "posts/**/*.jpg"

Workaround

The workaround I'm currently using is to create a .gitignore in the static directory that ends up in the publish directory. This seems to work fine, because when changes are committed to the gh-pages branch the files are ignored based on the pattern(s) defined the .gitignore like so:

posts/**/*.jpg

Anyways, I would love it if I could get exclude_assets working! Thanks

@peaceiris
Copy link
Owner

@kurtbruns Thank you for your feedback! Could you open another issue and provide more details?

Repository owner locked as resolved and limited conversation to collaborators May 23, 2021
@peaceiris peaceiris unpinned this issue Jun 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants