Using and Writing Actions

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

An action is a reusable unit of work that a workflow step runs with uses:. Everything you do in a workflow that is not a plain run: shell command is an action: checking out code, installing a toolchain, uploading an artifact, deploying to Pages. This page covers both sides: how to consume actions safely (references, versions, inputs and outputs) and how to write and publish your own. The running example is this documentation site’s Antora publish workflow, which today uses actions/checkout, actions/setup-node and crazy-max/ghaction-github-pages. Version numbers below were verified on 2026-11-10; the official documentation wins on any discrepancy. For the workflow file itself see Getting Started; for branches, tags and releases see Tags and Releases.

Using actions

The uses syntax

Form Meaning Example

owner/repo@ref

An action whose action.yml is at the root of that repository, at a tag, branch or commit SHA.

actions/checkout@v7

owner/repo/path@ref

An action in a subdirectory of the repository (monorepos of actions).

gradle/actions/setup-gradle@v6

./path

A local action in the same repository, relative to the workspace root. The repository must be checked out first.

./.github/actions/setup-antora

docker://image:tag

Run a public container image directly as the step.

docker://alpine:3.22

owner/repo/.github/workflows/x.yml@ref

Not an action: a reusable workflow, used at job level. See Reusable Workflows and Composite Actions.

(job-level uses)

steps:
  - uses: actions/checkout@v7                 # tag
  - uses: actions/setup-node@v7
    with:
      node-version: 24                         # input
  - uses: ./.github/actions/setup-antora       # local action: checkout must come first
  - uses: docker://alpine:3.22                 # image as a step
    with:
      entrypoint: /bin/sh
      args: -c "echo hello from alpine"

Versioning: tags versus commit SHAs

A ref can be a branch, a tag or a full commit SHA. The choice is a trade-off between convenience and supply-chain safety.

Reference Behaviour Use when

Branch (@main)

Moves with every push. Unreviewed changes run in your pipeline.

Almost never for third-party actions.

Major tag (@v7)

A floating tag the maintainer moves forward with each compatible release. Gets fixes automatically.

