Skip to content

Commit

Permalink
add input fails-without-credentials (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed May 4, 2021
1 parent 8feae1d commit 9b51bd3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion dist/index.js
Expand Up @@ -83,6 +83,10 @@ exports.defaultInputs = {
},
githubDeploymentDescription() {
return core.getInput('github-deployment-description') || undefined;
},
failsWithoutCredentials() {
// Default: false
return core.getInput('fails-without-credentials') === 'true';
}
};

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/inputs.ts
Expand Up @@ -16,6 +16,7 @@ export interface Inputs {
alias(): string | undefined
githubDeploymentEnvironment(): string | undefined
githubDeploymentDescription(): string | undefined
failsWithoutCredentials(): boolean
}

export const defaultInputs: Inputs = {
Expand Down Expand Up @@ -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'
}
}
6 changes: 5 additions & 1 deletion src/main.ts
Expand Up @@ -75,7 +75,11 @@ export async function run(inputs: Inputs): Promise<void> {
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()
Expand Down

1 comment on commit 9b51bd3

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.