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

New Option destination_dir for deploying to a subdirectory

peaceiris opened this issue · comments

Is your feature request related to a problem? Please describe

Some users seem to want to deploy to a subdirectory.

Describe the solution you'd like

Add a new option destination_dir for setting a directory name.

Describe alternatives you've considered

We can use the option keep_files in this case already. But it seems to be a little difficult for users to understand the behavior.

- name: Setup assets
  run: |
    mkdir public subdir1
    mv your_contents ./subdir1/
    mv ./subdir1 ./public/

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./public
    keep_files: true

After we get the destination_dir option, the above steps will be merged into one as follows.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./public
    destination_dir: ./subdir1

Additional context

It seems tedious to implement and test it in consideration of a variety of situations.

To be investigated:

  • #507 Weird nesting of content folders

The v3.7.0-0 has been released as a beta release.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-0
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: subdir

The v3.7.0-1 has been released as a beta release.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-1
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: subdir

#410 was opened

The v3.7.0-6 has been released as a beta release.

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-6
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: subdir

I defined an environment variable to be BRANCH_NAME and wanted to use that for the destination_dir:

destination_dir: ${BRANCH_NAME}

but it doesn't do expansion.

I got the behavior I wanted with keep_files:
cp -r build/html public/${BRANCH_NAME}

- name: Publish
  uses: peaceiris/actions-gh-pages@v3.7.0-6
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: public
    keep_files: true

I highly recommend you to read the GitHub Actions official documentation before you go. You can know the basic syntax of the Actions workflow.

- name: Set branch name
  id: branch
  run: echo "::set-output name=BRANCH_NAME::${GITHUB_REF##*/}"

- name: Deploy
  uses: peaceiris/actions-gh-pages@v3.7.0-6
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: ${( steps.branch.outputs.BRANCH_NAME }}

Thanks for the work on this action and this new feature which is exactly what I need to use this to deploy versioned docs to GH Pages. Unfortunately, I cannot for the life of me get this to work properly (with 3.7.0-6 or -7). Here's what my base config looks like:

    - name: Upload to GitHub Pages
      if: ${{ github.event_name != 'pull_request' && matrix.experimental == false }}
      uses: peaceiris/actions-gh-pages@v3.7.0-7
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./docs/build/html/
        exclude_assets: '.buildinfo'
        destination_dir: ./${{ env.DOC_VERSION }}
        keep_files: false
        full_commit_message: Deploy ${{ env.DOC_VERSION }} to GitHub Pages

(env.DOC_VERSION is dev in this case) with that config I end up with:

  [INFO] copy units.html
  [INFO] delete excluded assets
  [INFO] first deployment, create new branch gh-pages
  ENOENT: no such file or directory, uv_cwd
  /usr/bin/git init
  Reinitialized existing Git repository in /home/runner/actions_github_pages_1596913915535/.git/
  /usr/bin/git checkout --orphan gh-pages
  fatal: A branch named 'gh-pages' already exists.
  ##[error]Action failed with "The process '/usr/bin/git' failed with exit code 128"

so it's not a first deployment, but I think because copying & deleting fails, that's detected as "first deployment". Some googling around on the ENOENT...uv_cwd makes me think it's failing because the current working directory was deleted. My guess is the git command used to delete all the old files is deleting the target directory, which is also the CWD at that point.

If I switch to use keep_files: true, then I don't have the deletion problem, but I have a different problem. In the source I have a directory e.g. docs/build/html/_downloads/abcdef/myfile.py. This file already exists on the gh-pages branch at dev/_downloads/abcdef/myfile.py. After the deployment pushes, I have an additional copy at dev/_downloads/_downloads/abcdef/myfile.py. This happens for any file in a subdirectory as far as I can tell. The only things copied/updated properly are in the base docs/build/html/ going to dev/.

Any help would be appreciated, because it would be really cool to be able to use this action. Thanks!

@dopplershift Thank you for the detailed report.
I think this problem has been fixed by #444. Could you try the v3.7.0-8?

That seems to have done it. Thanks for the quick turn-around!

I bumped to v3.7.0-8 to get destinstion_dir. Got error:
Action failed with "The process '/usr/bin/ssh-add' failed with exit code 1"

Its running with: deploy_key: ${{ secrets.PAGES_DEPLOY_KEY }} which has the ssh private key.

Code here: https://github.com/fruktkartan/fruktsam

Your SSH private key has the wrong format. Just follow the instruction on the README. This ticket is not good for reporting this. If you still face your problem, please submit another issue.

Describe the bug

