AI Hints
Home›CI/CD with GitHub Actions Tutorial›Delivery Quiz and Reusable Workflows
CI/CD with GitHub Actions · Lesson 102 of 138

Inputs and Secrets for Reusable Workflows

Passing values in.

⏱ 2 min read▶ Video at 1:58:29🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Inputs are what make a reusable workflow flexible. Each one has a type, like string, number, or boolean, and can be required, or have a default. Secrets are declared separately, so they stay masked.

Inputs and Secrets for Reusable Workflows
From the video: Inputs and Secrets for Reusable Workflows
  • Typed inputs
  • Required or default
  • Secrets kept separate

A caller with a typo

Here's a caller. It uses the reusable workflow, and passes an input. But look closely. The input is called python versions, with an S. The reusable workflow expects python version.

.github/workflows/ci.ymlyaml
name: CI
on: [push, pull_request]
jobs:
  tests:
    uses: ./.github/workflows/python-tests.yml
    with:
      python-versions: "3.11"
    secrets: inherit

actionlint catches it

Actionlint reads both files, because the called workflow is in the same repository. It reports that python versions isn't a defined input, and lists the ones that are. We fix the name with sed, and actionlint is quiet.

Terminal
actionlint -format '{{range .}}{{.Message}}{{end}}' .github/workflows/ci.yml | fold -s -w 60
input "python-versions" is not defined in
"./.github/workflows/python-tests.yml" reusable workflow.
defined input is "python-version"
sed -i 's/python-versions/python-version/' .github/workflows/ci.yml
actionlint .github/workflows/ci.yml && echo "no problems found"
no problems found

Rules to remember

Required inputs must be passed, or the run fails. Secrets aren't passed automatically. Either list them, or use secrets inherit. Reusable workflows can also return outputs. And keep shared workflows in one repository, and call them with a version tag, so updates don't surprise anyone.

keyvalue
required: truemust be passed
secrets: inheritor list each one
outputsreturn values
@v1pin a version

Summary

Typed inputs and declared secrets make reusable workflows safe to share, and actionlint checks the calls. Next, composite actions.

Key takeaways
  • inputs with types
  • secrets: inherit
  • actionlint checks calls
Next up: Composite Actions — bundle steps together