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

New Option destination_dir for deploying to a subdirectory #324

Closed
1 task done
peaceiris opened this issue May 26, 2020 · 25 comments
Closed
1 task done

New Option destination_dir for deploying to a subdirectory #324

peaceiris opened this issue May 26, 2020 · 25 comments
Assignees
Labels

Comments

@peaceiris
Copy link
Owner

peaceiris commented May 26, 2020

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:

@peaceiris

This comment has been minimized.

@peaceiris peaceiris changed the title New Option destination_directory for deploying to a subdirectory New Option destination_dir for deploying to a subdirectory Jul 21, 2020
@peaceiris

This comment has been minimized.

@peaceiris
Copy link
Owner Author

#410 was opened

peaceiris added a commit that referenced this issue Jul 23, 2020
peaceiris pushed a commit that referenced this issue Jul 23, 2020
@peaceiris
Copy link
Owner Author

peaceiris commented Jul 25, 2020

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

- name: Deploy
  uses: peaceiris/[email protected]
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: subdir

@peaceiris peaceiris pinned this issue Jul 25, 2020
@rscohn2

This comment has been minimized.

@peaceiris
Copy link
Owner Author

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/[email protected]
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    destination_dir: ${( steps.branch.outputs.BRANCH_NAME }}

@dopplershift
Copy link

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/[email protected]
      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!

@peaceiris
Copy link
Owner Author

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

@dopplershift
Copy link

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

@quite

This comment has been minimized.

@peaceiris

This comment has been minimized.

@astrochun

This comment has been minimized.

@peaceiris

This comment has been minimized.

@astrochun

This comment has been minimized.

@astrochun
Copy link

astrochun commented Sep 27, 2020

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!

@peaceiris
Copy link
Owner Author

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.

@astrochun
Copy link

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.

@cjmayo
Copy link

cjmayo commented Oct 13, 2020

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

@peaceiris
Copy link
Owner Author

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

This is the expected behavior.

@peaceiris peaceiris mentioned this issue Oct 15, 2020
1 task
peaceiris added a commit that referenced this issue Oct 15, 2020
Close #520

Related to:

- pr: #512 
- #507 #509 
- #390
- #324
- #103
peaceiris pushed a commit that referenced this issue Oct 15, 2020
Close #520

Related to:

- pr: #512
- #507 #509
- #390
- #324
- #103
@m-mohr
Copy link
Contributor

m-mohr commented Feb 15, 2021

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

@peaceiris
Copy link
Owner Author

@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 peaceiris unpinned this issue Feb 16, 2021
@m-mohr
Copy link
Contributor

m-mohr commented Feb 16, 2021

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

@m-mohr
Copy link
Contributor

m-mohr commented Feb 16, 2021

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

@peaceiris
Copy link
Owner Author

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

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 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

7 participants