Avoid upload-pages-artifact action in GitHub Pages workflow#3502
Avoid upload-pages-artifact action in GitHub Pages workflow#3502justinmayer merged 2 commits intomainfrom
upload-pages-artifact action in GitHub Pages workflow#3502Conversation
In upload-pages-artifact@v4 the maintainers have made the curious decision to omit hidden files (files whose names begin with ".") from the site that gets deployed to GitHub Pages and to provide no way to include a hidden file (at least "for now"), even though static sites may of course want to include files whose names begin with "." actions/upload-pages-artifact#102 Work around this in by creating the "artifact" (tar file) ourselves and uploading it using the upload-artifact action, as suggested in the upload-pages-artifact PR linked above.
070a64c to
07d964f
Compare
| - name: Archive artifact | ||
| shell: sh | ||
| run: | | ||
| echo "::group::Archive artifact" | ||
| tar \ | ||
| --dereference \ | ||
| --hard-dereference \ | ||
| --directory "$OUTPUT_PATH" \ | ||
| -cvf "$RUNNER_TEMP/artifact.tar" \ | ||
| --exclude=.git \ | ||
| --exclude=.github \ | ||
| . | ||
| echo "::endgroup::" | ||
| env: | ||
| OUTPUT_PATH: ${{ inputs.output-path }} |
There was a problem hiding this comment.
This is exactly the same as the "Archive artifact" step from upload-pages-artifact@v3.0.1 other than INPUT_PATH being renamed to OUTPUT_PATH to match the name used elsewhere in our file.
In v4.0.0 upload-pages-artifact just added --exclude=".[^/]*" to the tar command to exclude hidden files.
| name: github-pages | ||
| path: ${{ runner.temp }}/artifact.tar | ||
| retention-days: 1 | ||
| if-no-files-found: error |
There was a problem hiding this comment.
These options are the same as how upload-pages-artifact calls upload-artifact.
There was a problem hiding this comment.
Pull Request Overview
This PR works around a limitation in upload-pages-artifact@v4 that excludes hidden files from GitHub Pages deployments by replacing the action with a custom tar command and direct artifact upload.
- Removes dependency on upload-pages-artifact@v3 in favor of manual tar creation
- Adds custom archive step that preserves hidden files while excluding .git and .github directories
- Updates upload step to use upload-artifact@v4 with specific GitHub Pages configuration
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| with: | ||
| path: ${{ inputs.output-path }} | ||
| name: github-pages | ||
| path: ${{ runner.temp }}/artifact.tar |
There was a problem hiding this comment.
The path reference uses ${{ runner.temp }} but the tar command creates the file at $RUNNER_TEMP/artifact.tar. GitHub Actions expressions should be consistent - either use ${{ runner.temp }} in both places or $RUNNER_TEMP in both places.
There was a problem hiding this comment.
I'm going to ignore Copilot's suggestion here because I'm following the style of GitHub's own actions (upload-pages-artifact and upload-artifact): for whatever reason they don't use variable references like ${{ runner.temp }} in inline shell scripts within the workflow, but instead use env: to make those variables available to the shell scripts as $RUNNER_TEMP.
It prevents hidden files from being deployed. For more details see: getpelican/pelican#3502
It prevents hidden files from being deployed. For more details see: getpelican/pelican#3502
upload-pages-artifact action in GitHub Pages workflow
justinmayer
left a comment
There was a problem hiding this comment.
Many thanks for enhancement and the detailed explanation! ✨
In upload-pages-artifact@v4 the maintainers have made the curious decision to omit hidden files (files whose names begin with ".") from the site that gets deployed to GitHub Pages and to provide no way to include a hidden file (at least "for now"), even though static sites may of course want to include files whose names begin with "." actions/upload-pages-artifact#102
Work around this in by creating the "artifact" (tar file) ourselves and uploading it using the upload-artifact action, as suggested in the upload-pages-artifact PR linked above.
Context
GitHub's upload-pages-artifact action is really just a lightweight wrapper for their upload-artifact action. The upload-pages-artifact action does two things:
tarcommand to create a tar file of your directory (in our case: Pelican's output directory)In upload-pages-artifact@v4 they've added a
--excludeoption to thetarcommand that causes any hidden files in Pelican's output dir to be omitted from the tar file and therefore ultimately omitted from the GitHub Pages site that gets deployed.In this PR I've removed upload-pages-artifact from our workflow in favour of just running our own
tarcommand without the new--excludeand then calling upload-artifact ourselves.