In GitHub Actions, it is common to combine multiple action.yml files, which typically means you need to integrate multiple independently defined actions into a single workflow.
First, we need to understand that action.yml files are actually configuration files used to define individual actions. If you want to use multiple actions in a repository, you typically reference them in a workflow file, such as .github/workflows/main.yml.
Steps to Follow:
-
Define Actions: Each action should have its own directory and
action.ymlfile. For example:action-a/action.ymlaction-b/action.yml
-
Create a Workflow: Create a workflow file in the
.github/workflowsdirectory, such asmain.yml. -
Reference Actions in the Workflow: In the workflow file
main.yml, you can reference actions in the repository using theuseskeyword. For example:
yamlname: Example Workflow on: [push] jobs: job1: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Run Action A uses: ./action-a - name: Run Action B uses: ./action-b
Here, uses: ./action-a and uses: ./action-b point to the two different actions defined in the repository.
Example:
Suppose you have two actions: one for setting up the environment (e.g., configuring Node.js) and another for running tests. You can structure your repository as follows:
.github/actions/setup-node/action.yml: This file defines the action for setting up the Node.js environment..github/actions/run-tests/action.yml: This file defines the action for running tests.
Then, your workflow file .github/workflows/main.yml might look like this:
yamlname: CI Workflow on: [push, pull_request] jobs: build-and-test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup Node.js uses: ./.github/actions/setup-node - name: Run Tests uses: ./.github/actions/run-tests
In this example, each action is organized in a separate directory and is called individually through the uses field in the workflow. This allows you to combine and reuse actions flexibly across different workflows.