skip to Main Content

Can I directly call a workflow from within a composite action?

This is my composite action:

name:   Service composite
description: Service composite
inputs:
    example_input:
      description: example input
      required: true
      type: string

runs:
  using: "composite"
  steps:
    - name: Service test
      id: Service_test
      shell: bash
      run: |
        echo "run the test1"
        echo "echo the inputs: ${{inputs.example_input}}"

    - name: call the workflow
      uses: ./.github/workflows/call_in_action_helper.yml

And this is my helper:

name: call in action

on:
  workflow_call:

jobs:
  job1:
    runs-on: ubuntu-latest
    outputs:
      data: ${{ steps.generate.outputs.data }}
    steps:
      - name: Generate data
        id: generate
        run: |
          echo "Hello from Job 1" > data.txt
          echo "data=$(cat data.txt)" >> $GITHUB_OUTPUT

runs:
  using: "composite"
  steps:
    - name: Service test
      id: Service_test
      shell: bash
      run: |
        echo "run the test1"
        echo "echo the inputs: ${{inputs.example_input}}"

    - name: call the workflow
      uses: ./.github/workflows/call_in_action_helper.yml

2

Answers


  1. Chosen as BEST ANSWER

    name: Start/Stop Service composite description: Start/Stop Service composite inputs: example_input: description: example input required: true type: string

    runs: using: "composite" steps: - name: Service test id: Service_test shell: bash run: | echo "run the test1" echo "echo the inputs: ${{inputs.example_input}}"

    - name: call the workflow
      uses: ./.github/workflows/call_in_action_helper.yml
    

    name: call in action

    on: workflow_call:

    jobs: job1: runs-on: ubuntu-latest outputs: data: ${{ steps.generate.outputs.data }} steps: - name: Generate data id: generate run: | echo "Hello from Job 1" > data.txt echo "data=$(cat data.txt)" >> $GITHUB_OUTPUT


  2. You can not call a reusable workflow from an action for reasons explained by @Benjamin W in his comment above. If you need to invoke both, you would need to define your reusable workflow so that it calls the action first and then performs the other steps that you need. Then you would invoke the reusable workflow as a job in your main workflow.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search