peaceiris / actions-gh-pages

GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.

Home Page:https://github.com/marketplace/actions/github-pages-action

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

option to commit .github files

pawsong opened this issue · comments

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

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?

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.

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

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'

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'

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

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

Using false looks prettier for me.

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

I agree with you. Using empty string is better.

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

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

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.

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.

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

@Legion2 The reason is described here

#163 (comment)

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

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

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.

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.

This issue is stale because it has been open 21 days with no activity. Remove stale label or comment or this will be closed in 7 days.

I have a similar need : I'm using publish_dir: ./ and I would like my node_modules directory to be commited on the gh-pages branch, despite this folder being in my .gitignore file.

Could an option be added that would perform a git add -f on some specific files before the commit ? -> https://github.com/peaceiris/actions-gh-pages/blob/master/src/main.ts#L55

(maybe I should open a separate issue ?)

@Lucas-C Could you open a new issue with the support label and tell me more details? I visited the covid19lejeu/covid-19-le-jeu#14 but I cannot understand it. I think your problem is not related to this issue.

Ok

I think I found a workaround, by putting the files in a public/ directory instead of using ./ directly : https://github.com/covid19lejeu/covid-19-le-jeu/pull/15/files

Hence I think I'll bother you with a bug report only if this tactic fails.

That's good!

Personally, I think projects that are using publish_dir: ./ need to re-consider its directory structure. In addition, managing node_modules under Git control is a little strange, in this case, the webpack or Parcel is useful for assets bundling.

Hi, is there any workaround to include .github ? My currently workflow only watches for changes on gh-pages branch, and you need .github inside that branch to trigger events there.

Currently, we have no workaround. I plan to work on the exclude_assets option.

Could you share your YAML workflow or the details of your use case?

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

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

Thank you for your feedback!

The beta v3.7.0-5 has been released. Could someone test this? CC: @diauweb

The exclude_assets option has .github by default.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-5
  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

Note that this option does not support regular expression currently. (We can only exclude files or directories at depth 1.)

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.

v3.7.0-5 is working for me now

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'

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}'

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:.

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?

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.

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

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

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