liveBook · Manning

GitHub CLI

As explained in GitHub Actions in Action: Continuous integration and delivery for DevOps

GitHub CLI is a command-line tool for working with GitHub repositories, workflows, and other GitHub resources.

GitHub CLI provides command-line control over GitHub Actions workflows and repository configuration. Use it to start a named workflow, pass manual-run inputs noninteractively, and manage secrets or variables where command-line access is needed. section 3.3.3 section 3.7

Run a manually dispatchable workflow with `gh workflow run WORKFLOW_FILENAME`. A workflow can be selected by name, ID, or filename; filenames are usually most practical, while names containing spaces require quoting. Use `gh workflow list` to find IDs. section 3.3.3

Supply `workflow_dispatch` inputs in two ways:

  • Pass individual values with repeated `-f` or `--field` arguments. section 3.3.3
  • Pipe JSON to standard input and use `--json` when inputs already exist as JSON. section 3.3.3
  • Expect CLI prompting when required or optional inputs are not supplied directly. section 3.3.3

Run a staged workflow

`gh workflow run MyFirstWorkflow.yml -f homedrive=/home -f logLevel=warning -f tag=true -f environment=Staging` starts a workflow with string, choice, boolean, and environment inputs. Workflow steps read these values through the `inputs` context. section 3.3.3

Use `gh secret set` and `gh variable set` to create repository configuration values. Secrets are encrypted at rest, decrypted only at run time, and masked in workflow logs; variables and secrets may be defined at organization, repository, or environment levels, with lower levels overriding higher ones. section 3.7

$ gh secret set secret-name
$ gh variable set var-name

These commands create a secret or variable from the command line; input redirection can provide a secret value from a file, while `--body` sets a variable value directly. section 3.7

How GitHub Actions in Action: Continuous integration and delivery for DevOps covers it

How deep it goes
Demonstrates workflow execution, field and JSON inputs, plus secret and variable creation, without covering CLI installation or authentication.
Examples
Uses a workflow filename with home-drive, log-level, tag, and staging-environment inputs, plus secret and variable commands.
What it assumes
Assumes access to a repository and permission appropriate to workflow execution or configuration management.
What you can do after
Operate/configure GitHub Actions workflows and repository configuration through `gh` commands.
How it connects
Connects GitHub Actions, workflow_dispatch, repository_dispatch, secrets, variables, environments, and the GitHub API.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of GitHub Actions in Action: Continuous integration and delivery for DevOps. The section links point to the parts of the book it draws on.