Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-hairs-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"delete-deployments": patch
---

fix: small behavioural discrepancies
4 changes: 2 additions & 2 deletions actions/delete-deployments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | — |
Expand Down
8 changes: 5 additions & 3 deletions actions/delete-deployments/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 10 additions & 26 deletions actions/delete-deployments/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
Expand Down Expand Up @@ -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)
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.`);
Expand Down
2 changes: 1 addition & 1 deletion actions/delete-deployments/src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export async function listDeployments(
owner: string,
repo: string,
environment: string,
ref: string,
paginateOptions: PaginateOptions,
ref?: string,
): Promise<ListDeploymentsResponse> {
core.info(
`Listing deployments for environment ${environment} and ref ${ref} in repository ${owner}/${repo}`,
Expand Down
49 changes: 16 additions & 33 deletions actions/delete-deployments/src/run-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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),
};
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion actions/delete-deployments/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export async function run(): Promise<void> {
owner,
repo,
inputs.environment,
inputs.ref,
{
numOfPages: inputs.numOfPages,
startingPage: inputs.startingPage,
},
inputs.ref,
);

const deploymentIds = deployments.map((d) => d.id);
Expand Down
Loading