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
92 changes: 92 additions & 0 deletions .github/scripts/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import {
pullRequestHasLabels,
getCurrentPullRequestNumber,
getRepoInfo,
sanitizeInput,
escapeMarkdown,
formatDate,
checkBranchExists,
} from "github-typescript-utils";

type Ctx = {
core: typeof import("@actions/core");
github: ReturnType<typeof import("@actions/github").getOctokit>;
context: typeof import("@actions/github").context;
args: {
testMessage: string;
testLabels: string[];
testBranch: string;
};
};

/**
* E2E test script that exercises various utility functions
* to verify they can be imported and bundled correctly
*/
export default async function run({ core, github, context, args }: Ctx) {
core.info("πŸš€ Starting E2E test of github-typescript-utils");

try {
const ctx = { core, github, context };

// Test 1: Input sanitization
const sanitizedMessage = sanitizeInput(args.testMessage);
core.info(
`βœ… Input sanitization: "${args.testMessage}" β†’ "${sanitizedMessage}"`
);

// Test 2: Text formatting utilities
const escapedText = escapeMarkdown("**Bold** _italic_ `code`");
const formattedDate = formatDate(new Date());
core.info(
`βœ… Text formatting: escaped="${escapedText}", date="${formattedDate}"`
);

// Test 3: Context utilities
const repoInfo = getRepoInfo(ctx);
core.info(`βœ… Repo info: ${repoInfo.owner}/${repoInfo.repo}`);

// Test 4: PR context (if available)
const prNumber = getCurrentPullRequestNumber(ctx);
if (prNumber) {
core.info(`βœ… PR context: Found PR #${prNumber}`);

// Test PR utilities
const hasLabels = await pullRequestHasLabels({
ctx,
repo: repoInfo,
pullNumber: prNumber,
labels: args.testLabels,
});
core.info(
`βœ… PR label check: has labels [${args.testLabels.join(
", "
)}] = ${hasLabels}`
);
} else {
core.info("ℹ️ No PR context available, skipping PR-specific tests");
}

// Test 5: Branch utilities
const branchExists = await checkBranchExists({
ctx,
repo: repoInfo,
branchName: args.testBranch,
});
core.info(`βœ… Branch check: "${args.testBranch}" exists = ${branchExists}`);

core.info("πŸŽ‰ E2E test completed successfully!");

return {
success: true,
testsRun: 7,
repoInfo,
prNumber,
branchExists,
};
} catch (error) {
core.error(`❌ E2E test failed: ${error}`);
core.setFailed(`E2E test failed: ${error}`);
return { success: false, error: String(error) };
}
}
8 changes: 8 additions & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@tkstang/ci-scripts",
"private": true,
"type": "module",
"dependencies": {
"github-typescript-utils": "file:../../"
}
}
223 changes: 223 additions & 0 deletions .github/scripts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .github/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"baseUrl": ".",
"paths": {
"github-typescript-utils": ["../../dist/index.d.ts"]
}
},
"include": ["*.ts"],
"exclude": ["node_modules"]
}
Loading