github action - reusable workflow within the same repository

To call a reusable workflow within github, the workflow must and must exist in .github/workflows folder. For example,



We have 2 files here main.yaml and test.yaml. 

main.yaml calls test.yaml. 


main.yaml.


name: Hello World Workflow

on:
  push:
    branches:
      - main

  workflow_dispatch:  

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout self repo
        uses: actions/checkout@v4

      - name: Checkout gha core
        uses: actions/checkout@v4
        with:
          repository: mitzenjeremywoo/gha-core
          path: gha-core
          token: ${{ secrets.GITHUB_TOKEN }}  # or PAT if private

      - name: Say hello
        run: ls -al -R ${{ github.workspace }}

  call-reusable-workflow-external:
     needs: build
     uses: ./gha-core/.github/workflows/dotnet.yaml
     with:
       environment: "dev"
       
 

And 

name: dotnet-build

on:
  push:  # on push
    branches:
      - main
      - release
  pull_request: # on pull request
    branches:

  workflow_dispatch:  # able to

  workflow_call:
    inputs:
      environment:
        required: true
        type: string
   
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Say hello
        run: echo "👋 Hello from GitHub Actions! ${{ inputs.environment }}"

This is not the ideal workflow, as we probably wants to promote workflow reusability across our pipeline and more likely to references a key or master repo which contains reusable workflows.




 



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