CI/CD & GitHub Actions (50 Qs)•Part 2: Advanced Workflows, Security & Containerization (Mid-Level)
How do you create Custom JavaScript / TypeScript Actions?
junior LevelCode ExampleState ManagementTypeScriptSecurity & Auth
In Simple Words: Custom actions allow encapsulating complex pipeline automation:
- Define metadata in
action.yml(inputs, outputs, entrypoint). - Write logic in TypeScript using
@actions/coreand@actions/github. - Compile using
@vercel/nccto bundle all dependencies into a singledist/index.jsfile.
typescript
// src/index.ts
import * as core from '@actions/core';
import * as github from '@actions/github';
async function run() {
try {
const environment = core.getInput('environment', { required: true });
core.info(`Deploying to environment: ${environment}`);
// Set output variable for downstream steps
core.setOutput('deployment_id', Date.now().toString());
} catch (error: any) {
core.setFailed(error.message);
}
}
run();