feat(gcs): filename date/time tokens + manual bucket override for cross-project delivery#757
feat(gcs): filename date/time tokens + manual bucket override for cross-project delivery#757vklm2002 wants to merge 3 commits into
Conversation
Two backward-compatible enhancements to the Google Cloud Storage action.
1. Filename date tokens
Substitute UTC date tokens anywhere in the resolved filename before the
existing Overwrite timestamp logic: {YYYYMMDD}, {YYYY}, {MM}, {DD}
(zero-padded, UTC). Because GCS object names may contain "/", this enables
date-partitioned "folders", e.g. "daily/report_{YYYYMMDD}.csv" ->
"daily/report_20260617.csv". Filenames without tokens are unchanged and the
Overwrite="no" Date.now() uniqueness suffix still applies. No new deps.
2. Manual bucket override for cross-project / third-party delivery
The "Bucket" dropdown is populated by gcs.getBuckets(), which requires
project-level storage.buckets.list. Delivering to a partner's bucket in
another project should not require granting project-level IAM. Make
getBuckets() non-fatal (render the form with an empty dropdown instead of
erroring) and add an optional "Bucket name (manual override)" field that
takes precedence. execute() then only needs storage.objects.create on the
target bucket.
Docs: document the token syntax and manual override in the Filename form-field
descriptions and in the action README (including the UTC server-clock note).
Tests: add cases for {YYYYMMDD} resolution, tokens combined with path segments,
no-token regression, token-before-timestamp ordering, and bucket_override
precedence; update the form tests for the non-fatal listing behavior.
Extend filename token substitution beyond the date-only set:
- {YY} : 2-digit year (e.g. 26)
- {HH} : 2-digit UTC hour, 24-hour (e.g. 08)
- {mm} : 2-digit UTC minutes (e.g. 30)
- {ss} : 2-digit UTC seconds (e.g. 45)
Tokens are replaced independently wherever they appear, so any format can be
composed with arbitrary separators, e.g. "{YYYY}-{MM}-{DD}_{HH}{mm}{ss}" or
"report_{MM}-{DD}-{YY}.csv". Tokens are case-sensitive (moment.js convention):
{MM} is month while {mm} is minutes. This enables sub-daily (hourly/by-minute)
partitioning in addition to date partitioning.
Updates the Filename form-field description, README token table/examples, and
adds tests for {YY}, the {HH}/{mm}/{ss} time tokens, and the {MM}-vs-{mm}
case-sensitivity distinction.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces support for UTC date/time tokens in filenames and adds a manual bucket override option to allow writing to GCS buckets in other projects where the service account lacks project-level listing permissions. The form fields and documentation have been updated accordingly, along with comprehensive unit tests. The feedback suggests trimming the manual bucket override input to prevent potential whitespace issues that could lead to API errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Address review feedback: the manual bucket override is free-form text and users often copy-paste bucket names, which can introduce leading/trailing whitespace (spaces, newlines) and cause hard-to-debug GCS API errors (400/404). Trim bucket_override before use; a whitespace-only value trims to "" and falls back to the dropdown bucket. Tighten the test helper's bucket assertion to an exact match (calledWith) so the trimming is actually verified, and add tests for the trimmed and whitespace-only-fallback cases.
|
@googlebot I signed it! |
c267b0b to
8d8c865
Compare
Summary
Two backward-compatible enhancements to the Google Cloud Storage action.
1. Filename date/time tokens
The destination object name now supports UTC tokens that are substituted at delivery time, before the existing Overwrite uniqueness timestamp. Each token is replaced independently wherever it appears, so any format can be composed with your own separators. Because GCS object names may contain
/, this also enables date-/time-partitioned "folders" with no extra field.2026-06-17 08:30:45Z){YYYYMMDD}20260617{YYYY}2026{YY}26{MM}06{DD}17{HH}08{mm}30{ss}45Before / after
Implemented with the built-in
Date— no new npm dependencies (no moment/dayjs).2. Manual bucket override (cross-project / third-party delivery)
The Bucket dropdown is populated by
gcs.getBuckets(), which requires the project-levelstorage.buckets.listpermission. Delivering a scheduled Look to a partner's bucket in their GCP project shouldn't require granting project-level IAM to your service account — partners will (correctly) only grantroles/storage.objectCreatoron the single target bucket.This PR:
getBuckets()non-fatal — if listing fails (or returns nothing), the form renders with an empty dropdown instead of erroring;bucket_override) that takes precedence over the dropdown.execute()then only needsstorage.objects.createon the target bucket.Backward compatibility
Overwrite = "No"Date.now()uniqueness suffix is intact (tokens are substituted first).formParams.bucket(dropdown) behavior is unchanged when no override is supplied.Design note: time zone
Tokens resolve against the action hub server's UTC clock, not the query/schedule timezone. The action only receives the rendered data file, not the query's filters or timezone, so server-side UTC is used for deterministic, predictable partitioning. This is documented in the action README and called out here in case maintainers prefer a different stance.
Testing
yarn test(mocha +tsc --noEmit+ tslint) passes clean for this action: typecheck ✅, lint ✅, and all GCS tests pass. New/updated tests cover{YYYYMMDD}resolution, tokens combined with path segments,{YY}, the{HH}/{mm}/{ss}time tokens, the{MM}-vs-{mm}case-sensitivity distinction, the no-token regression, token-before-timestamp ordering,bucket_overrideprecedence, and the non-fatal bucket-listing form behavior.Docs
Token syntax and the manual bucket override are documented in the Filename form-field description and in
src/actions/google/gcs/README.md.CLA
This is a Google-owned repository and requires a signed Contributor License Agreement before it can be merged. The contributor will sign the CLA.
🤖 Generated with Claude Code