@factorialco/gat
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -1,2 +0,2 @@ | ||
import { Job, JobOptions } from "./job"; | ||
import { ConcurrencyGroup, Job, JobOptions } from "./job"; | ||
import type { Event, EventName, EventOptions } from "./event"; | ||
@@ -18,2 +18,3 @@ import { BaseStep, Step } from "./step"; | ||
env: EnvVar[]; | ||
concurrencyGroup?: ConcurrencyGroup; | ||
constructor(name: string); | ||
@@ -24,2 +25,3 @@ on<T extends EventName>(name: T, options?: EventOptions<T>): this; | ||
setEnv(name: string, value: string): this; | ||
setConcurrencyGroup(concurrencyGroup: ConcurrencyGroup): this; | ||
defaultRunner(): string; | ||
@@ -26,0 +28,0 @@ private assignRunner; |
@@ -34,2 +34,6 @@ "use strict"; | ||
} | ||
setConcurrencyGroup(concurrencyGroup) { | ||
this.concurrencyGroup = concurrencyGroup; | ||
return this; | ||
} | ||
defaultRunner() { | ||
@@ -47,2 +51,8 @@ return "ubuntu-22.04"; | ||
on: Object.fromEntries(this.events.map(({ name, options }) => [name, options ? options : null])), | ||
concurrency: this.concurrencyGroup | ||
? { | ||
group: this.concurrencyGroup.groupSuffix, | ||
"cancel-in-progress": this.concurrencyGroup.cancelPrevious, | ||
} | ||
: undefined, | ||
defaults: this.defaultOptions | ||
@@ -49,0 +59,0 @@ ? { |
@@ -229,2 +229,19 @@ "use strict"; | ||
}); | ||
(0, vitest_1.it)("allows concurrency groups at workflow level", () => { | ||
const workflow = new workflow_1.Workflow("Concurrency at workflow level") | ||
.on("push") | ||
.setConcurrencyGroup({ | ||
groupSuffix: "${{ github.workflow }}-${{ github.ref }}", | ||
cancelPrevious: true, | ||
}) | ||
.addJob("job1", { | ||
steps: [ | ||
{ | ||
name: "Do something", | ||
run: "exit 0", | ||
}, | ||
], | ||
}); | ||
(0, vitest_1.expect)(workflow.compile()).toMatchSnapshot(); | ||
}); | ||
}); |
{ | ||
"name": "@factorialco/gat", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "TODO", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -1,3 +0,92 @@ | ||
# GitHub Actions Template Generator (aka GAT) | ||
# gat ![Build](https://github.com/factorialco/gat/actions/workflows/build.yml/badge.svg?branch=main) [![npm version](https://badge.fury.io/js/@factorialco%2Fgat.svg)](https://badge.fury.io/js/@factorialco%2Fgat) | ||
The `gat` project is a tool to **write your GitHub Actions workflows using TypeScript**. | ||
Maintaining YAML files is hard and if your project is big enough you will find yourself duplicating a lot of code between your workflows. With `gat` you can create reusable jobs and steps just using TypeScript objects and importing them in your workflow templates. | ||
_Why `gat`?_ The name is an acronym of "GitHub Actions Template Generator" without the last part because `gat` means "cat" in Catalan. | ||
## Installation | ||
Install the main package and its dependencies using the following command: | ||
```bash | ||
npm i -D @factorialco/gat typescript ts-node commander | ||
``` | ||
## Usage | ||
### Writing a template | ||
The `gat` CLI assumes that your templates are inside `.github/templates`. Let's create our first template: | ||
```ts | ||
// .github/templates/my-first-workflow.ts | ||
import { Workflow } from "@factorialco/gat"; | ||
new Workflow("My first workflow") | ||
.on("push") | ||
.addJob("test", { | ||
steps: [ | ||
{ | ||
uses: "actions/checkout@v3", | ||
}, | ||
{ | ||
uses: "actions/setup-node@v3", | ||
}, | ||
{ | ||
run: "npm test", | ||
}, | ||
], | ||
}) | ||
.compile(); | ||
``` | ||
Notice that you need to call the `compile()` method at the end. | ||
### Compiling your templates | ||
You can build your templates running this command in your root folder: | ||
```bash | ||
npx gat build | ||
``` | ||
Alternatively you can also compile a single template: | ||
```bash | ||
npx gat build .github/templates/some-workflow.ts | ||
``` | ||
Following the previous example, you should see now a file `.github/workflows/my-first-workflow.yml` like this: | ||
```yaml | ||
# Workflow automatically generated by gat | ||
# DO NOT CHANGE THIS FILE MANUALLY | ||
name: My first workflow | ||
on: | ||
push: null | ||
jobs: | ||
test: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- run: npm test | ||
``` | ||
Notice that the job includes a few assumptions like the `runs-on` and `timeout-minutes` fields. You can change those when adding a new job. | ||
### Create your own workflow class | ||
TODO | ||
## Contributing | ||
TODO | ||
## License | ||
TODO |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23010
539
93