github-actionsgithub-actions-reusable-workflows

GitHub Actions: Inputs not getting passed to reusable workflow


I'm having trouble passing inputs from my main workflow to a reusable workflow.

I pass a string using with so that I can access it from inputs, and then I supply inputs.myvar to the relevant step as an environmental variable to avoid quoting issues.

However, I get a null value instead of the value I expect:

cat: .ci/github/pa11y/.pa11yci-.js: No such file or directory
Error: Process completed with exit code 1.

Main workflow test.yml:

  pa11y_mysite:
    uses: ./.github/workflows/pa11y.yml
    with:
      site_alias: 'mysite'

Reusable workflow pa11y.yml:

name: pa11y

on:
  workflow_dispatch:
  workflow_call:
    inputs:
      site_alias:
        type: 'string'
        required: true


jobs:
  pa11y:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    steps:
      - name: "Check out this repo and submodules."
        uses: actions/checkout@v4.1.1
        with:
          lfs: false
          submodules: true
        timeout-minutes: 3
      - name: "Debug: Check pa11y config."
        run: cat ".ci/github/pa11y/.pa11yci-$SITE_ALIAS.js"
        env:
          SITE_ALIAS: $${ inputs.site_alias }}

What am I doing wrong?


Solution

  • The problem with your GitHub Actions workflow seems to come from incorrect syntax when using the input variable.

    In your reusable workflow (pa11y.yml):

    - name: "Debug: Check pa11y config."
      run: cat ".ci/github/pa11y/.pa11yci-${{ inputs.site_alias }}.js"
      env:
        SITE_ALIAS: ${{ inputs.site_alias }}
    

    Change $${ inputs.site_alias }} to ${{ inputs.site_alias }} to correctly pass the site_alias input from the main workflow to the reusable workflow.