GH-200 · CHEAT SHEET
GitHub Actions
Key concepts grouped by official exam weight.
Download as PDF (free, no sign-up)1. Author and manage workflows
20–25%Configure workflow triggers and events
- Pick the event by its source: schedule with cron (UTC unless a timezone is set, always on the default branch), workflow_dispatch for manual runs, repository_dispatch for external systems through the API with event_type and client_payload, and workflow_run to chain workflows. Events such as issues, issue_comment, release or pull_request_review cover repository activity.
- Narrow each event with types (without them pull_request only reacts to opened, synchronize and reopened) and with branches, tags and paths filters, which combine: all must be satisfied. Choose pull_request_target only for tasks that do not run pull request code. Declare permissions at workflow or job level: anything not listed becomes none.
- workflow_dispatch inputs support the boolean, choice, number, environment and string types, with required, default and options (a choice default must be in options); read them with the inputs context, which keeps Booleans. In workflow_call, type is required and only allows boolean, number or string, and secrets are mapped by name or with secrets: inherit.
Design and implement workflow structure
- Job and step if conditions are evaluated by GitHub Actions and get an implicit success() unless they include always(), failure(), cancelled() or !cancelled(); an expression that starts with ! must be wrapped in ${{ }}. continue-on-error keeps a job (on a step) or the run (on a job) from failing, and timeout-minutes limits how long a step or a job can run.
- Without needs, jobs run in parallel; needs, as a string or array, makes a job wait for the listed jobs to complete successfully. If a dependency fails or is skipped, every later job in the chain is skipped unless it uses a condition such as always() or !cancelled(). needs.<job_id>.result lets you react to the result of one specific dependency.
- Workflow commands are written to output as ::command parameters::value: group and endgroup nest lines, add-mask hides values (once per value per job), error, warning and notice create annotations with file and line, and stop-commands pauses processing with a random token. env is set at workflow, job or step level and the most specific wins; default GITHUB_* variables cannot be overwritten.
- services creates fresh Docker containers for each job (databases, caches or queues) that are destroyed when the job ends and require a Linux runner. If the job runs in a container, reach the service by its label without port mapping; if it runs on the runner, map ports and use localhost. options accepts Docker health checks, and command or entrypoint change how the service starts.
- jobs.<job_id>.strategy.matrix creates one job per combination of variables; exclude removes combinations (a partial match is enough) and include adds keys or new combinations, and is processed after exclude. fail-fast (true by default) cancels the rest of the matrix when a job fails, and max-parallel limits simultaneous jobs. To avoid -latest label migrations, specify an explicit version label.
Manage workflow execution and outputs
- actions/cache stores paths under a key (for example runner.os plus hashFiles of the lock file); without an exact match it tries restore-keys as prefixes and restores the most recent cache, and an existing cache is never modified. upload-artifact accepts retention-days, bounded by the repository or organization limit, which is read and changed with GET and PUT on .../actions/permissions/artifact-and-log-retention.
- Within a job, a step with an id writes name=value to GITHUB_OUTPUT and later steps read it with steps.<id>.outputs; GITHUB_ENV and GITHUB_PATH only affect later steps of the same job. Between jobs you use jobs.<id>.outputs and needs, or artifacts for files; a reusable workflow exposes job outputs in on.workflow_call.outputs. Outputs containing secrets are skipped.
- Each step can add GitHub Flavored Markdown to the GITHUB_STEP_SUMMARY environment file, which is unique per step; when the job ends, its steps' summaries are grouped into one job summary on the run summary page. Use >> to append, > to overwrite the current step's content, and delete the file to remove it; uploaded content cannot be changed later and secrets are masked.
- A status badge uses https://github.com/OWNER/REPOSITORY/actions/workflows/WORKFLOW-FILE/badge.svg and shows the default branch by default; ?branch= and ?event= filter by branch or event, and private repository badges are not accessible externally. jobs.<job_id>.environment takes a name or an object with name and url (both can use expressions), and deployment: false uses environment secrets without creating a deployment.
2. Consume and troubleshoot workflows
15–20%Interpret workflow behavior and results
- To see why a run started or not, check on:, the branches, tags and paths filters (defining only branches means tag pushes do not run) and event conditions: schedule and issues use the default branch, pull_request does not run with merge conflicts and [skip ci] only affects push and pull_request. Events raised with GITHUB_TOKEN create no runs except workflow_dispatch and repository_dispatch, and its pull_request runs need approval.
- To diagnose a failed run, review the failed step's logs, search them or download the log archive; the Set up job step records the runner image and JOB-NAME/system.txt shows how a job-level if was evaluated. Setting ACTIONS_STEP_DEBUG and ACTIONS_RUNNER_DEBUG to true (the secret wins over the variable) adds detail, and a re-run can enable debug logging (gh run rerun --debug).
- In a workflow, an anchor (&name) marks content and an alias (*name) repeats it unchanged elsewhere: a value, a list, an env mapping or a whole job. To read the file, replace each alias with the most recent preceding node anchored with that name; an alias before its anchor is an error, anchor names are discarded after parsing and an alias cannot carry content of its own.
- A matrix creates one job per combination of variables; exclude removes partially matching combinations and include, processed afterwards, adds keys to original combinations it does not overwrite or creates new ones. A name using ${{ matrix.* }} ties each job to its axes, fail-fast (true by default) cancels the rest when one fails, and you can re-run a single job (gh run rerun --job), which also re-runs jobs that depend on it.
Access workflow artifacts and logs
- In the UI, the Actions tab lists workflows and their runs; each run summary leads to job logs and the artifacts section. With GitHub CLI, gh run list filters by workflow, branch, event, status or user (--all includes disabled workflows) and gh run view shows attempts, jobs and logs. The REST API lists runs and jobs and redirects to downloads of run or job logs.
- Inside a run, actions/download-artifact downloads one artifact by name or artifact-ids, or all of them when omitted, each into its own directory unless merge-multiple is set; another run or repository needs github-token and run-id. Outside a run, use gh run download or the REST API, which lists, downloads through a redirect and deletes artifacts; a deleted artifact cannot be restored.
Use and manage workflow templates
- A reusable workflow (on: workflow_call) is called with jobs.<job_id>.uses, never from a step, and the calling job only accepts keys such as with, secrets, strategy, needs, if, concurrency and permissions. The caller's env is not propagated, the github context and billing belong to the caller, and re-running only failed jobs uses the same commit as the first attempt.
- An organization's workflow templates can be used in repositories whose visibility matches or is more restricted than the .github repository: a public one serves all, an internal one only internal and private repositories, and a private one only private repositories. If the .github repository is private or internal, grant Read access to the users or teams who should use the templates.
- Workflow templates (formerly starter workflows) are chosen when creating a workflow: GitHub recommends them based on the repository's language and the full list lives in actions/starter-workflows. The template produces your own file that you can adjust before committing (for example on), storing any secret it uses as a repository secret, and committing to the default branch or through a pull request.
- A workflow template writes a new file into each repository, which then evolves on its own. A reusable workflow is a central file in .github/workflows called at job level; it can hold several jobs with their own runners and logs each step. A composite action bundles steps that run as a single step inside the job and can be published to GitHub Marketplace.
- Disabling a workflow (UI, gh workflow disable or PUT .../workflows/{workflow_id}/disable) stops it from being triggered without deleting its file and is reversed by enabling it; existing runs are not cancelled, but they cannot be re-run while it is disabled. Deleting the file removes the workflow, and deleting a run (gh run delete) permanently removes its artifacts as well.
3. Author and maintain actions
15–20%Create and troubleshoot custom actions
- JavaScript actions run directly on the runner, work on Linux, Windows and macOS when the code is pure JavaScript, and start faster. Docker container actions package the OS and tools from a Dockerfile or a docker:// registry image, but only run on Linux (with Docker installed on self-hosted runners). Composite actions bundle run and uses steps into a single step.
- Action failures usually come from the package itself: a JavaScript action must ship its dependencies (for example bundled into dist/index.js), Docker container actions only run on Linux runners with Docker and their entrypoint.sh must be executable, and every run step of a composite action needs shell. required: true does not validate an input by itself; use core.getInput with required and core.setFailed.
Define action structure and metadata
- Every action needs a metadata file named action.yml or action.yaml with the required name, description and runs keys; inputs, outputs, author and branding are optional. Composite action outputs need value, a local Dockerfile must be named Dockerfile with a path relative to the metadata file, and actions in a repository with application code belong in .github/actions.
- Inside an action, @actions/core wraps the workflow commands: getInput reads INPUT_<NAME>, setOutput writes to GITHUB_OUTPUT, exportVariable to GITHUB_ENV, addPath to GITHUB_PATH, setSecret matches add-mask and setFailed matches ::error plus exit 1. saveState writes to GITHUB_STATE, and the value reaches the pre and post scripts of the same action as STATE_.
Distribute and maintain actions
- An action in a public repository can be used by any repository, even if it is not on GitHub Marketplace. Actions in internal repositories are shared with internal and private repositories of the organization or enterprise, and actions in private repositories only with private repositories. A local action is referenced with ./ after checking out the repository, and a Docker Hub image with docker://image:tag.
- To publish to GitHub Marketplace the action must be in a public repository with a single action.yml at the root and a unique name, and the owning account must accept the Marketplace Developer Agreement. Publishing is immediate, without GitHub review, and requires two-factor authentication. The listing is linked to the action's name and is removed by editing each published release.
- Publish releases with semantic tags (v1.0.1) and keep the major and minor tags (v1, v1.1) current; create a new major version for breaking changes such as changed inputs. With immutable releases, a published release's tag and assets are locked: keep v1 as a Git tag without a release and create releases as drafts before attaching assets.
4. Manage GitHub Actions for the enterprise
20–25%Distribute and govern actions and workflows
- Organization workflow templates live in the workflow-templates directory of the .github repository, each with a NAME.properties.json metadata file (name and description required; iconName, categories and filePatterns optional) and the $default-branch placeholder. Reusable workflows live directly in .github/workflows, without subdirectories, and declare on: workflow_call.
- Actions and reusable workflows in a private or internal repository are shared through the repository's Actions access setting (or access_level in the REST API: none, user, organization, enterprise). Private repositories serve only private callers, internal ones serve internal and private callers. Enterprise policies decide which organizations use Actions, and organizations cannot override them.
- The organization decides which repositories run Actions (enabled_repositories: all, none or selected), the GITHUB_TOKEN default (a restrictive default disables the permissive option in repositories) and whether workflows may create or approve pull requests. It also sets approval for public fork runs and the policies for forks of private repositories.
Manage runners at scale
- GitHub-hosted runners (standard or larger) use a fresh VM per job; self-hosted runners give hardware control but you update the OS. They are registered with config.sh (URL and token), routed with cumulative runs-on labels and scaled with ephemeral runners (--ephemeral) or Actions Runner Controller. Their status is Idle, Active or Offline.
- With an IP allow list, GitHub Actions needs self-hosted runners or larger runners with static IPs added to the list, because GITHUB_TOKEN is restricted too. Self-hosted runners only need outbound HTTPS on port 443 and read proxy settings from https_proxy, no_proxy or a .env file. Azure private networking works with larger runners attached to a runner group.
- Runner groups limit which repositories can use runners; without a group a runner joins the default group, and config.sh --runnergroup registers it elsewhere. With runs-on group and labels a runner must match both or the job stays queued. To troubleshoot, use config.sh --check, the Runner_ and Worker_ logs in _diag, journalctl and the Docker checks.
- The Set up job log links to the software included on the exact runner, and actions/runner-images publishes releases and pre-releases for each image. setup-* actions check the tool cache (RUNNER_TOOL_CACHE) first and pin versions; you can also install with apt-get, brew or choco, run the job in a container, or build custom images with snapshot for larger runners.
Manage encrypted secrets and variables
- Secrets and variables exist at organization, repository and environment level; with the same name, the lowest level wins. Organization ones support access policies (all, private or selected) and environment ones need admin access and are read when the job starts. Names use only letters, numbers and underscores, with no GITHUB_ prefix and no leading number.
- Secrets are read with the secrets context and passed to actions as inputs or environment variables; they are not used directly in if or inside composite actions. Variables are read with vars. Through the API, a secret value is encrypted with libsodium and the public key and sent with PUT; variables are created with POST and updated with PATCH. GitHub CLI offers gh secret set and gh variable set.
5. Secure and optimize automation
10–15%Implement security best practices
- An environment can require reviewers (one approval is enough; self-review can be prevented), a wait timer, deployment branches and tags, and custom rules built with GitHub Apps. The job cannot read environment secrets until the rules pass, and a rejection fails the workflow. With deployment: false, required reviewers still apply.
- The verified creator badge means GitHub verified the creator as a partner organization, but it does not replace auditing the action's code. The dependency graph lists the actions your workflows use and their version or SHA; Dependabot alerts on vulnerable semver-referenced actions and opens update pull requests, and dependency review warns before merge.
- ${{ }} expressions are substituted before the run: script executes, so values such as titles, bodies, commit messages or branch names can inject commands. The recommended fix is an action that takes the value as an input or, for inline scripts, a double-quoted intermediate environment variable; restricting GITHUB_TOKEN only limits damage. pull_request_target must not run fork code.
- GITHUB_TOKEN is a GitHub App installation token created at the start of each job; it expires when the job ends and only reaches the workflow's repository. The permissions key, at workflow or job level, sets its scopes (unlisted scopes become none). For other repositories, use a GitHub App installation token or a personal access token.
- With OIDC, the workflow gets a short-lived token from the cloud provider that is valid for one job, without storing long-lived credentials as secrets. The job needs id-token: write, which grants no write access to other resources, and the cloud trusts https://token.actions.githubusercontent.com with conditions on sub and aud; with an environment, sub includes its name.
Optimize workflow performance and cost
- The setup-* actions (for example setup-node with cache and cache-dependency-path) create and restore caches with little configuration. When storage fills up, GitHub evicts caches by last access date; to avoid this you delete caches with gh cache delete or the REST API (by key and ref), and remove artifacts by ID or by deleting their run.
- Concurrency groups with cancel-in-progress cancel outdated runs, and queue: max queues deployments without canceling them. For scale, larger runners are pools that scale out to their maximum concurrency, and for self-hosted runners GitHub recommends Actions Runner Controller on Kubernetes and ephemeral runners (--ephemeral) for autoscaling.