Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reusing GitHub Action workflow steps inside another job

I have created a Reusable Workflow using a workflow_call trigger, but I need to run additional steps based on its outcome.

Example:

jobs:
  released:
    steps:
      - name: Build
        uses: my-org/some-repo/.github/workflows/build.yml@main

      - name: Upload source maps
        run: something

The reusable Build step builds my JS app and produces source maps. Now I need to upload these source maps to somewhere as a separate step that should only run inside this Released job.

Doing the above results in the following error:

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

It only allows running my reusable workflow inside a job, not inside a step. But by doing that I can no longer access the source maps.

My question: How do I reuse the steps from the Build workflow and access its output inside the Released job?

like image 445
Duncan Luk Avatar asked Feb 12 '26 21:02

Duncan Luk


1 Answers

You can share these output files between jobs using artifacts.

Use the upload-artifact to upload the build files from the Build workflow and download-artifact to download them in the Released workflow.

Build workflow

name: Build

on:
  workflow_call:
    secrets:
      SOME_SECRET:
        required: true

jobs:
  build:
    steps:
      # Your build steps here

      - name: Create build-output artifact
        uses: actions/upload-artifact@master
        with:
          name: build-output
          path: build/

Released workflow

name: Released

on:
  push:
    branches:
      - main

jobs:
  build:
    uses: my-org/some-repo/.github/workflows/build.yml@main
    secrets:
      SOME_SECRET: ${{ secrets.SOME_SECRET }}

  released:
    needs: build

    steps:
      - name: Download build-output artifact
        uses: actions/download-artifact@master
        with:
          name: build-output
          path: build/

      # The "build" directory is now available inside this job

      - name: Upload source maps
        run: something

Bonus tip: Note that the "my-org/some-repo/.github/workflows/build.yml@main" string is case-sensitive. I wasted some time figuring out that that was the cause of the error below.

Error : .github#L1
error parsing called workflow "my-org/some-repo/.github/workflows/build.yml@main": workflow was not found. See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.

like image 122
Duncan Luk Avatar answered Feb 15 '26 11:02

Duncan Luk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!