rossjrw / pr-preview-action

GitHub Action that deploys a pull request preview to GitHub Pages, similar to Vercel and Netlify, and cleans up after itself.
https://github.com/marketplace/actions/deploy-pr-preview
MIT License
255 stars 39 forks source link

Check for org pages repo matches unexpectedly #39

Closed electrofelix closed 1 year ago

electrofelix commented 1 year ago

I'm using this action in https://github.com/vagrant-libvirt/vagrant-libvirt, unfortunately because the repo name matches the org name, the current behaviour of identifying repos for updating org gh-pages repos things that previews for the main application which should show up under https://vagrant-libvirt.github.io/vagrant-libvirt/ as though they should appear under https://vagrant-libvirt.github.io/

This can be seen with https://github.com/vagrant-libvirt/vagrant-libvirt/pull/1733#issuecomment-1518684270 which indicates the preview should appear as https://vagrant-libvirt.github.io/pr-preview/pr-1733/ when the correct URL is https://vagrant-libvirt.github.io/vagant-libvirt/pr-preview/pr-1733/

It appears this was caused by an improvement to try and generate the correct preview URLs for PRs in repos updating org pages https://github.com/rossjrw/pr-preview-action/blob/2a652922e9b9c53e7e5ea62fa38da744de09043c/action.yml#L68-L74

It appears that the code behaviour is expecting to match the following scenario:

GITHUB_REPOSITORY="vagrant-libvirt/vagrant-libvirt.github.io"

org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2 | cut -d "." -f 1)
[ "$org" == "$thirdleveldomain" ] && echo "${org} == ${thirdleveldomain}"

Unfortunately it will also match on the following:

GITHUB_REPOSITORY="vagrant-libvirt/vagrant-libvirt"

org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2 | cut -d "." -f 1)
[ "$org" == "$thirdleveldomain" ] && echo "${org} == ${thirdleveldomain}"

A simple fix should be to skip removal of the dot domain components:

org=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 1)
thirdleveldomain=$(echo "$GITHUB_REPOSITORY" | cut -d "/" -f 2)
[ "${org}.github.io" == "$thirdleveldomain" ] && echo "${org} == ${thirdleveldomain}"

will correctly skip outputting when GITHUB_REPOSITORY="vagrant-libvirt/vagrant-libvirt" while still detecting GITHUB_REPOSITORY="vagrant-libvirt/vagrant-libvirt.github.io"

rossjrw commented 1 year ago

Makes perfect sense to me and looks like a far better implementation of the .github.io detection. Will merge right away, thanks for the contribution!

rossjrw commented 1 year ago

Released in v1.3.2 https://github.com/rossjrw/pr-preview-action/releases/tag/v1.3.2