{"id":18750639,"url":"https://github.com/webiny/github-actions-wac","last_synced_at":"2025-04-12T23:32:20.799Z","repository":{"id":42497868,"uuid":"509504405","full_name":"webiny/github-actions-wac","owner":"webiny","description":"GitHub Actions - Workflows as Code (WAC)","archived":false,"fork":false,"pushed_at":"2023-11-02T10:18:05.000Z","size":1118,"stargazers_count":27,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-26T18:06:16.991Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webiny.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-01T15:29:06.000Z","updated_at":"2025-02-07T08:28:43.000Z","dependencies_parsed_at":"2024-06-21T04:17:09.639Z","dependency_job_id":"d16e6a84-8f71-4827-b8ff-8bdd2228849a","html_url":"https://github.com/webiny/github-actions-wac","commit_stats":null,"previous_names":["adrians5j/github-actions-wac"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2Fgithub-actions-wac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2Fgithub-actions-wac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2Fgithub-actions-wac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webiny%2Fgithub-actions-wac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webiny","download_url":"https://codeload.github.com/webiny/github-actions-wac/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:12:40.128Z","updated_at":"2025-04-12T23:32:15.789Z","avatar_url":"https://github.com/webiny.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `github-actions-wac`\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./docs/splash.png\" width=\"600\"\u003e\n\u003c/p\u003e\n\n[![](https://img.shields.io/npm/dw/github-actions-wac.svg)](https://www.npmjs.com/package/github-actions-wac)\n[![](https://img.shields.io/npm/v/github-actions-wac.svg)](https://www.npmjs.com/package/github-actions-wac)\n[![license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/webiny/webiny-js/blob/master/LICENSE)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nGitHub Actions - Workflows as Code (WaC).\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Overview](#overview)\n- [Examples](#examples)\n- [Reference](#reference)\n  - [Functions](#functions)\n    - [`createWorkflow`](#createWorkflow)\n  - [CLI](#cli)\n    - [`build`](#build)\n    - [`watch`](#watch)\n\n## Installation\n\n```\nnpm install --save github-actions-wac --dev\n```\n\nOr if you prefer yarn:\n\n```\nyarn add github-actions-wac --dev\n```\n\n## Overview\n\nThe `github-actions-wac` package enables you to create GitHub Actions workflows via TypeScript code.\n\nTo get started, simply create a new `.wac.ts` file in your `.github/workflows` folder and start creating your GitHub Actions workflow. For example:\n\n```ts\n// .github/workflows/index.wac.ts\n\nimport { createWorkflow, NormalJob } from \"github-actions-wac\";\n\n// Some global environment variables.\nconst defaultEnv = {\n  NODE_OPTIONS: \"--max_old_space_size=4096\"\n};\n\n// Let's assign some of the common steps into a standalone const.\nconst checkoutInstallBuildTest: NormalJob[\"steps\"] = [\n  { uses: \"actions/checkout@v2\" },\n  { name: \"Install dependencies\", run: \"yarn --immutable\" },\n  { name: \"Build\", run: \"yarn build\" }\n];\n\n// Create \"Push to main branch\" workflow.\nexport const push = createWorkflow({\n  name: \"Push to main branch\",\n  on: \"push\",\n  env: defaultEnv,\n  jobs: {\n    buildTestRelease: {\n      name: \"Build, test, release\",\n      \"runs-on\": \"ubuntu-latest\",\n      steps: [\n        ...checkoutInstallBuildTest,\n        {\n          name: \"Release\",\n          uses: \"cycjimmy/semantic-release-action@v3\",\n          with: { working_directory: \"./dist\" },\n          env: {\n            GITHUB_TOKEN: \"${{ secrets.GITHUB_TOKEN }}\",\n            NPM_TOKEN: \"${{ secrets.NPM_TOKEN }}\"\n          }\n        }\n      ]\n    }\n  }\n});\n\n// Create \"Pull requests\" workflow.\nexport const pullRequests = createWorkflow({\n  name: \"Pull requests\",\n  on: \"pull_request\",\n  env: defaultEnv,\n  jobs: {\n    buildTest: {\n      name: \"Build and test\",\n      \"runs-on\": \"ubuntu-latest\",\n      steps: [...checkoutInstallBuildTest]\n    }\n  }\n});\n```\n\nOnce you're done, in your terminal, simply run the `npx github-actions-wac build` (or `npx ghawac build`) CLI command to emit regular YAML files. For example, if we were to build the above example, we'd end up with two YAML files: `push.yml` and `pullRequests.yml`.\n\n\u003e The `npx github-actions-wac build` commands detects all exported workflows from `.wac.ts` files and emits a standalone YAML file for each one.\n\n\u003e It's up to you to decide whether you want a single `.wac.ts` file that exports all workflows, or multiple `.wac.ts` files where each exports a single workflow.\n\n## Why Create GitHub Actions via Code?\n\nCreating GitHub Actions workflows via (TypeScript) code has a couple of benefits:\n\n- if you don't like YAML in general, then this might be a more favorable approach\n- type safety - the mentioned `npx github-actions-wac build` CLI command will throw TypeScript errors if something is wrong\n- no need to copy/paste dozens of lines of YAML - simply store all of your repetitive jobs/steps as variables (or even as factory functions if additional dynamicity is required)\n- it's even possible to import external NPM modules if needed (although, personally I haven't had the need to do it yet)\n\n## Examples\n\n| Example                                                      | Description                                                                 |\n| ------------------------------------------------------------ | --------------------------------------------------------------------------- |\n| [Simple Workflow](./docs/examples/simpleWorkflow.md) | Exports a single workflow that consists of a couple of a single job and some steps. |\n| [Multiple Workflows](./docs/examples/multipleWorkflows.md) | Exports multiple workflows that consist of a single jobs and multiple steps. |\n| [Complex Example](./docs/examples/complexExample.md) | A more complex example that exports multiple branch-dependent workflows. |\n\n## Reference\n\n### Functions\n\n#### `createWorkflow`\n\n\u003cdetails\u003e\n\u003csummary\u003eType Declaration\u003c/summary\u003e\n\u003cp\u003e\n\n```ts\nexport declare const createWorkflow: (workflow: Workflow) =\u003e Workflow;\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\nCreates a new GitHub Actions workflow. Accepts a `Workflow` object.\n\n```ts\nimport { createWorkflow } from \"github-actions-wac\";\n\nexport const push = createWorkflow({\n    name: \"Push to main branch\",\n    on: \"push\",\n    env: defaultEnv,\n    jobs: { ... }\n});\n```\n\n### CLI\n\nThis package includes a small CLI that can be invoked via `npx` or `yarn`:\n\n```bash\n# Using npx:\nnpx github-actions-wac\n\n# Using yarn: \nyarn github-actions-wac\n```\n\n\u003e Instead of `github-actions-wac`, you can also use `ghawac` to invoke the CLI. For example: `npx ghawac` (`yarn ghawac`).\n\n\u003e You can also run `npx github-actions-wac --help` for in-terminal reference.\n\n#### `build`\n\nBuilds YAML from detected TypeScript (`.wac.ts`) workflow files.\n\n```bash\nnpx github-actions-wac build\n```\n\n#### `watch`\n\nWatches for changes in detected TypeScript (`.wac.ts`) workflow files and automatically generates YAML.\n\n```bash\nnpx github-actions-wac watch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fgithub-actions-wac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebiny%2Fgithub-actions-wac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebiny%2Fgithub-actions-wac/lists"}