Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 36 ยท Projects and Practice

Practice: GitHub Scenarios and Decisions

Test what you learned with realistic GitHub scenarios: choose the right feature for security, automation, releases and administration problems, with answers and a self-scoring drill.

Knowing a feature exists is different from knowing when to reach for it. In real work nobody asks "explain environments"; they say "production deploys must be approved by a lead" and you must connect the problem to the tool. This practice lesson trains that connection with fourteen scenarios drawn from chapters 5 to 8, followed by a self-scoring drill you can run.

Cover the answers, decide what you would do, and then compare. Each answer names the feature and gives the reason, because a wrong tool that happens to work is a trap.

Automation scenarios

1. Tests take eight minutes, and 6 of them are downloading the same packages. Use a dependency cache keyed on the lock file hash (actions/cache, or cache: npm in setup-node). Add restore-keys for partial hits. See caching.

2. You must test on three Node versions and two operating systems without copying a job six times. A build matrix: os times node, with exclude for combinations you do not support and fail-fast: false to see all failures. See matrices.

3. Ten repositories run the same 40-line test workflow, and you need to change it. A reusable workflow (on: workflow_call) in a shared repository, called with uses: and pinned to a tag. A composite action is the better fit when only a sequence of steps is shared.

4. A deploy job must wait for a lead to click approve. An environment named production with required reviewers, and environment: production on the job. It also scopes production secrets to that job.

5. A step needs a cloud credential, and the security team forbids storing long-lived keys in GitHub. OpenID Connect: permissions: id-token: write, and the cloud trusts GitHub's short-lived token for your repository and branch. See secrets and OIDC.

6. A pull request title containing quotes breaks a shell step that echoes it. That is script injection in the making. Pass the title through env: and read it as $TITLE instead of splicing ${{ ... }} into the script.

Security scenarios

7. A contractor pushed an API key, noticed, and deleted it in the next commit. Revoke and rotate the key immediately; deleting a commit does not remove it from history or from clones. Turn on secret scanning and push protection so it is blocked next time. See secret scanning.

8. A critical vulnerability is announced in a library you use, deep in the dependency tree. Dependabot alerts tell you; a Dependabot security update pull request proposes the fixed version; if the direct parent has no new release, use your package manager's override mechanism. See Dependabot.

9. A researcher emails you details of a bug in your library, and you want to fix it quietly first. Enable private vulnerability reporting, draft a repository security advisory with a temporary private fork, request a CVE, then publish the advisory together with the patched release. See advisories.

10. Your workflow uses third-party/action@v2, and you worry a tag could be moved. Pin the action to a full commit SHA with a version comment, and let Dependabot's github-actions ecosystem update the pin.

Release and publishing scenarios

11. Your documentation site must update on every merge to main, for free, at a custom domain. GitHub Pages with the Actions publishing source (upload-pages-artifact plus deploy-pages), a CNAME record at your DNS provider, and Enforce HTTPS. See Pages.

12. You want every v* tag to produce a release with notes grouped as features and fixes. A tag-triggered workflow running gh release create "$GITHUB_REF_NAME" --generate-notes with contents: write, and .github/release.yml for categories. See releases.

Administration scenarios

13. Only the security team may change .github/workflows/, and everyone else needs their review. A CODEOWNERS rule /.github/workflows/ @org/security plus the ruleset option "Require review from Code Owners". See CODEOWNERS.

14. Nobody should push directly to main, and merges must wait for the ci-ok check. A branch ruleset on the default branch: require a pull request, require the status check, block force pushes. Test it in Evaluate mode first. See rulesets.

Match the problem to the feature

Slow CI Cache and matrix
Secrets Secrets, OIDC, scanning
Approval Environments and rulesets
Shipping Tags, releases, packages

Name the problem first, then pick the tool.

1 / 2

A self-scoring drill

Run the drill below. It holds a list of problem statements and the feature keywords that a good answer must mention. Replace the myAnswers strings with your own words and see how many you hit. It checks keywords only, which makes it a crude scorer (a real answer can be right in other words), so use the printed model answers to judge yourself honestly.

JS Stand-in: scenario drill (keyword scorer)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

With the starting answers you should score 4 of 6; fix the two misses by rewriting those answers.

How to study from here

  • Re-read the chapters in which you missed a scenario, and rebuild the relevant example in a scratch repository on GitHub.
  • Invent a fifteenth scenario from your own job and answer it in two sentences. Explaining the why is the real test.
  • Try the troubleshooting practice next: there the workflow is already written, and it is broken.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Ten repositories share one test pipeline that must be maintained centrally. Which feature fits best?

    A reusable workflow gives one source of truth, called from each repository.
  2. 2. A key was pushed to a public repository and then deleted. What comes first?

    Assume the key is compromised; cleanup of history comes after revocation.
  3. 3. You want to find bugs in your own code, not in dependencies. Which tool?

    Code scanning analyzes the source you wrote; Dependabot watches third-party packages.
  4. 4. Which pair makes direct pushes to main impossible and merges wait for CI?

    Rulesets enforce the pull request flow and required checks.

Summary

  • Start from the problem, then choose the feature: cache, matrix, reusable workflow, environment, OIDC, scanning, advisories, Pages, releases, CODEOWNERS, rulesets.
  • Always give the reason; a wrong tool that works today is a trap tomorrow.
  • Practice by inventing scenarios from your own projects.

Next: Practice: Troubleshooting Workflows