Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,50 @@ npm install --save-dev @github-actions-workflow-ts/lib @github-actions-workflow-

```typescript
// workflows/ci.wac.ts
import { Workflow, NormalJob, Step } from '@github-actions-workflow-ts/lib'
import { Workflow, NormalJob, Step, expressions as ex, dedentString as ds } from '@github-actions-workflow-ts/lib'
import { ActionsCheckoutV4, ActionsSetupNodeV4 } from '@github-actions-workflow-ts/actions'

const testJob = new NormalJob('test', {
'runs-on': 'ubuntu-latest',
}).addStep(new Step({
// Typed actions give you autocomplete on `with` inputs and typed `outputs`
const checkout = new ActionsCheckoutV4({
name: 'Checkout',
uses: 'actions/checkout@v4',
})).addStep(new Step({
})

const setupNode = new ActionsSetupNodeV4({
id: 'setup-node',
name: 'Setup Node.js',
with: {
'node-version': '20.x', // ← autocomplete for all valid inputs
cache: 'npm',
},
})

// Plain steps work too — use whichever style fits
const script = new Step({
name: 'Simple script',
run: ds(`
for i in {1..5}; do
if [ $i -eq 3 ]; then
echo "This is number three!"
else
echo "Number: $i"
fi
done
`)
})

const test = new Step({
name: 'Run tests',
run: 'npm test',
}))
env: {
CI: 'true',
NODE_AUTH_TOKEN: ex.secret('NPM_TOKEN'), // ← expression helpers -> ${{ secrets.NPM_TOKEN }}
},
})


const testJob = new NormalJob('test', {
'runs-on': 'ubuntu-latest',
}).addSteps([checkout, setupNode, script, test])

// Every Workflow instance MUST be exported
export const ci = new Workflow('ci', {
Expand All @@ -58,12 +91,13 @@ export const ci = new Workflow('ci', {
push: { branches: ['main'] },
pull_request: { branches: ['main'] },
},
}).addJob(testJob)
}).addJobs([testJob])
```

Generate the YAML:

```bash
# creates .github/workflows/ci.yml
npx gwf build
```

Expand All @@ -84,7 +118,7 @@ See more examples in the [./examples](./examples) folder and their respective ou

| Package | Description |
|---------|-------------|
| [@github-actions-workflow-ts/lib](https://www.npmjs.com/package/@github-actions-workflow-ts/lib) | Core library (zero dependencies) |
| [@github-actions-workflow-ts/lib](https://www.npmjs.com/package/@github-actions-workflow-ts/lib) | Core lib for generating workflow JSON objects |
| [@github-actions-workflow-ts/cli](https://www.npmjs.com/package/@github-actions-workflow-ts/cli) | CLI for generating YAML files |
| [@github-actions-workflow-ts/actions](https://www.npmjs.com/package/@github-actions-workflow-ts/actions) | Typed wrappers for popular actions |

Expand Down
55 changes: 47 additions & 8 deletions docs/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,71 @@ import CodeBlock from '@theme/CodeBlock'

import styles from './index.module.css'

const typescriptCode = `import { Workflow, NormalJob, Step } from '@github-actions-workflow-ts/lib'
const typescriptCode = `import {
Workflow,
NormalJob,
Step,
expressions as ex
} from '@github-actions-workflow-ts/lib'
import {
ActionsCheckoutV4,
ActionsSetupNodeV4
} from '@github-actions-workflow-ts/actions'

const testJob = new NormalJob('test', {
'runs-on': 'ubuntu-latest',
}).addStep(new Step({
// Typed actions: autocomplete on inputs, typed outputs
const checkout = new ActionsCheckoutV4({ name: 'Checkout' })

const setupNode = new ActionsSetupNodeV4({
id: 'setup-node',
name: 'Setup Node.js',
with: { 'node-version': '20.x', cache: 'npm' },
})

// Plain steps work too
const test = new Step({
name: 'Run tests',
run: 'npm test',
}))
env: { CI: 'true', NODE_AUTH_TOKEN: ex.secret('NPM_TOKEN') },
})

const testJob = new NormalJob('test', {
'runs-on': 'ubuntu-latest',
}).addSteps([checkout, setupNode, test])

export const ci = new Workflow('ci', {
name: 'CI',
on: { push: { branches: ['main'] } },
}).addJob(testJob)`
on: {
push: { branches: ['main'] },
pull_request: { branches: ['main'] },
},
}).addJobs([testJob])`

const yamlOutput = `# Generated by github-actions-workflow-ts
name: CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: npm
- name: Run tests
run: npm test`
run: npm test
env:
CI: "true"
NODE_AUTH_TOKEN: \${{ secrets.NPM_TOKEN }}`

function HomepageHeader() {
const { siteConfig } = useDocusaurusContext()
Expand Down