From a4dba970bb17463ca9a2151fc52746915a27eb32 Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Tue, 28 Feb 2023 09:26:01 +0000 Subject: [PATCH 1/3] Add mode input and URL base output. --- action.yml | 12 ++++++++++++ src/index.ts | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 50876f0..4593d68 100644 --- a/action.yml +++ b/action.yml @@ -21,3 +21,15 @@ inputs: If not supplied or supplied as an empty string then the artifacts are uploaded to S3 at root for this deployment context. required: false default: '' + mode: + description: | + Specify `"preempt"` in order use this action before content build in order to output the URL base. + required: false +outputs: + url-base: + description: | + The URL base. For example: + + https://sdk.ably.com/builds/ably/ably-flutter/pull/307/dartdoc/ + + When used in the Flutter SDK repository, with `artifactName` as `"dartdoc"`. diff --git a/src/index.ts b/src/index.ts index f48fdb6..c8ebff3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -89,6 +89,13 @@ if (artifactName.length > 0) { core.debug(`S3 Key Prefix: ${s3KeyPrefix}`); core.debug(`GitHub Environment Name: ${githubEnvironmentName}`); +const urlBase = `https://${s3BucketName}/${s3KeyPrefix}/`; +const runMode = core.getInput('mode'); +if (runMode === 'preempt') { + core.setOutput('url-base', urlBase); + process.exit(0); +} + const s3ClientConfig: S3ClientConfig = { // RegionInputConfig region: 'eu-west-2', @@ -163,7 +170,7 @@ const run = async () => { ContentType: lookup(file) || 'application/octet-stream', }); })); - await setDeploymentStatus(deploymentId, 'success', `https://${s3BucketName}/${s3KeyPrefix}/`); + await setDeploymentStatus(deploymentId, 'success', urlBase); } catch (err) { await setDeploymentStatus(deploymentId, 'failure'); throw err; From 255ccd1f7066b2b7adea32016efed5b384b694fb Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Tue, 28 Feb 2023 09:33:26 +0000 Subject: [PATCH 2/3] Document the URL base output as well as the mode input. --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 585c778..06e8b6a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This action automates the deployment of generated artifacts to our Ably SDK team ## Usage +### Usage After Artifact Generation + See [action.yml](action.yml) for explanations of each input. ```yaml @@ -31,6 +33,19 @@ In the above example, `` should be the Ably repository name (e.g. `ab If `artifactName` is not specified, or specified as an empty string, then artifacts are pushed to the root of the upload context (i.e. dropping `/${artifactName}` from the URL structures outlined above). +### Usage Before Artifact Generation + +There are times when the URL base on `sdk.ably.com` needs to be known ahead of artifact build. + +This action has an input called `mode` which can be set to `"preempt"` in order to obtain this information up front. + +If the preempt mode is requested then nothing will be uploaded to S3, however the action will emit an output called `url-base`, +containing the URL base as a string value. For example: + + https://sdk.ably.com/builds/ably/ably-flutter/pull/307/dartdoc/ + +When used in the Flutter SDK repository, with `artifactName` as `"dartdoc"`. + ## Permissions ### AWS From b7796472cc2455a321afb9e6ac7b359a5ee52776 Mon Sep 17 00:00:00 2001 From: Quintin Willison Date: Tue, 28 Feb 2023 09:42:32 +0000 Subject: [PATCH 3/3] Emit the URL base output regardless of mode. Feels safer as contract in action.yml strongly suggests the output will always be present. --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c8ebff3..f219262 100644 --- a/src/index.ts +++ b/src/index.ts @@ -90,9 +90,9 @@ core.debug(`S3 Key Prefix: ${s3KeyPrefix}`); core.debug(`GitHub Environment Name: ${githubEnvironmentName}`); const urlBase = `https://${s3BucketName}/${s3KeyPrefix}/`; +core.setOutput('url-base', urlBase); const runMode = core.getInput('mode'); if (runMode === 'preempt') { - core.setOutput('url-base', urlBase); process.exit(0); }