Creating Github Actions has never been easier. Here is a simple, strongly typed package to create your own .github/workflows/<action>.yaml
file.
npm install github-action-code
import {Workflow} from 'github-action-code'; // TS
// const {Workflow} = require('github-action-code'); // JS
const wfBuilder = Workflow.createWorkflow();
wfBuilder
.setName('my-service')
.addOn({
push: {
branches: ['main']
}
})
.addJob('build', {
"runs-on": 'ubuntu-latest',
steps: [{
run: 'SOME_ENV=${{ secrets.MY_SECRET }} npm run build'
}]
});
// Build the workflow
const workflow = wfBuilder.build();
Workflow.saveWorkflow(workflow, 'my-workflow', /* callback */); // Do not add the extension .yml/.yaml
jobs:
build-job:
runs-on: ubuntu-latest
steps:
- run: SOME_ENV=${{ secrets.MY_SECRET }} npm run build
on:
push:
branches:
- main