Skip to content

Commit

Permalink
fix (nit): formatted dart codes
Browse files Browse the repository at this point in the history
  • Loading branch information
hahnandrew committed Jun 25, 2024
1 parent 4f04988 commit b735fa5
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 118 deletions.
7 changes: 4 additions & 3 deletions actions/lib/src/android/shell_script.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ extension type ShellScript(String script) {
set -eo pipefail
$script
''';
core.info('Running script:\n$fullScript\n=======================================');
core.info(
'Running script:\n$fullScript\n=======================================');
await fs.withTempDir('launch_android_emulator', (tempDir) async {
final scriptPath = p.join(tempDir, 'script.sh');
fs.writeFileSync(scriptPath, fullScript);
final result = await processManager.start(
['/bin/bash', scriptPath],
['/bin/bash', scriptPath],
mode: ProcessStartMode.inheritStdio,
);
final exitCode = await result.exitCode;
if (exitCode != 0) {
throw ProcessException(
'/bin/bash',
[script],
'Script failed with exit code',
'Script failed with exit code',
exitCode,
);
}
Expand Down
14 changes: 7 additions & 7 deletions actions/lib/src/node/actions/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ import 'dart:js_interop';
external Cache get cache;

/// Tools for interacting with the GitHub Actions cache.
///
///
/// See: https://www.npmjs.com/package/@actions/cache
@JS()
@anonymous
extension type Cache._(JSObject it) {
/// Returns true if Actions cache service feature is available, otherwise false.
external bool isFeatureAvailable();

@JS('restoreCache')
external JSPromise _restoreCache(
JSArray paths,
String primaryKey,[
String primaryKey, [
JSArray? restoreKeys,
]);

/// Restores cache from keys
///
///
/// @param paths a list of file paths to restore from the cache
/// @param primaryKey an explicit key for restoring the cache
/// @param restoreKeys an optional ordered list of keys to use for restoring the cache if no cache hit occurred for key
Expand All @@ -34,7 +34,7 @@ extension type Cache._(JSObject it) {
List<String>? restoreKeys,
}) async {
final promise = _restoreCache(
paths.map((p) => p.toJS).toList().toJS,
paths.map((p) => p.toJS).toList().toJS,
primaryKey,
restoreKeys?.map((key) => key.toJS).toList().toJS,
);
Expand All @@ -49,7 +49,7 @@ extension type Cache._(JSObject it) {
);

/// Saves a list of files with the specified key
///
///
/// @param paths a list of file paths to be cached
/// @param primaryKey an explicit key for restoring the cache
/// @returns number returns cacheId if the cache was saved successfully and throws an error if save fails
Expand All @@ -58,7 +58,7 @@ extension type Cache._(JSObject it) {
required String primaryKey,
}) async {
final promise = _saveCache(
paths.map((path) => path.toJS).toList().toJS,
paths.map((path) => path.toJS).toList().toJS,
primaryKey,
);
final result = await promise.toDart;
Expand Down
7 changes: 5 additions & 2 deletions actions/lib/src/node/actions/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ extension type Core._(JSObject it) {

String getRequiredInput(String name) {
final inputValue = _getInput(name);
return inputValue.isEmpty ? (throw StateError('Input "$name" was required but no value was passed')) : inputValue;
return inputValue.isEmpty
? (throw StateError(
'Input "$name" was required but no value was passed'))
: inputValue;
}

T getTypedInput<T>(
Expand Down Expand Up @@ -50,7 +53,7 @@ extension type Core._(JSObject it) {
external void endGroup();

Future<R> withGroup<R>(
String name,
String name,
Future<R> Function() action,
) async {
startGroup(name);
Expand Down
2 changes: 1 addition & 1 deletion actions/lib/src/node/actions/exec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ extension type Exec._(JSObject it) {
try {
final exitCode = await promiseToFuture<int>(
_exec(
commandLine,
commandLine,
args.map((arg) => arg.toJS).toList().toJS,
options,
),
Expand Down
167 changes: 84 additions & 83 deletions actions/lib/src/node/actions/github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ external GitHub get github;
@anonymous
extension type GitHub._(JSObject it) {
/// The GitHub context this action is running in.
///
///
/// See: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
external GitHubContext get context;
}

/// A typed representation of the `github` context object.
///
/// See also:
///
/// See also:
/// - https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
/// - https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
@JS('github.Context')
Expand All @@ -28,102 +28,102 @@ extension type GitHubContext._(JSObject it) {
external WebhookPayload get payload;

/// The name of the event that triggered the workflow run.
///
///
/// From the `GITHUB_EVENT_NAME` environment variable.
external String get eventName;

/// The commit SHA that triggered the workflow.
///
/// The value of this commit SHA depends on the event that triggered the workflow.
/// The commit SHA that triggered the workflow.
///
/// The value of this commit SHA depends on the event that triggered the workflow.
/// For more information, see [Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows).
///
///
/// For example, `ffac537e6cbbf934b08745a378932722df287a53`.
///
///
/// From the `GITHUB_SHA` environment variable.
external String get sha;

/// The fully-formed ref of the branch or tag that triggered the workflow run.
///
/// For workflows triggered by push, this is the branch or tag ref that was pushed.
/// For workflows triggered by pull_request, this is the pull request merge branch.
/// For workflows triggered by release, this is the release tag created. For other
/// triggers, this is the branch or tag ref that triggered the workflow run.
///
/// This is only set if a branch or tag is available for the event type. The ref given
/// is fully-formed, meaning that for branches the format is `refs/heads/<branch_name>`,
/// for pull requests it is `refs/pull/<pr_number>/merge`, and for tags it is
/// `refs/tags/<tag_name>`.
///
/// The fully-formed ref of the branch or tag that triggered the workflow run.
///
/// For workflows triggered by push, this is the branch or tag ref that was pushed.
/// For workflows triggered by pull_request, this is the pull request merge branch.
/// For workflows triggered by release, this is the release tag created. For other
/// triggers, this is the branch or tag ref that triggered the workflow run.
///
/// This is only set if a branch or tag is available for the event type. The ref given
/// is fully-formed, meaning that for branches the format is `refs/heads/<branch_name>`,
/// for pull requests it is `refs/pull/<pr_number>/merge`, and for tags it is
/// `refs/tags/<tag_name>`.
///
/// For example, `refs/heads/feature-branch-1`.
///
///
/// From the `GITHUB_REF` environment variable.
external String get ref;

/// The name of the workflow. If the workflow file doesn't specify a `name`, the value of
/// The name of the workflow. If the workflow file doesn't specify a `name`, the value of
/// this property is the full path of the workflow file in the repository.
///
///
/// From the `GITHUB_WORKFLOW` environment variable.
external String get workflow;

/// The name of the action currently running, or the `id` of a step.
///
/// GitHub removes special characters, and uses the name `__run` when the current step runs
/// a script without an `id`. If you use the same action more than once in the same job,
/// the name will include a suffix with the sequence number with underscore before it.
///
/// For example, the first script you run will have the name `__run`, and the second script
/// will be named `__run_2`. Similarly, the second invocation of `actions/checkout` will be
/// The name of the action currently running, or the `id` of a step.
///
/// GitHub removes special characters, and uses the name `__run` when the current step runs
/// a script without an `id`. If you use the same action more than once in the same job,
/// the name will include a suffix with the sequence number with underscore before it.
///
/// For example, the first script you run will have the name `__run`, and the second script
/// will be named `__run_2`. Similarly, the second invocation of `actions/checkout` will be
/// `actionscheckout2`.
///
///
/// From the `GITHUB_ACTION` environment variable.
external String get action;

/// The username of the user that triggered the initial workflow run.
///
/// If the workflow run is a re-run, this value may differ from `github.triggering_actor`.
/// Any workflow re-runs will use the privileges of `github.actor`, even if the actor initiating
/// The username of the user that triggered the initial workflow run.
///
/// If the workflow run is a re-run, this value may differ from `github.triggering_actor`.
/// Any workflow re-runs will use the privileges of `github.actor`, even if the actor initiating
/// the re-run (`github.triggering_actor`) has different privileges.
///
///
/// From the `GITHUB_ACTOR` environment variable.
external String get actor;

/// The `job_id` of the current job.
///
/// **Note:** This context property is set by the Actions runner, and is only available within
///
/// **Note:** This context property is set by the Actions runner, and is only available within
/// the execution `steps` of a job. Otherwise, the value of this property will be `null`.
///
///
/// From the `GITHUB_JOB` environment variable.
external String get job;

/// A unique number for each run of a particular workflow in a repository.
///
/// This number begins at 1 for the workflow's first run, and increments with each new run. This
/// A unique number for each run of a particular workflow in a repository.
///
/// This number begins at 1 for the workflow's first run, and increments with each new run. This
/// number does not change if you re-run the workflow run.
///
///
/// From the `GITHUB_RUN_NUMBER` environment variable.
external int get runNumber;

/// A unique number for each workflow run within a repository.
///
/// A unique number for each workflow run within a repository.
///
/// This number does not change if you re-run the workflow run.
///
///
/// From the `GITHUB_RUN_ID` environment variable.
external int get runId;

/// The URL of the GitHub REST API.
///
///
/// From the `GITHUB_API_URL` environment variable.
external String get apiUrl;

/// The URL of the GitHub server.
///
/// The URL of the GitHub server.
///
/// For example: `https://github.com`.
///
///
/// From the `GITHUB_SERVER_URL` environment variable.
external String get serverUrl;

/// The URL of the GitHub GraphQL API.
///
///
/// From the `GITHUB_GRAPHQL_URL` environment variable.
external String get graphqlUrl;

Expand All @@ -133,56 +133,57 @@ extension type GitHubContext._(JSObject it) {
/// The repo from which this action was run.
external GitHubRepo get repo;

/// The name of the base ref or target branch of the pull request in a workflow run.
///
/// The name of the base ref or target branch of the pull request in a workflow run.
///
/// This is only set when the event that triggers a workflow run is either `pull_request`
/// or `pull_request_target`.
///
/// or `pull_request_target`.
///
/// For example, `main`.
///
///
/// From the `GITHUB_BASE_REF` environment variable.
String? get baseRef => process.getEnv('GITHUB_BASE_REF');

/// The head ref or source branch of the pull request in a workflow run.
///
/// This property is only set when the event that triggers a workflow run is either
/// `pull_request` or `pull_request_target`.
///
/// The head ref or source branch of the pull request in a workflow run.
///
/// This property is only set when the event that triggers a workflow run is either
/// `pull_request` or `pull_request_target`.
///
/// For example, feature-branch-1.
///
///
/// From the `GITHUB_HEAD_REF` environment variable.
String? get headRef => process.getEnv('GITHUB_HEAD_REF');

/// The short ref name of the branch or tag that triggered the workflow run.
///
/// This value matches the branch or tag name shown on GitHub.
///
/// The short ref name of the branch or tag that triggered the workflow run.
///
/// This value matches the branch or tag name shown on GitHub.
///
/// For example, `feature-branch-1`.
///
///
/// From the `GITHUB_REF_NAME` environment variable.
String get refName => process.getEnv('GITHUB_REF_NAME')!;

/// The type of ref that triggered the workflow run.
///
/// The type of ref that triggered the workflow run.
///
/// Valid values are `branch` or `tag`.
///
///
/// From the `GITHUB_REF_TYPE` environment variable.
GitHubRefType get refType => GitHubRefType.values.byName(
process.getEnv('GITHUB_REF_TYPE')!,
);

/// A unique number for each attempt of a particular workflow run in a repository.
///
/// This number begins at `1` for the workflow run's first attempt, and increments
/// with each re-run.
///
process.getEnv('GITHUB_REF_TYPE')!,
);

/// A unique number for each attempt of a particular workflow run in a repository.
///
/// This number begins at `1` for the workflow run's first attempt, and increments
/// with each re-run.
///
/// For example, `3`.
///
///
/// From the `GITHUB_RUN_ATTEMPT` environment variable.
int get runAttempt => int.parse(process.getEnv('GITHUB_RUN_ATTEMPT')!);

/// The URL to this workflow's run.
String get workflowRunUrl => '$serverUrl/${repo.owner}/${repo.repo}/actions/runs/$runId';
String get workflowRunUrl =>
'$serverUrl/${repo.owner}/${repo.repo}/actions/runs/$runId';
}

enum GitHubRefType { branch, tag }
Expand Down Expand Up @@ -211,7 +212,7 @@ extension type WebhookPayload._(JSObject it) implements JSObject {
@anonymous
extension type PullRequest._(JSObject it) implements JSObject {
external int get number;

@JS('html_url')
external String? get htmlUrl;
external String? get body;
Expand Down
7 changes: 4 additions & 3 deletions actions/lib/src/node/actions/http_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ extension type HttpClient._(JSObject it) {
@JS('getJson')
external JSPromise _getJson(String requestUrl, [JSObject headers]);

Future<Map<String, Object?>> getJson(String requestUrl, {
Future<Map<String, Object?>> getJson(
String requestUrl, {
Map<String, String> headers = const {},
} ) async {
final jsHeaders = headers.jsify() as JSObject;
}) async {
final jsHeaders = headers.jsify() as JSObject;
final response = await _getJson(requestUrl, jsHeaders).toDart;
final result = response as TypedResponse<JSObject>;
if (result.statusCode != 200) {
Expand Down
Loading

0 comments on commit b735fa5

Please sign in to comment.