From 210905b19899925035521f2ba05520fcc31aae53 Mon Sep 17 00:00:00 2001 From: Ryo Ota Date: Tue, 4 May 2021 23:23:10 +0900 Subject: [PATCH] add input fails-without-credentials --- README.md | 1 + action.yml | 3 +++ dist/index.js | 10 +++++++++- src/inputs.ts | 5 +++++ src/main.ts | 6 +++++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a57f4bba..526d7284 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ jobs: - `alias: deploy-preview-${{ github.event.number }}` replicates the [deploy preview prefix](https://docs.netlify.com/site-deploys/overview/#definitions) - `github-deployment-environment` Environment name of GitHub Deployments - `github-deployment-description` Description of the GitHub Deployment +- `fails-without-credentials` Fails if no credentials provided (default: false) ### Paths are relative to the project's root All paths (eg, `publish-dir`, `netlify-config-path`, `functions-dir`) are relative to the project's root or absolute paths. diff --git a/action.yml b/action.yml index 7b4c8e33..b3dcbfa6 100644 --- a/action.yml +++ b/action.yml @@ -44,6 +44,9 @@ inputs: github-deployment-description: description: Description of the GitHub Deployment required: false + fails-without-credentials: + description: Fails if no credentials provided + required: false outputs: deploy-url: description: Deploy URL diff --git a/dist/index.js b/dist/index.js index 0bebee45..d8d37ef2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -83,6 +83,10 @@ exports.defaultInputs = { }, githubDeploymentDescription() { return core.getInput('github-deployment-description') || undefined; + }, + failsWithoutCredentials() { + // Default: false + return core.getInput('fails-without-credentials') === 'true'; } }; @@ -194,7 +198,11 @@ function run(inputs) { const siteId = process.env.NETLIFY_SITE_ID; // NOTE: Non-collaborators PRs don't pass GitHub secrets to GitHub Actions. if (!(netlifyAuthToken && siteId)) { - process.stderr.write('Netlify credentials not provided, not deployable'); + const errorMessage = 'Netlify credentials not provided, not deployable'; + if (inputs.failsWithoutCredentials()) { + throw new Error(errorMessage); + } + process.stderr.write(errorMessage); return; } const dir = inputs.publishDir(); diff --git a/src/inputs.ts b/src/inputs.ts index f068dd52..bd796a66 100644 --- a/src/inputs.ts +++ b/src/inputs.ts @@ -16,6 +16,7 @@ export interface Inputs { alias(): string | undefined githubDeploymentEnvironment(): string | undefined githubDeploymentDescription(): string | undefined + failsWithoutCredentials(): boolean } export const defaultInputs: Inputs = { @@ -67,5 +68,9 @@ export const defaultInputs: Inputs = { }, githubDeploymentDescription(): string | undefined { return core.getInput('github-deployment-description') || undefined + }, + failsWithoutCredentials(): boolean { + // Default: false + return core.getInput('fails-without-credentials') === 'true' } } diff --git a/src/main.ts b/src/main.ts index 134b52ca..d3870940 100644 --- a/src/main.ts +++ b/src/main.ts @@ -75,7 +75,11 @@ export async function run(inputs: Inputs): Promise { const siteId = process.env.NETLIFY_SITE_ID // NOTE: Non-collaborators PRs don't pass GitHub secrets to GitHub Actions. if (!(netlifyAuthToken && siteId)) { - process.stderr.write('Netlify credentials not provided, not deployable') + const errorMessage = 'Netlify credentials not provided, not deployable' + if (inputs.failsWithoutCredentials()) { + throw new Error(errorMessage) + } + process.stderr.write(errorMessage) return } const dir = inputs.publishDir()