Skip to content

Commit

Permalink
feat(publisher-gcs): only include provided upload options (#3576)
Browse files Browse the repository at this point in the history
* Separate config properties out and only include provided upload options

* exclamation point

* run prettier

---------

Co-authored-by: Erick Zhao <erick@hotmail.ca>
Co-authored-by: George Xu <33054982+georgexu99@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 19, 2024
1 parent 04945d5 commit a29dd65
Showing 1 changed file with 7 additions and 8 deletions.
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;

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

0 comments on commit a29dd65

Please sign in to comment.