14

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?

5
  • if I understand correctly, might it help to split your things into multiple jobs and have the jobs communicate via outputs? stackoverflow.com/a/61236803/1080523 Commented Nov 17, 2021 at 11:59
  • @rethab If I understand correctly, outputs only work for string values. In this case I need to access the generated source map files. Commented Nov 17, 2021 at 12:58
  • Could the build job upload the source maps as build artifacts (using artifact-upload) and then the release job would download them again and upload them whereever else it wants to upload them? Commented Nov 17, 2021 at 13:07
  • 1
    You could create a local action using the composite type on this repository in the .github/actions/<action-folder-name> directory, and access it in your workflow job using in a step with uses: ./.github/actions/<action-folder-name>. This action could have an output variable that you could access in your other steps. Commented Nov 17, 2021 at 13:19
  • 3
    I've made an example: the workflow, the local (composite) action with an output, the workflow run. Let me know if it resolves your problem. Commented Nov 17, 2021 at 13:49

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.