actions_toolkit_dart

Creator: coderz1093

Last updated:

0 purchases

actions_toolkit_dart Image
actions_toolkit_dart Images

Languages

Categories

Add to Cart

Description:

actions toolkit dart

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
copied to clipboard
OR
add it manually to pubspec.yaml
dependencies:
actions_toolkit_dart: ^0.5.1
copied to clipboard
Import the package
import 'package:actions_toolkit_dart/core.dart' as core;
copied to clipboard
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');
copied to clipboard
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');
copied to clipboard
Setting a secret
Setting a secret registers the secret with the runner to ensure it is masked in logs.
core.setSecret('myPassword');
copied to clipboard
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');
copied to clipboard
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');
}
copied to clipboard
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');
}
copied to clipboard
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;
});
copied to clipboard
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.');
copied to clipboard
These will surface to the UI in the Actions page and on Pull Requests.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.