Repository navigation
fix: check ignore rules against workspace-relative paths - #407
Open
rootkiller6788 wants to merge 3 commits into
Open
rootkiller6788 wants to merge 3 commits into
rootkiller6788 wants to merge 3 commits into
Conversation
The .gcloudignore lives at the repository root, so the paths we test against it have to be relative to that root. We were building them with path.join(root, file), which produces an absolute path when the path input is absolute. ignore() rejects absolute paths with a RangeError, so every check blew up and nothing was ever excluded.
The catch around the ignore check kept the file in the upload list, so an error meant the file got uploaded anyway - exactly what the ignore file was supposed to prevent. Files outside $GITHUB_WORKSPACE can't be matched against a .gcloudignore that lives in the workspace, so drop them instead.
Absolute paths never matched anything, so the existing tests (which all use a relative "./testdata") didn't catch it. Also covers the out-of-workspace case, which we now skip instead of uploading.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #405.
With an absolute
path,process_gcloudignoredid nothing and every file got uploaded, including ones the.gcloudignoreexcludes.filescomes out ofexpandGlob(absoluteRoot, ...), so entries are relative to the absolute root, not to the repo.path.join(root, files[i])only produced a workspace-relative path whileroothappened to be relative. Give it an absoluterootand the joined path is absolute too, whichignore.ignores()rejects with aRangeError- and the catch block kept the file in the upload list. That was the bug: an error meant "upload it anyway" instead of "don't".So: build each path from
absoluteRootand make it relative toGITHUB_WORKSPACE, then convert to posix (Windows separators would otherwise not match). Relative and absolutepathnow take the same code path. Thetestdata/**/*.txtstyle from #376 keeps working.I also dropped the try/catch. If a file genuinely can't be matched against a
.gcloudignorethat lives in the workspace - i.e. it's outside the workspace, or on another Windows drive - we now log an error and leave it out of the upload rather than sending it.ignore()also throws on..prefixes, so that's checked explicitly.Tests: added the absolute-path case to
tests/main.test.ts(the existing ones all use./testdata, which is why this slipped through) plus one for the outside-the-workspace case. Both fail on main and pass here. Full suite is 64 pass / 0 fail locally (the 3 skips are pre-existing - unicode and integration tests).