github action using composite actions from current repository and another repository

Github composite action is flexible and you can reuse it multiple times. Unlike the hard limitation impose by reusable workflow where you can only reference 1 single reusable workflow. This workflow cannot reference other workflow.

Let's create a simple composite action and then call it within the repository itself and then reference it from another external workflow. 

So I have the following folder structure 


And then the composite action here.

# .github/actions/greet-action/action.yml
name: 'Greet User'
description: 'Prints a greeting message'
inputs:
  name:
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  message:
    description: 'The greeting message'
runs:
  using: composite
  steps:
    - name: Greet
      shell: bash
      run: |
        echo "Hello, ${{ inputs.name }}!"
        echo "message='Hello, ${{ inputs.name }}!'" >> $GITHUB_OUTPUT

Then let's call it from a github workflow within the same repository.

# .github/workflows/use-composite.yml
name: Use Composite Action
on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Greeting Action
        id: greet
        uses: ./.github/actions/greet-action
        with:
          name: Alice

      - name: Output Result
        run: echo "Greeting!!! ${{ steps.greet.outputs.message }}"

To call it from another workflow residing in another repository.

# .github/workflows/use-composite.yml
name: Use Composite Action
on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Use Greeting Action
        id: greet
        uses: kepungnzai/gh-action-core/.github/actions/greet-action@main
        with:
          name: Alice

      - name: Output Result
        run: echo "Greeting!!! ${{ steps.greet.outputs.message }}"

You can reference here:-

https://github.com/kepungnzai/gh-action-consumer

https://github.com/kepungnzai/gh-action-core    



Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type