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
- Host: GitHub
- URL: https://github.com/jpb06/effect-action
- Owner: jpb06
- License: mit
- Created: 2024-12-10T20:13:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-16T16:22:39.000Z (over 1 year ago)
- Last Synced: 2025-02-16T17:33:01.393Z (over 1 year ago)
- Topics: effect-ts, github-actions
- Language: TypeScript
- Homepage:
- Size: 3.7 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# effect-action
[](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

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')
)
);
```