Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested templates (calling a yaml file from another yaml file) in GitHub Actions

Does GitHub action support nested templates? For example, here is an example of Azure Pipeline yaml where it calls another yaml file:

- job: BuildFunctions
    
  steps:
  - ${{ each func in parameters.functionApps }}:
    - template: yaml/build-functionapps.yml
      parameters:

Is it possible to call a yaml file from another yaml file in GitHub actions?

like image 506
user989988 Avatar asked Sep 24 '20 22:09

user989988


People also ask

Can YAML files include other YAML files?

No, YAML does not include any kind of "import" or "include" statement.

How do I call one workflow from another workflow in GitHub Actions?

You call a reusable workflow by using the uses keyword. Unlike when you are using actions within a workflow, you call reusable workflows directly within a job, and not from within job steps.

Can you have multiple GitHub workflows?

github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks.


1 Answers

You can use composite run steps actions. These are actions that are solely defined in YAML (documentation).

You can now specify containers, other composite actions (up to a depth of 9) and node actions in additional to the previously available run steps

node actions likely refers to leaf actions, i.e. actions that don't call any other actions.

Source: https://github.com/actions/runner/issues/646#issuecomment-901336347

Workflow

[...]

jobs:
  job:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: ./.github/workflows/composite-action

[...]

Composite run steps action
.github/workflows/composite-action/action.yml (same repository as the workflow)

name: "My composite action"
description: "Checks out the repository and does something"
runs:
  using: "composite"
  steps:
  - uses: actions/checkout@v2
  - uses: actions/setup-node@v2
    with:
      node-version: 12
  - run: npm test
    shell: bash
  - run: |
      echo "Executing action"
    shell: bash

Old limitations:

What does composite run steps currently support?

For each run step in a composite action, we support:

  • name
  • id
  • run
  • env
  • shell
  • working-directory

In addition, we support mapping input and outputs throughout the action.

See docs for more info.

What does Composite Run Steps Not Support

We don't support setting conditionals, continue-on-error, timeout-minutes, "uses" [remark: i.e. using other actions], and secrets on individual steps within a composite action right now.

(Note: we do support these attributes being set in workflows for a step that uses a composite run steps action)

Source: https://github.com/actions/runner/issues/646

like image 115
riQQ Avatar answered Nov 15 '22 09:11

riQQ