An open API service indexing awesome lists of open source software.

https://github.com/jpb06/effect-action

A template to create a github action relying on effect, with pretty errors reporting
https://github.com/jpb06/effect-action

effect-ts github-actions

Last synced: 2 months ago
JSON representation

A template to create a github action relying on effect, with pretty errors reporting

Awesome Lists containing this project

README

          

# effect-action

[![Open in Visual Studio Code](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc)](https://github.dev/jpb06/effect-action)

A template to create a github action using [Effect](https://effect.website/) and [effect-errors](https://github.com/jpb06/effect-errors).

      

## ⚡ Output

![example](./docs/workflow-run-example.png)

You can take a look at the three sample workflows:

- [Success](https://github.com/jpb06/effect-action/actions/workflows/success.yml).
- [Main task failure](https://github.com/jpb06/effect-action/actions/workflows/main-task-failure.yml).
- [Sub task failure](https://github.com/jpb06/effect-action/actions/workflows/sub-task-failure.yml).

## ⚡ Usage

To pretty print the error and display a stack trace that is actually useful, we must collect the `cause` using `Effect.catchAll` and use `captureErrors` from [effect-errors](https://github.com/jpb06/effect-errors).

This function will use source maps if present to resolve sources location. We can then use `prettyPrintFromCapturedErrors` function to display the error details.

```ts
import { setFailed } from '@actions/core';
import { FetchHttpClient } from '@effect/platform';
import { NodeFileSystem } from '@effect/platform-node';
import { Effect, Layer, pipe } from 'effect';
import { captureErrors, prettyPrintFromCapturedErrors } from 'effect-errors';
import type { Cause } from 'effect/Cause';

const collectErrorDetails = (cause: Cause) =>
pipe(
Effect.gen(function* () {
const captured = yield* captureErrors(cause, {
reverseSpans: true,
stripCwd: true,
});
const message = prettyPrintFromCapturedErrors(captured, {
hideStackTrace: true,
stripCwd: true,
reverseSpans: true,
});

console.error(message);

setFailed('❌ Github action workflow failure');
}),
Effect.scoped,
Effect.provide(Layer.mergeAll(FetchHttpClient.layer, NodeFileSystem.layer)),
Effect.withSpan('collect-error-details')
);

export const actionWorkflow = Effect.runPromise(
pipe(
starter,
Effect.sandbox,
Effect.catchAll(collectErrorDetails),
Effect.provide(LoggerConsoleLive),
Effect.withSpan('action-workflow')
)
);
```