Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 3Name in the course: Actions and the Marketplace

Use and write actions

An action is a reusable step: check out code, set up a language, log in to a cloud, scan an image. Thousands are in the GitHub Marketplace. You can also write your own small composite actions to share steps between workflows.

  • 4 Lessons
  • 0 Commands

$ run as a normal user# run as root (or with sudo)

3.1

Use actions with inputs

uses: OWNER/REPO@VERSION runs an action; with: gives its inputs.

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
    with:
      fetch-depth: 0
  - uses: actions/setup-python@v5
    with:
      python-version: "3.12"
      cache: pip
  - uses: hashicorp/setup-terraform@v3
    with:
      terraform_version: "1.12.2"
Common actionDoes
actions/checkoutGet the repository code
actions/setup-python, setup-node, setup-goInstall a language version, with caching
actions/cacheCache any folder between runs
actions/upload-artifact, download-artifactPass files between jobs, keep reports
azure/loginLog in to Azure (with OIDC)
docker/build-push-actionBuild and push images
aquasecurity/trivy-actionScan images and code

3.2

Pin versions safely

A tag like @v4 can be moved by the action's owner. A full commit SHA can not.

.github/workflows/ci.yml
steps:
  - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683  # v4.2.2
ReferenceSafety
@mainWorst: any new commit runs in your pipeline
@v4OK for trusted publishers (GitHub, HashiCorp, Microsoft)
@<full SHA>Best: exactly the code you reviewed

At work

Dependabot can update pinned SHAs for you (see Secure your pipelines).

3.3

Pass outputs between steps

A step writes name=value into $GITHUB_OUTPUT; later steps read it with steps.ID.outputs.NAME.

.github/workflows/version.yml
steps:
  - id: ver
    run: echo "version=$(date +%Y.%m.%d)-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
  - run: echo "Building ${{ steps.ver.outputs.version }}"

3.4

Write a composite action

A composite action bundles several steps in one action.yml — for example "set up Terraform and run the checks".

.github/actions/tf-checks/action.yml
name: Terraform checks
description: fmt, init, validate and scan
inputs:
  dir:
    description: Working directory
    required: true
runs:
  using: composite
  steps:
    - run: terraform fmt -check -recursive
      shell: bash
      working-directory: ${{ inputs.dir }}
    - run: terraform init -backend=false && terraform validate
      shell: bash
      working-directory: ${{ inputs.dir }}
.github/workflows/ci.yml
steps:
  - uses: actions/checkout@v4
  - uses: ./.github/actions/tf-checks
    with:
      dir: envs/staging

Remember

In composite actions every run step needs shell:.