Thanks for the great GitHub actions. The execution of lates (v3.6.4) with destination_dir appears to work fine, but reviewing the logs, I noticed the following.

##[warning]Unexpected input(s) 'destination_dir', valid inputs are ['deploy_key', 'github_token',
'personal_token', 'publish_branch', 'publish_dir', 'external_repository', 'allow_empty_commit',
'keep_files', 'force_orphan', 'user_name', 'user_email', 'commit_message', 'full_commit_message',
'tag_name', 'tag_message', 'enable_jekyll', 'disable_nojekyll', 'cname']

To Reproduce

You can see the logs here:
https://github.com/astrochun/site-hugo-academic/runs/1147794258?check_suite_focus=true

Expected behavior

No error message with destination_dir in YAML file

Screenshots

N/A

Your YAML file

repo: https://github.com/astrochun/site-hugo-academic
yaml: https://github.com/astrochun/site-hugo-academic/blob/master/.github/workflows/hugo_deploy.yml

Additional context

If I get a chance, I can create a PR request. Just thought I report it here. Let me know if you prefer a separate issue.

See the README carefully, use the tag v3.7.0-8.

See the README carefully, use the tag v3.7.0-8.

Thanks. I had not noticed the more recent versions as I often use latest.

I seem to have a weird issue related to the destination_dir. The deployment creates sub-folders such that I have post/post, tags/tags, etc.

I tried a number of options:

  1. destination_dir = ./
  2. destination_dir = .
  3. Not providing a destination_dir

The gh actions is available here.

You can see here that a post sub-directory was created under post:
https://github.com/astrochun/astrochun.github.io/tree/master/post.

The changes are reflected in the post/post set and not the post set.

If this issue is related to keep_files, I have it set in part because there's a Google file that I use for tracking. Without it, the file is deleted.

Thanks for your help, and apologies if this is a newbie question!

The expected input of the destination_dir is a subdirectory. You do not need to define the destination_dir option in your case, I think.

- destination_dir: .

If this issue is related to keep_files, I have it set in part because there's a Google file that I use for tracking. Without it, the file is deleted.

If you mean that the file is the google4b948f642fcee9fe.html, you can put it under the static folder and run Hugo. Yes, you do not need the keep_files option, too.

Directory Structure | Hugo

Stores all the static content: images, CSS, JavaScript, etc. When Hugo builds your site, all assets inside your static directory are copied over as-is. A good example of using the static folder is for verifying site ownership on Google Search Console, where you want Hugo to copy over a complete HTML file without modifying its content.

If you mean that the file is the google4b948f642fcee9fe.html, you can put it under the static folder and run Hugo. Yes, you do not need the keep_files option, too.

Directory Structure | Hugo
Stores all the static content: images, CSS, JavaScript, etc. When Hugo builds your site, all assets inside your static directory are copied over as-is. A good example of using the static folder is for verifying site ownership on Google Search Console, where you want Hugo to copy over a complete HTML file without modifying its content.

Clever solution as I only thought of static files for img and files only. Seems to work now with keep_files: false.

Works great except .nojekyll is written to the root directory instead of the directory given by destination_dir.

Works great except .nojekyll is written to the root directory instead of the directory given by destination_dir.

This is the expected behavior.

Thanks for this handy config option. One thing that became not immediately clear to me is the behavior of destination_dir and keep_files. If I set a destination dir and keep files is false, is only the destination dir erased or the whole branch? Erasing the whole branch would not be very useful for me as it contains documentation of previous versions...

@m-mohr According to the following line, when the keep_files is false, only the destination_dir will be cleaned up.

if (inps.KeepFiles) {
core.info('[INFO] Keep existing files');
} else {
core.info(`[INFO] clean up ${destDir}`);
core.info(`[INFO] chdir ${destDir}`);
process.chdir(destDir);
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
}

@peaceiris Thank you. Yeah, I assumed that, but I think it would be good to clarify that in the docs.

No. It sounds like it removes all files from the branch and adds the files to publish dir. It seems this assumes branch = dir, but that is confusing. Clear would be something like "If destination_dir is set, it removes only files in the given directory."

@m-mohr I understood your suggestion now. (Sorry, I deleted my previous comment before I get your new reply.)

Thank you for the suggestion. I am working on https://github.com/peaceiris/actions-gh-pages/pull/569/files, I am happy if you review it.

This issue has been LOCKED because of it being resolved!

The issue has been fixed and is therefore considered resolved.
If you still encounter this or it has changed, open a new issue instead of responding to solved ones.