reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps

Viewed 1754

reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps

name: HelloWorld 
 on:
  workflow_dispatch:

 jobs:
  checkout:
   runs-on: windows-latest

  steps:
   - name: Checkout using the Template File 
     uses: actions/checkout@v2

   - name: Compile Java
     uses: org/repo/.github/workflows/build.yml@main
     with:
       jdk_version: 11
      
     

Error: .github#L1 reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps

2 Answers

Try the following:

name: HelloWorld 
 on:
  workflow_dispatch:

 jobs:
  checkout:
   uses: org/repo/.github/workflows/build.yml@main
   with:
    jdk_version: 11

And then at the beginning of build.yml, you can do

runs-on: windows-latest
steps:
 - uses: actions/checkout@v2

For whatever reason reusable workflows can't be inside steps, so you have to just use it at the top-level and do all your configuration/other steps inside the workflow you're calling.

Workflows can't be nested. A workflow bundles a bunch of actions.

You have to convert your workflows/build.yml into an actions/build.yml and then that action can be used for individual steps.

Related