Files
languageservices/workflow-parser
2023-02-28 15:18:40 -08:00
..
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-28 18:22:11 +00:00
2023-02-28 15:18:40 -08:00
2023-02-22 15:52:40 -08:00
2023-02-22 15:52:40 -08:00

actions/workflow-parser

@actions/workflow-parser is a library to parse GitHub Actions workflows.

Installation

The package contains TypeScript types and compiled ECMAScript modules.

npm install @actions/workflow-parser

Usage

The parser is driven by a custom schema defined in worflows-v1.0.json.

Simple example

parseWorkflow parses the workflow YAML into an intermediate representation and validates that it conforms to the schema. Any parsing errors are returned in the errors property of the result context.

var trace: TraceWriter;

const result = parseWorkflow(
  {
    name: "test.yaml",
    content: `on: push
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - run: echo 'hello'`
  },
  trace
);

convertWorkflowTemplate then takes that intermediate representation and converts it to a WorkflowTemplate object, which is a more convenient representation for working with workflows.

const workflowTemplate = await convertWorkflowTemplate(result.context, result.value);

// workflowTemplate.jobs[0].id === "build"
// workflowTemplate.jobs[0].steps[0].run === "echo 'hello'"

Build

npm run build

or to watch for changes

npm run watch

Test

npm test

or to watch for changes and run tests:

npm run test-watch

Lint

npm run format-check

License

This project is licensed under the terms of the MIT open source license. Please refer to MIT for the full terms.