View Source mix github_workflows.generate (GithubWorkflowsGenerator v0.1.1)
Generates GitHub Actions YAML workflow files.
$ mix github_workflows.generate [--dir .github/workflows] [--source .github/github_workflows.ex]
Workflows will be read from the source
file and stored in the dir
directory.
Options
--dir
- directory path to store the generated workflows. Defaults to.github/workflows
.--source
- path to the source file containing the map of workflows. Defaults to.github/github_workflows.ex
.
Example
Given the following .github/github_workflows.ex
file:
defmodule GithubWorkflows do
def get do
%{
"main.yml" => main_workflow(),
"pr.yml" => pr_workflow()
}
end
defp main_workflow do
[
[
name: "Main",
on: [
push: [
branches: ["main"]
]
],
jobs: [
test: test_job(),
deploy: [
name: "Deploy",
needs: :test,
steps: [
checkout_step(),
[
name: "Deploy",
run: "make deploy"
]
]
]
]
]
]
end
defp pr_workflow do
[
[
name: "PR",
on: [
pull_request: [
branches: ["main"]
]
],
jobs: [
test: test_job()
]
]
]
end
defp test_job do
[
name: "Test",
steps: [
checkout_step(),
[
name: "Run tests",
run: "make test"
]
]
]
end
defp checkout_step do
[
name: "Checkout",
uses: "actions/checkout@v4"
]
end
end
running the mix github_workflows.generate
task will output the following files:
.github/workflows/main.yml
:
name: Main
on:
push:
branches:
- main
jobs:
test:
name: Test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run tests
run: make test
deploy:
name: Deploy
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy
run: make deploy
.github/workflows/pr.yml
:
name: PR
on:
pull_request:
branches:
- main
jobs:
test:
name: Test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run tests
run: make test
More complex workflows can be found here: https://github.com/optimumBA/github_workflows_generator/blob/main/.github/github_workflows.ex