Git Product home page Git Product logo

skills-reusable-workflows's Introduction

Reusable workflows and matrix strategies

Make a workflow reusable, call it in another workflow, and use a matrix strategy to run multiple versions.

Step 2: Add a job to call the reusable workflow

Nice work! 🎉 You made a workflow reusable!

Now that you have a reusable workflow, you can call it in another workflow within a new or existing job. But before we do that, let's take a minute to understand what our reusable workflow is doing by looking at the content of the file.

Understanding the file contents of your reusable workflow

name: Reusable Workflow

on:
  workflow_call:
    inputs:
      node:
        required: true
        type: string

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - name: Output the input value
        run: |
          echo "The node version to use is: ${{ inputs.node }}"

The reusable workflow requires an input of node in order for the workflow to work. You need to make sure that the other workflow you are using to call this reusable workflow outputs a node version. If a node input is detected, the workflow will kick off a job called build that runs on ubuntu-latest.

The step within the build job uses an action called checkout@v3 to checkout the code and then a step to output the input value by running an echo command to print to the Actions log console the following message, The node version to use is: ${{ inputs.node }}. The node input here is the output node value you need to have in your other workflow.

Okay, now that we know what the reusable workflow is doing, let's now add a new job to another workflow called my-starter-workflow to call our reusable workflow. We can do this by using the uses: command and then setting the path to the workflow we want to use. We also need to make sure we define that node input or the reusable workflow won't work.

⌨️ Activity: Add a job to your workflow to call the reusable workflow

  1. Navigate to the .github/workflows/ folder and open the my-starter-workflow.yml file.

  2. Add a new job to the workflow called call-reusable-workflow.

  3. Add a uses command and path the command to the reusable-workflow.yml file.

  4. Add a with command to pass in a node paramater and set the value to 14.

    call-reusable-workflow:
      uses: ./.github/workflows/reusable-workflow.yml
      with:
        node: 14
  5. To commit your changes, click Start commit, and then Commit changes.

  6. Wait about 20 seconds for actions to run, then refresh this page (the one you're following instructions from) and an action will automatically close this step and open the next one.


Get help: Post in our discussion boardReview the GitHub status page

© 2023 GitHub • Code of ConductMIT License

skills-reusable-workflows's People

Contributors

seacrest avatar github-actions[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.