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

inconsistent handling of symbolic links in publish_dir #103

Closed
dhimmel opened this issue Feb 17, 2020 · 10 comments
Closed

inconsistent handling of symbolic links in publish_dir #103

dhimmel opened this issue Feb 17, 2020 · 10 comments
Assignees
Labels

Comments

@dhimmel
Copy link
Contributor

dhimmel commented Feb 17, 2020

I got the following error when building dhimmel/rootstock-actions-deploy@c29e40a:

##[error]Action failed with "Error: Error: no such file or directory: /home/runner/work/rootstock-actions-deploy/rootstock-actions-deploy/webpage/images"
##[error]Node run failed with exit code 1

The corresponding action step is:

      - name: Deploy Webpage
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./webpage
          publish_branch: gh-pages

I believe this error occurs because webpage/images is a symlink to another directory. The contents of the webpage directory, set as publish_dir, are something like:

image

There are several types of possible symlinks:

  1. symlink to directory within publish_dir
  2. symlink to a file within publish_dir
  3. symlink to a directory or file outside of publish_dir

Currently, I'm interested in a solution that solves 1 & 2.

The python ghp-import utility has a --follow-links argument (see c-w/ghp-import#37). When specified, it copies (dereferences) the contents of a symlink rather than preserving it. However, I think the ideal behavior is to preserve symlinks in categories 1 & 2 above (see c-w/ghp-import#70), since GitHub Pages can navigate symlinks.

@dhimmel dhimmel added the bug Something isn't working label Feb 17, 2020
dhimmel added a commit to dhimmel/rootstock-actions-deploy that referenced this issue Feb 17, 2020
@dhimmel
Copy link
Contributor Author

dhimmel commented Feb 17, 2020

Before looking into this, let me confirm that it's not a bug on my end where the symlink target does not exist.

dhimmel added a commit to dhimmel/rootstock-actions-deploy that referenced this issue Feb 17, 2020
@dhimmel
Copy link
Contributor Author

dhimmel commented Feb 17, 2020

Update: the issue was on my end. Previously, I hadn't actually created the target files where the symlinks pointed. I fixed this in dhimmel/rootstock-actions-deploy@78350c1 and the build passed and properly deployed to the gh-pages branch.

It looks like symlinks were handled in the following way. Symlinks to files (possibility 2 above) were preserved as symlinks. Symlinks to directories (possibility 1 above) were dereferenced and their contents copied. Was this discrepancy in behavior intentional?

So @peaceiris feel free to close or rename this issue. While my original issue was my fault, there are some possible enhancements:

  1. improved error message indicating that symlink target does not exist. Although frankly the error message is actually pretty good, so perhaps nothing needs to be done here.
  2. consistent treatment of symlinks to files and directories
  3. consideration of possibility 3 above, although this does not matter for my application.

@dhimmel dhimmel changed the title action fails for symbolic links inconsistent handling of symbolic links in publish_dir Feb 17, 2020
@peaceiris
Copy link
Owner

peaceiris commented Feb 18, 2020

I got it. Yes, this problem is caused by the behavior of this action.

This action copies the publish_dir to the ${HOME}/actions_github_pages/publish_dir, so symbolic links will become unresolved links.

The copy operation depends on the io.cp actions/toolkit.

To solve this issue, we can:

  1. Fix the io.cp on the upstream OR
  2. Switch to the rsync --copy-links-like operation (rsync -rptgoDv --copy-links --copy-dirlinks ./public/ ${HOME}/actions_github_pages/publish_dir/)

@dhimmel
Copy link
Contributor Author

dhimmel commented Feb 18, 2020

Yes, this problem is caused by the behavior of this action.

@peaceiris I am not sure we're on the same page. Note that the initial problem I commented on was my fault... the target of the symlink did not exist because I did not create it.

This action copies the publish_dir to the ${HOME}/actions_github_pages/publish_dir, so symbolic links will become unresolved links.

If the symbolic link points to a target also in publish_dir, the symbolic link can be preserved without becoming unresolvable. Currently, symbolic links to files are preserved while symbolic links to directories are dereferenced.

For symbolic links that point to a target outside of publish_dir, then dereferencing (copying) would be required to get them to resolve once deployed to a branch.

I think the ideal behavior is to preserve symlinks whose targets are within publish_dir, while dereferencing symlinks whose targets are outside of publish_dir. However, I'm not sure how challenging that is to implement. Perhaps there could also be an option. Dereferencing all symlinks is also a solution (as in rsync --copy-links or cp --recursive --dereference).

@peaceiris peaceiris added the enhancement New feature or request label Feb 28, 2020
@peaceiris
Copy link
Owner

@dhimmel
I opened #144 and released 3.6.0-0. Could you test it?

@peaceiris peaceiris linked a pull request Mar 6, 2020 that will close this issue
@peaceiris peaceiris added proposal and removed bug Something isn't working labels Mar 20, 2020
@dhimmel
Copy link
Contributor Author

dhimmel commented Mar 22, 2020

I think the ideal behavior is to preserve symlinks whose targets are within publish_dir, while dereferencing symlinks whose targets are outside of publish_dir.

Looks like rsync has an option for this:

--copy-unsafe-links
This tells rsync to copy the referent of symbolic links that point outside the copied tree. Absolute symlinks are also treated like ordinary files, and so are any symlinks in the source path itself when --relative is used. This option has no additional effect if --copy-links was also specified.

So if you combine --links --copy-unsafe-links:

Turn all unsafe symlinks into files and duplicate all safe symlinks.

@github-actions

This comment has been minimized.

@peaceiris
Copy link
Owner

Could someone test the branch fix-copy-assets as follows?

- name: Deploy
  uses: peaceiris/actions-gh-pages@fix-copy-assets
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}

@peaceiris
Copy link
Owner

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

Successfully merging a pull request may close this issue.

2 participants