diff --git a/.changeset/funny-hairs-scream.md b/.changeset/funny-hairs-scream.md new file mode 100644 index 000000000..5f9e28894 --- /dev/null +++ b/.changeset/funny-hairs-scream.md @@ -0,0 +1,5 @@ +--- +"delete-deployments": patch +--- + +fix: small behavioural discrepancies diff --git a/actions/delete-deployments/README.md b/actions/delete-deployments/README.md index 34ba4ad17..71167770b 100644 --- a/actions/delete-deployments/README.md +++ b/actions/delete-deployments/README.md @@ -7,8 +7,8 @@ | Name | Description | Required | Default | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | -------- | -------------------------- | | `github-token` | GitHub token to use for authentication | Yes | `${{ github.token }}` | -| `environment` | The environment to filter deployments by | No | — | -| `ref` | The ref to filter deployments by | Yes | — | +| `environment` | The environment to filter deployments by | Yes | — | +| `ref` | The ref to filter deployments by | No | — | | `dry-run` | Whether to actually delete deployments or not | No | — | | `num-of-pages` | Number of pages (100 per page) to fetch deployments from. Set to `all` to fetch all deployments. Must be "all" or a number greater than 0. | No | `all` | | `starting-page` | Page to start fetching deployments from. Only valid if `num-of-pages` is set to a number. Must be greater than or equal to 0. | No | — | diff --git a/actions/delete-deployments/action.yml b/actions/delete-deployments/action.yml index d831f9cf2..06b233969 100644 --- a/actions/delete-deployments/action.yml +++ b/actions/delete-deployments/action.yml @@ -8,11 +8,13 @@ inputs: required: true environment: - description: The environment to filter deployments by - required: false + description: | + The environment to filter deployments by. + Required to ensure deletions are properly scoped. + required: true ref: - required: true + required: false description: The ref to filter deployments by dry-run: diff --git a/actions/delete-deployments/dist/index.js b/actions/delete-deployments/dist/index.js index bc432304d..f79dc3912 100644 --- a/actions/delete-deployments/dist/index.js +++ b/actions/delete-deployments/dist/index.js @@ -25764,7 +25764,7 @@ function getOctokit2(token) { }; return github.getOctokit(token, options, throttling, retry); } -async function listDeployments(octokit, owner, repo, environment, ref, paginateOptions) { +async function listDeployments(octokit, owner, repo, environment, paginateOptions, ref) { info( `Listing deployments for environment ${environment} and ref ${ref} in repository ${owner}/${repo}` ); @@ -25846,10 +25846,10 @@ var github2 = __toESM(require_github()); function getInputs() { info("Getting inputs for run."); const inputs = { - ref: getRunInputString("ref", true), + ref: getRunInputString("ref", false), dryRun: getRunInputBool("dryRun", false), - repository: getRunInputStringOrEnv("repository", true), - environment: getRunInputStringOrEnv("environment", true), + repository: getRunInputString("repository", true), + environment: getRunInputString("environment", true), numOfPages: getNumOfPagesInput("numOfPages", false), startingPage: getRunInputNumber("startingPage", false) }; @@ -25900,27 +25900,11 @@ var runInputsConfiguration = { }; function getRunInputString(input, required = true) { const inputKey = getInputKey(input); - const inputValue = getInput(inputKey, { - required - }); - return inputValue; -} -function getRunInputStringOrEnv(input, required = true) { - const inputKey = getInputKey(input); - const inputValue = getInput(inputKey, { - required: false - }); - if (inputValue) { - return inputValue; - } - const localParameter = runInputsConfiguration[input]?.localParameter; - if (localParameter && process.env[localParameter]) { - return process.env[localParameter]; - } - if (required) { - throw new Error(`Input ${inputKey} is required but not set.`); + const inputValue = getInput(inputKey, { required }); + if (inputValue === "" && !required) { + return void 0; } - return ""; + return inputValue; } function getRunInputBool(input, required = true) { const inputKey = getInputKey(input); @@ -26008,11 +25992,11 @@ async function run() { owner, repo, inputs.environment, - inputs.ref, { numOfPages: inputs.numOfPages, startingPage: inputs.startingPage - } + }, + inputs.ref ); const deploymentIds = deployments.map((d) => d.id); info(`Found ${deploymentIds.length} deployments to delete.`); diff --git a/actions/delete-deployments/src/github.ts b/actions/delete-deployments/src/github.ts index 57795986a..7056c1e04 100644 --- a/actions/delete-deployments/src/github.ts +++ b/actions/delete-deployments/src/github.ts @@ -63,8 +63,8 @@ export async function listDeployments( owner: string, repo: string, environment: string, - ref: string, paginateOptions: PaginateOptions, + ref?: string, ): Promise { core.info( `Listing deployments for environment ${environment} and ref ${ref} in repository ${owner}/${repo}`, diff --git a/actions/delete-deployments/src/run-inputs.ts b/actions/delete-deployments/src/run-inputs.ts index 5c33415f9..8b7703949 100644 --- a/actions/delete-deployments/src/run-inputs.ts +++ b/actions/delete-deployments/src/run-inputs.ts @@ -2,7 +2,7 @@ import * as core from "@actions/core"; import * as github from "@actions/github"; export interface RunInputs { - ref: string; + ref?: string; dryRun: boolean; repository: string; environment: string; @@ -16,10 +16,10 @@ export function getInputs(): RunInputs { core.info("Getting inputs for run."); const inputs: RunInputs = { - ref: getRunInputString("ref", true), + ref: getRunInputString("ref", false), dryRun: getRunInputBool("dryRun", false), - repository: getRunInputStringOrEnv("repository", true), - environment: getRunInputStringOrEnv("environment", true), + repository: getRunInputString("repository", true), + environment: getRunInputString("environment", true), numOfPages: getNumOfPagesInput("numOfPages", false), startingPage: getRunInputNumber("startingPage", false), }; @@ -101,41 +101,24 @@ const runInputsConfiguration: { }, }; -function getRunInputString(input: keyof RunInputs, required: boolean = true) { - const inputKey = getInputKey(input); - const inputValue = core.getInput(inputKey, { - required, - }); - - return inputValue; -} - -/** - * Usage of this function is for backwards compatibility. - */ -function getRunInputStringOrEnv( +function getRunInputString(input: keyof RunInputs): string; +function getRunInputString(input: keyof RunInputs, required: true): string; +function getRunInputString( + input: keyof RunInputs, + required: false, +): string | undefined; +function getRunInputString( input: keyof RunInputs, required: boolean = true, -) { +): string | undefined { const inputKey = getInputKey(input); - const inputValue = core.getInput(inputKey, { - required: false, - }); - - if (inputValue) { - return inputValue; - } - const localParameter = runInputsConfiguration[input]?.localParameter; + const inputValue = core.getInput(inputKey, { required }); - if (localParameter && process.env[localParameter]) { - return process.env[localParameter] as string; - } - - if (required) { - throw new Error(`Input ${inputKey} is required but not set.`); + if (inputValue === "" && !required) { + return undefined; } - return ""; + return inputValue; } function getRunInputBool(input: keyof RunInputs, required: boolean = true) { diff --git a/actions/delete-deployments/src/run.ts b/actions/delete-deployments/src/run.ts index 9c34e1c3b..48e83971e 100644 --- a/actions/delete-deployments/src/run.ts +++ b/actions/delete-deployments/src/run.ts @@ -45,11 +45,11 @@ export async function run(): Promise { owner, repo, inputs.environment, - inputs.ref, { numOfPages: inputs.numOfPages, startingPage: inputs.startingPage, }, + inputs.ref, ); const deploymentIds = deployments.map((d) => d.id);