Deploying usually needs passwords, tokens, or keys. Those must never be written in a workflow file, because everyone who can read the repository would see them. GitHub stores them separately, as encrypted secrets.
You add a secret in the repository settings, under secrets and variables. In the workflow, secrets dot API key reads it. The safest way to use it is through an env value, so it reaches the command as an environment variable, not as text pasted into the script.
.github/workflows/deploy.ymlyaml
name: Deployon: pushjobs: deploy: runs-on: ubuntu-latest steps: - name: Use the API key env: API_KEY: ${{ secrets.API_KEY }} run: | echo "Key length: ${#API_KEY}" test -n "$API_KEY" && echo "Key is set"
Our run steps helper reads secrets from variables starting with SECRET underscore, standing in for GitHub's secret store. The step sees the key, and prints only its length, never the value. On GitHub, if a secret's value ever appears in a log, it's automatically replaced with stars.
Terminal
SECRET_API_KEY=sk-test-12345 run-steps .github/workflows/deploy.ymlWorkflow: Deploy (event: push, branch: main)Job: deploy ✓ Use the API key Key length: 13 Key is set Job succeeded
Never print a secret, even partly. Give each secret the smallest permissions possible. Rotate secrets now and then, and straight away if one might have leaked. And remember that pull requests from forks don't get your secrets, which protects you from strangers' code.