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

add input fails-without-credentials #532

Merged
merged 1 commit into from May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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