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 |
|---|---|---|
|
An action whose |
|
|
An action in a subdirectory of the repository (monorepos of actions). |
|
|
A local action in the same repository, relative to the workspace root. The repository must be checked out first. |
|
|
Run a public container image directly as the step. |
|
|
Not an action: a reusable workflow, used at job level. See Reusable Workflows and Composite Actions. |
(job-level |
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 ( |
Moves with every push. Unreviewed changes run in your pipeline. |
Almost never for third-party actions. |
Major tag ( |
A floating tag the maintainer moves forward with each compatible release. Gets fixes automatically. |
Official |
Exact tag ( |
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 |
|---|---|---|
|
v7 |
Clone the repository at the triggering ref; |
|
v7 |
Install Node.js, optional package-manager cache, registry auth. |
|
v6 |
Install a JDK ( |
|
v7 |
Install Python, cache pip, pipenv or poetry. |
|
v6 |
Install .NET SDKs, NuGet source auth. |
|
v7 |
Install Go with module and build cache. |
|
v6 |
Generic cache with |
|
v7 |
Store files from a job as an artifact. |
|
v8 |
Fetch artifacts in a later job or from another run. |
|
v9 |
Run JavaScript with an authenticated Octokit client inline in a step. |
|
v4 |
Sign build provenance for an artifact (wrapper over |
|
v6, v5, v5 |
The Pages trio for deploying a built static site without a |
|
v3 |
Mint a short-lived GitHub App installation token. |
|
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.
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 |
|---|---|
|
Required. |
|
|
|
For JavaScript and Docker actions only |
|
|
|
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 |
|---|---|
|
|
|
|
|
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 byGITHUB_OUTPUT. From shell in a composite orrunstep useecho "name=value" >> "$GITHUB_OUTPUT". -
State passes data between
pre,mainandpostof the same action:core.saveState('key', value)(theGITHUB_STATEfile) andcore.getState('key'). -
preruns before the job’s other steps;mainruns in sequence;postruns 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 anifcondition (pre-if,post-if), for examplepost-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 |
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/coreand@actions/github. -
Integration test in the same repository: a workflow that runs the action from the local path and asserts on its outputs.
-
actcan 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
-
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. -
Commit the built
distand 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. -
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 compositerun: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
@mainfor a third-party action; one push by the maintainer changes your pipeline. -
Referencing a local
./action beforeactions/checkouthas run. -
Expecting Docker actions to work on Windows or macOS runners.
-
Printing a secret from an action without calling
core.setSecretfirst.