Official actions/* and docker/* actions you trust.

Exact tag (@v7.0.1)

Reproducible unless the maintainer deletes and recreates the tag.

Compromise between readability and stability.

Full commit SHA

Immutable: the only reference a maintainer cannot silently re-point.

Third-party actions, release pipelines, anything with write permissions or secrets.

Pin to a SHA and leave the human-readable version in a comment, so Dependabot or Renovate can update both:

- uses: crazy-max/ghaction-github-pages@0123456789abcdef0123456789abcdef01234567 # v5.0.0

Dependabot understands the github-actions ecosystem and opens pull requests that bump the SHA and the comment together; see Security Hardening for the policy side (allow-listing actions, requiring SHA pinning).

Inputs and outputs

Inputs go in with:; they reach the action as environment variables named INPUT_<NAME> (upper-cased, spaces to underscores). An action’s outputs are read through the steps context by the step’s id:

- id: node
  uses: actions/setup-node@v7
  with:
    node-version-file: .nvmrc
- run: echo "Node ${{ steps.node.outputs.node-version }} installed"

Because with: values are strings, true and 24 arrive as the strings "true" and "24". Check the action’s README or action.yml for the exact input names and defaults; unknown inputs only produce a warning, so a typo silently falls back to the default.

Common official actions

Action Latest major Purpose

actions/checkout

v7

Clone the repository at the triggering ref; fetch-depth, submodules, persist-credentials, sparse-checkout.

actions/setup-node

v7

Install Node.js, optional package-manager cache, registry auth.

actions/setup-java

v6

Install a JDK (temurin, zulu, …​), cache Maven or Gradle, write settings.xml for publishing.

actions/setup-python

v7

Install Python, cache pip, pipenv or poetry.

actions/setup-dotnet

v6

Install .NET SDKs, NuGet source auth.

actions/setup-go

v7

Install Go with module and build cache.

actions/cache

v6

Generic cache with key and restore-keys. See Caching and Artifacts.

actions/upload-artifact

v7

Store files from a job as an artifact.

actions/download-artifact

v8

Fetch artifacts in a later job or from another run.

actions/github-script

v9

Run JavaScript with an authenticated Octokit client inline in a step.

actions/attest-build-provenance

v4

Sign build provenance for an artifact (wrapper over actions/attest).

actions/configure-pages, actions/upload-pages-artifact, actions/deploy-pages

v6, v5, v5

The Pages trio for deploying a built static site without a gh-pages branch.

actions/create-github-app-token

v3

Mint a short-lived GitHub App installation token.

github/codeql-action

v4

Code scanning with CodeQL.

Anatomy of an action run

When a job reaches a uses: step, the runner resolves the reference, downloads the action’s repository at that ref, reads action.yml, and executes according to runs.using. A JavaScript action runs inside the runner process tree; a Docker action builds or pulls an image and runs a container; a composite action expands into its own steps.

flowchart TD A["Step: uses owner/repo@ref"] --> B["Runner downloads the action at that ref"] B --> C["Read action.yml"] C --> D{"runs.using"} D -->|"node24"| E["pre (optional)"] E --> F["main: node dist/index.js"] D -->|"docker"| G["Build Dockerfile or pull image, run container"] D -->|"composite"| H["Run each inner step in order"] F --> I["Outputs via GITHUB_OUTPUT, state via GITHUB_STATE"] G --> I H --> I I --> J["post (optional) runs at the end of the job"]

Writing actions: action.yml

Every action has a metadata file named action.yml (or action.yaml) at its root. It declares the interface and how to run it.

name: 'Setup Antora'
description: 'Install Node, cache npm and install the Antora toolchain'
author: 'albertoirurueta'
branding:
  icon: 'book-open'
  color: 'blue'

inputs:
  node-version:
    description: 'Node.js version'
    required: false
    default: '24'
  extensions:
    description: 'Space separated list of extra npm packages'
    required: false
    default: ''

outputs:
  antora-version:
    description: 'Installed Antora version'
    value: ${{ steps.version.outputs.version }}

runs:
  using: composite
  steps:
    - uses: actions/setup-node@v7
      with:
        node-version: ${{ inputs.node-version }}
        cache: npm
    - run: npm ci
      shell: bash
    - id: version
      run: echo "version=$(npx antora --version | head -n1)" >> "$GITHUB_OUTPUT"
      shell: bash
Key Notes

name, description

Required. name is shown in the Marketplace and must be unique there.

inputs.<id>

description is required; required, default and deprecationMessage are optional.

outputs.<id>

For JavaScript and Docker actions only description; for composite actions also value, an expression.

runs

using selects the kind: node24, node20, docker or composite.

branding

Icon (a Feather icon name) and colour for the Marketplace badge.

JavaScript actions

A JavaScript action runs directly on the runner, starts fast, and works on Linux, Windows and macOS. Its metadata points at the entry file:

runs:
  using: node24
  pre: dist/pre.js
  main: dist/index.js
  post: dist/post.js

node24 is the current runtime for JavaScript actions and node20 is being retired; check the actions/runner release notes for the exact schedule before choosing, and prefer node24 for anything new. The runner provides the Node binary, so the action does not depend on the Node version installed on the image.

The toolkit

Package Use

@actions/core

getInput, setOutput, setFailed, info, warning, error, setSecret, saveState, getState, summary.

@actions/github

context (event payload, repo, sha) and getOctokit(token) for the REST and GraphQL APIs.

@actions/exec, @actions/io, @actions/tool-cache, @actions/cache, @actions/artifact

Run processes, file helpers, download and cache tools, and the cache and artifact services.

import * as core from '@actions/core'
import * as github from '@actions/github'

async function run() {
  try {
    const token = core.getInput('token', { required: true })
    const octokit = github.getOctokit(token)
    const { owner, repo } = github.context.repo
    const { data } = await octokit.rest.repos.get({ owner, repo })
    core.setOutput('default-branch', data.default_branch)
    core.info(`Default branch is ${data.default_branch}`)
  } catch (error) {
    core.setFailed(error instanceof Error ? error.message : String(error))
  }
}

run()

Bundling with ncc and committing dist

The runner does not run npm install for an action, so node_modules must either be committed or, better, bundled into a single file. @vercel/ncc compiles the entry point and its dependencies into dist/index.js:

npm install --save @actions/core @actions/github
npm install --save-dev @vercel/ncc
npx ncc build src/main.js -o dist --source-map --license licenses.txt
git add dist action.yml
git commit -m "Rebuild dist"

The dist directory must be committed on the tagged commit. A common safeguard is a CI job that rebuilds and fails if git diff --exit-code dist is not clean, so reviewers never approve source that does not match the shipped bundle.

Outputs, state, and pre and post steps

  • Outputs are written with core.setOutput(name, value), which appends to the file named by GITHUB_OUTPUT. From shell in a composite or run step use echo "name=value" >> "$GITHUB_OUTPUT".

  • State passes data between pre, main and post of the same action: core.saveState('key', value) (the GITHUB_STATE file) and core.getState('key').

  • pre runs before the job’s other steps; main runs in sequence; post runs at the end of the job even if earlier steps failed, which makes it the place for cleanup such as stopping a daemon or saving a cache. Both accept an if condition (pre-if, post-if), for example post-if: always().

runs:
  using: node24
  main: dist/main.js
  post: dist/post.js
  post-if: success()

Docker container actions

A Docker action packages the code and its environment, which makes it ideal for tools with heavy dependencies. It runs only on Linux runners.

name: 'Antora lint'
description: 'Run a docs linter inside a container'
inputs:
  path:
    description: 'Directory to lint'
    default: 'modules'
outputs:
  issues:
    description: 'Number of issues found'
runs:
  using: docker
  image: Dockerfile
  args:
    - ${{ inputs.path }}
FROM node:24-alpine
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
#!/bin/sh -l
issues=$(find "$1" -name '*.adoc' | wc -l)
echo "issues=$issues" >> "$GITHUB_OUTPUT"

image: Dockerfile builds the image on every run; for faster starts publish the image to a registry and reference it as image: 'docker://ghcr.io/albertoirurueta/antora-lint:1.0.0'. The workspace is mounted at /github/workspace, and the standard GITHUB_* variables are passed in.

Composite actions

A composite action bundles several steps (shell commands and other actions) behind a single uses:, as in the action.yml above. Every run: step needs an explicit shell:. The syntax, limits and a comparison with reusable workflows are on Reusable Workflows and Composite Actions.

Comparing the three kinds

JavaScript Docker container Composite

Runners

Linux, Windows, macOS

Linux only

All

Start-up

Fast

Slower (build or pull)

Fast

Dependencies

Bundled into dist

Anything in the image

Whatever the steps install

Best for

API calls, parsing, logic

Tools with complex environments

Gluing existing steps together

Testing actions

  • Unit tests for JavaScript actions with a test runner (Jest or Vitest), mocking @actions/core and @actions/github.

  • Integration test in the same repository: a workflow that runs the action from the local path and asserts on its outputs.

  • act can run workflows locally in containers; it is useful for fast feedback but does not reproduce every runner behaviour.

name: test-action
on: [push, pull_request]
jobs:
  smoke:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
    steps:
      - uses: actions/checkout@v7
      - id: run
        uses: ./
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - name: Assert output
        shell: bash
        run: test -n "${{ steps.run.outputs.default-branch }}"

Publishing to the Marketplace

  1. Keep one action per repository (the Marketplace lists the root action.yml), public, with a README documenting every input and output and a licence file.

  2. Commit the built dist and tag a release: git tag -a v1.0.0 -m "v1.0.0" and push the tag, then create a GitHub release; tick Publish this Action to the GitHub Marketplace and pick categories.

  3. Maintain a floating major tag so consumers can write @v1:

git tag -fa v1 -m "Update v1 to v1.0.1"
git push origin v1 --force

Moving a tag requires a forced push, which is exactly why security-conscious consumers pin to a SHA instead. Publish breaking changes as a new major (v2) and leave v1 untouched. See Tags and Releases for the general tagging workflow.

Common mistakes

  • Forgetting shell: on a composite run: step; the workflow fails validation.

  • Not committing dist, or committing a stale one; the action runs old code or fails with a missing module.

  • Using @main for a third-party action; one push by the maintainer changes your pipeline.

  • Referencing a local ./ action before actions/checkout has run.

  • Expecting Docker actions to work on Windows or macOS runners.

  • Printing a secret from an action without calling core.setSecret first.