actions_toolkit_dart 0.2.0 copy "actions_toolkit_dart: ^0.2.0" to clipboard
actions_toolkit_dart: ^0.2.0 copied to clipboard

outdated

The GitHub ToolKit for developing GitHub Actions in Dart.

Build Status Coverage Status Pub Version Dart SDK Version License Pub popularity GitHub popularity

Actions Toolkit for Dart #

A third-party toolkit for GitHub Actions written in Dart. This is port of the official actions/toolkit.

core #

Core functions for setting results, logging, registering secrets and exporting variables across actions.

Usage #

Installation

$ dart pub add actions_toolkit_dart

OR

add it manually to pubspec.yaml

dependencies:
  actions_toolkit_dart: ^0.2.0

Import the package

import 'package:actions_toolkit_dart/core.dart' as core;
Inputs/Outputs

Action inputs can be read with getInput which returns a string or getBooleanInput which parses a boolean based on the YAML 1.2 specification. If required set to be false, the input should have a default value in action.yml.

Outputs can be set with setOutput which makes them available to be mapped into inputs of other actions to ensure they are decoupled.

final myInput = core.getInput(name: 'inputName', options: const core.InputOptions(required: true));
final myBooleanInput = core.getBooleanInput(name: 'booleanInputName', options: const core.InputOptions(required: true));
final myMultilineInput = core.getMultilineInput(name: 'multilineInputName', options: const core.InputOptions(required: true));

core.setOutput(name: 'outputKey', value: 'outputVal');
Exporting variables

Since each step runs in a separate process, you can use exportVariable to add it to this step and future steps environment blocks.

core.exportVariable(name: 'envVar', value: 'Val');
Setting a secret

Setting a secret registers the secret with the runner to ensure it is masked in logs.

core.setSecret(secret: 'myPassword');
PATH Manipulation

To make a tool's path available in the path for the remainder of the job (without altering the machine or containers state), use addPath. The runner will prepend the path given to the jobs PATH.

core.addPath('/path/to/my_tool');
Exit codes

You should use this library to set the failing exit code for your action. If status is not set and the script runs to completion, that will lead to a success.

try {
  // Do stuff
}
catch (err) {
  // setFailed logs the message and sets a failing exit code
  core.setFailed('Action failed with error $err');
}
Logging
import 'package:actions_toolkit_dart/core.dart' as core;

try {
  core.debug('Inside try block');

  core.warning('myInput was not set');

  if (core.isDebug()) {
    // curl -v https://github.com
  } else {
    // curl https://github.com
  }

  // Do stuff
  core.info('Output to the actions build log');

  core.notice('This is a message that will also emit an annotation');
}
catch (err) {
  core.error('Error $err, action may still succeed though');
}

This library can also wrap chunks of output in foldable groups.

import 'package:actions_toolkit_dart/core.dart' as core;

// Manually wrap output
core.startGroup('Do some function');
doSomeFunction();
core.endGroup();

// Wrap an asynchronous function call
const result = await core.group('Do something async', () async {
  const response = await doSomeHTTPRequest();
  return response;
});
Annotations

This library has 3 methods that will produce annotations.

core.error('This is a bad error. This will also fail the build.');

core.warning("Something went wrong, but it's not bad enough to fail the build.");

core.notice('Something happened that you might want to know about.');

These will surface to the UI in the Actions page and on Pull Requests.

3
likes
0
pub points
75%
popularity

Publisher

unverified uploader

The GitHub ToolKit for developing GitHub Actions in Dart.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

meta, path

More

Packages that depend on actions_toolkit_dart