Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(publisher-gcs): only include provided upload options #3576

Merged
merged 5 commits into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions packages/publisher/gcs/src/PublisherGCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ export default class PublisherGCS extends PublisherStatic<PublisherGCSConfig> {
async publish({ makeResults, setStatusLine }: PublisherOptions): Promise<void> {
const artifacts: GCSArtifact[] = [];

if (!this.config.bucket) {
const { storageOptions, bucket: configBucket, folder, ...uploadOptions } = this.config;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I haven't tested this locally yet but we do have a custom keyResolver property in the Config as well that would get rolled up with ...uploadOptions. Would passing in that unknown key into bucket.upload trigger an error on the GCS SDK side?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't had any trouble with it, and it doesn't look like there's any checking for extraneous keys in their library. That could change, of course.

We could also pull out keyResolver here if you think it's a concern


if (!configBucket) {
throw new Error('In order to publish to Google Cloud Storage you must set the "bucket" property in your Forge config.');
}

for (const makeResult of makeResults) {
artifacts.push(
...makeResult.artifacts.map((artifact) => ({
path: artifact,
keyPrefix: this.config.folder || this.GCSKeySafe(makeResult.packageJSON.name),
keyPrefix: folder || this.GCSKeySafe(makeResult.packageJSON.name),
platform: makeResult.platform,
arch: makeResult.arch,
}))
);
}

const storage = new Storage(this.config.storageOptions);
const storage = new Storage(storageOptions);

const bucket = storage.bucket(this.config.bucket);
const bucket = storage.bucket(configBucket);

d('creating Google Cloud Storage client with options:', this.config);

Expand All @@ -51,14 +53,11 @@ export default class PublisherGCS extends PublisherStatic<PublisherGCSConfig> {
await Promise.all(
artifacts.map(async (artifact) => {
d('uploading:', artifact.path);

await bucket.upload(artifact.path, {
metadata: this.config.metadataGenerator ? this.config.metadataGenerator(artifact) : {},
gzip: true,
destination: this.keyForArtifact(artifact),
predefinedAcl: this.config.predefinedAcl,
public: this.config.public,
private: this.config.private,
...uploadOptions,
});

uploaded += 1;
Expand Down