Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simenandre/actions-parsers
Upgrade inputs from `@actions/core` by parsing and extended types!
https://github.com/simenandre/actions-parsers
actions github-actions parser typescript
Last synced: 24 days ago
JSON representation
Upgrade inputs from `@actions/core` by parsing and extended types!
- Host: GitHub
- URL: https://github.com/simenandre/actions-parsers
- Owner: simenandre
- License: apache-2.0
- Created: 2022-12-27T20:07:52.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-15T02:47:30.000Z (2 months ago)
- Last Synced: 2024-10-05T08:41:15.880Z (about 1 month ago)
- Topics: actions, github-actions, parser, typescript
- Language: TypeScript
- Homepage:
- Size: 6.68 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Github Action Parsers
This library tries to improve building actions for Github Actions using
Typescript. It might be a bit opinionated, but I feel it's important to make
sure inputs are validated and type-safe.There are some ease-of-life added features here:
- Input functions that can easily be tied with Runtypes / Zod.
- Parser for union, number and literal inputs
- Parser for YAMLAnother big thing is that this package re-exports all input-related functions in
`@actions/core` with improved types.To learn more, check out this issue:
https://github.com/actions/toolkit/issues/1290## Quickstart
```shell
yarn add actions-parsers @actions/core
```## Example
```typescript
import * as parsers from 'actions-parsers';export const config = {
/**
* Functions from `@actions/core`:
**/simpleString: parsers.getInput('simple-string'),
// ๐ Type is string or undefinedsimpleRequiredString: parsers.getInput('simple-required-string', {ย required: true }),
// ๐ Type is string or undefinedmultilineString: parsers.getMultilineInput('multiline', { required: true }).
// ๐ Type is string[]aNumericValue: parsers.getNumber('a-numeric-value'),
// ๐ Type is number or undefined.type: parsers.getUnion('type', { alternatives: ['one', 'two'] as const }),
// ๐ Type is "one" |ย "two" |ย undefinedliteral: parsers.getLiteral('literal', { requiredValue: 'hello-world' }),
// ๐ Type is "hello-world" | undefined
}
```If combined with Runtypes, Zod or any other runtime validation for static types
can get parsed type-safe YAML, for example like this:```typescript
import { getYAMLInput } from 'actions-parsers';
import * as rt from 'runtypes';const inputFieldRt = rt.Record({
firstKey: rt.String,
literal: rt.Literal('hello-world'),
anArrayOfObject: rt.Array(
rt.Record({
key: rt.String,
value: rt.String,
}),
),
});export const yamlValue = getYAMLInput('input-field', {
parser: value => inputFieldRt.check(value),
});
```This is also possible to do the same with `getParsedInput`, like this:
```typescript
import { getParsedInput } from 'actions-parsers';
import { z } from 'zod';const aDateFieldZod = z
.date()
.min(new Date('1900-01-01'), { message: 'Too old' })
.max(new Date(), { message: 'Too young!' });export const aDateField = getParsedInput('a-field', {
parser: value => aDateFieldZod.parse(value),
});
```