brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh secret set -f loads several repository secrets from a dotenv file

CLI
~/tips/tip-github-secret-set-env-file

gh secret set -f .env

Sets GitHub Actions secrets from the terminal, one by one or all at once from a .env file.

Adding a secret in the GitHub web interface means a form per secret and a value pasted into a browser. The CLI does the same from your terminal, and it can take a whole dotenv file in one go.

gh secret set MYSECRET --body "$ENV_VALUE"
gh secret set -f .env

The first line sets one secret for the current repository, with the value from an environment variable. If you leave out --body, gh reads the value from standard input, or asks for it in an interactive prompt:

gh secret set MYSECRET < myfile.txt

With -f (--env-file) the names and values come from a dotenv-formatted file. -f - reads them from standard input. The help also says secret values are encrypted locally before they are sent to GitHub.

By default the secret is a repository secret for GitHub Actions. The flags change the level or the app:

  • --env myenvironment sets a deployment environment secret.
  • --org myOrg sets an organization secret, and --visibility takes all, private or selected (default private). With --repos repo1,repo2 you name the repositories that may use it.
  • --user sets a secret for your user, available to Codespaces.
  • --app dependabot sets it for Dependabot instead of Actions.

Two caveats. A .env file contains secrets in plain text, so keep it out of the repository and delete it when you are done. And --body puts the value on the command line, so it can end up in your shell history. For anything sensitive I would use standard input or the prompt. I did not run these commands against a real repository here. The details are from gh secret set --help.

Further reading: gh secret set manual

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link