Skip to content

fix: check ignore rules against workspace-relative paths - #407

Open
rootkiller6788 wants to merge 3 commits into
google-github-actions:mainfrom
rootkiller6788:fix-gcloudignore-absolute-path
Open

rootkiller6788 wants to merge 3 commits into
google-github-actions:mainfrom
rootkiller6788:fix-gcloudignore-absolute-path

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #405.

With an absolute path, process_gcloudignore did nothing and every file got uploaded, including ones the .gcloudignore excludes.

files comes out of expandGlob(absoluteRoot, ...), so entries are relative to the absolute root, not to the repo. path.join(root, files[i]) only produced a workspace-relative path while root happened to be relative. Give it an absolute root and the joined path is absolute too, which ignore.ignores() rejects with a RangeError - 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 absoluteRoot and make it relative to GITHUB_WORKSPACE, then convert to posix (Windows separators would otherwise not match). Relative and absolute path now take the same code path. The testdata/**/*.txt style from #376 keeps working.

I also dropped the try/catch. If a file genuinely can't be matched against a .gcloudignore that 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).

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.
@rootkiller6788
rootkiller6788 marked this pull request as ready for review December 3, 2026 05:01
@rootkiller6788
rootkiller6788 requested a review from a team as a code owner December 3, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Absolute path silently bypasses .gcloudignore exclusions

1 participant