Core functions for setting results, logging, registering secrets and exporting variables across actions
npx @tessl/cli install tessl/npm-actions--core@1.11.0@actions/core provides essential core functions for GitHub Actions, enabling action developers to interact with the GitHub Actions runtime environment. It offers comprehensive functionality for input/output handling, environment variable management, logging capabilities, secret masking, exit code management, OIDC token generation, filesystem path utilities, platform detection helpers, job summary generation, and annotation systems.
npm install @actions/coreimport * as core from '@actions/core';For CommonJS:
const core = require('@actions/core');You can also import specific functions:
import {
getInput,
setOutput,
setFailed,
info,
warning,
error,
exportVariable,
setSecret
} from '@actions/core';import * as core from '@actions/core';
try {
// Get action inputs
const name = core.getInput('name', { required: true });
const count = core.getInput('count') || '1';
// Log information
core.info(`Processing ${name} with count ${count}`);
// Perform action logic
const result = processData(name, parseInt(count));
// Set outputs
core.setOutput('result', result);
core.setOutput('success', 'true');
} catch (error) {
// Handle errors and set action as failed
core.setFailed(`Action failed with error: ${error.message}`);
}@actions/core is built around several key components:
Core functionality for reading action inputs with type conversion and validation, and setting outputs for downstream actions.
function getInput(name: string, options?: InputOptions): string;
function getBooleanInput(name: string, options?: InputOptions): boolean;
function getMultilineInput(name: string, options?: InputOptions): string[];
function setOutput(name: string, value: any): void;
interface InputOptions {
required?: boolean;
trimWhitespace?: boolean;
}Environment variable management, secret masking, and state preservation across action execution phases.
function exportVariable(name: string, val: any): void;
function setSecret(secret: string): void;
function addPath(inputPath: string): void;
function saveState(name: string, value: any): void;
function getState(name: string): string;Environment and State Management
Comprehensive logging system with multiple severity levels and GitHub Actions annotation support for creating contextual feedback.
function debug(message: string): void;
function info(message: string): void;
function warning(message: string | Error, properties?: AnnotationProperties): void;
function error(message: string | Error, properties?: AnnotationProperties): void;
function notice(message: string | Error, properties?: AnnotationProperties): void;
function setFailed(message: string | Error): void;
function setCommandEcho(enabled: boolean): void;
interface AnnotationProperties {
title?: string;
file?: string;
startLine?: number;
endLine?: number;
startColumn?: number;
endColumn?: number;
}Organize log output in collapsible groups for better readability in workflow logs.
function startGroup(name: string): void;
function endGroup(): void;
function group<T>(name: string, fn: () => Promise<T>): Promise<T>;Rich HTML content generation for creating detailed, formatted summaries that appear in GitHub Actions workflow runs.
interface Summary {
write(options?: SummaryWriteOptions): Promise<Summary>;
clear(): Promise<Summary>;
addRaw(text: string, addEOL?: boolean): Summary;
addCodeBlock(code: string, lang?: string): Summary;
addList(items: string[], ordered?: boolean): Summary;
addTable(rows: SummaryTableRow[]): Summary;
addHeading(text: string, level?: number | string): Summary;
addImage(src: string, alt: string, options?: SummaryImageOptions): Summary;
// ... additional formatting methods
}
const summary: Summary;Secure JWT ID token generation for authenticating with third-party cloud providers and services.
function getIDToken(aud?: string): Promise<string>;Cross-platform path manipulation utilities for handling file paths across different operating systems.
function toPosixPath(pth: string): string;
function toWin32Path(pth: string): string;
function toPlatformPath(pth: string): string;Runtime environment detection and system information gathering for platform-specific logic.
namespace platform {
const platform: string;
const arch: string;
const isWindows: boolean;
const isMacOS: boolean;
const isLinux: boolean;
function getDetails(): Promise<PlatformDetails>;
}
interface PlatformDetails {
name: string;
platform: string;
arch: string;
version: string;
isWindows: boolean;
isMacOS: boolean;
isLinux: boolean;
}enum ExitCode {
Success = 0,
Failure = 1
}
interface InputOptions {
required?: boolean;
trimWhitespace?: boolean;
}
interface AnnotationProperties {
title?: string;
file?: string;
startLine?: number;
endLine?: number;
startColumn?: number;
endColumn?: number;
}