Assignments
25 practical assignments: 10 ๐ข Beginner, 10 ๐ก Intermediate, 5 ๐ด Advanced. Do them in a real repository (a free public repo gives you unlimited hosted minutes and every feature used here). Reading YAML is not the same as debugging it.
Index
| # | Level | Assignment |
|---|---|---|
| 1 | ๐ข | Your first workflow with branch and path filters |
| 2 | ๐ข | Drive runs from the terminal with gh |
| 3 | ๐ข | Node.js CI with the built-in dependency cache |
| 4 | ๐ข | Manual runs with typed workflow_dispatch inputs |
| 5 | ๐ข | Secrets vs configuration variables |
| 6 | ๐ข | Hand files between jobs with artifacts v4 |
| 7 | ๐ข | Scheduled health check with a job summary |
| 8 | ๐ข | Passing data: step outputs, job outputs, GITHUB_ENV, GITHUB_PATH |
| 9 | ๐ข | Conditions, status functions and failure handling |
| 10 | ๐ข | Readable logs and debug logging |
| 11 | ๐ก | Matrix with include/exclude and a single required gate |
| 12 | ๐ก | Concurrency: cancel stale PR runs, queue deployments |
| 13 | ๐ก | Least-privilege GITHUB_TOKEN and a PR comment bot |
| 14 | ๐ก | Environments with reviewers, wait timers and branch policies |
| 15 | ๐ก | Write a composite action |
| 16 | ๐ก | Write a reusable workflow with inputs, secrets and outputs |
| 17 | ๐ก | Caching done right: keys, restore-keys and BuildKit type=gha |
| 18 | ๐ก | OIDC to AWS: push to ECR with zero stored keys |
| 19 | ๐ก | Monorepo: dynamic matrix from changed paths |
| 20 | ๐ก | Build and publish images to GHCR with proper tags |
| 21 | ๐ด | Exploit and fix script injection and a pull_request_target pwn request |
| 22 | ๐ด | Build, test and release a JavaScript action |
| 23 | ๐ด | Self-hosted runners on Kubernetes with ARC scale sets |
| 24 | ๐ด | OIDC to Azure and GCP, and a custom sub claim |
| 25 | ๐ด | Supply-chain hardened release pipeline with org-level guardrails |
๐ข Beginner
Assignment 1. Your first workflow with branch and path filters ๐ข
Objective: Understand how an event is matched to a workflow file and when a workflow does not start.
Tasks
- Create a repo with a
src/folder, adocs/folder and.github/workflows/ci.yml. - Trigger on
pushtomainand onpull_requesttargetingmain. - Add
paths-ignore: ['docs/**', '**.md']to both triggers. - Add one job on
ubuntu-latestthat checks out the code and printsgithub.event_name,github.ref,github.shaandgithub.actor. - Push a change to
docs/README.mdand confirm no run starts. Push a change tosrc/and confirm it does. - Open a PR from a feature branch and compare
github.refon the PR run with the push run.
Expected outcome / acceptance criteria
- A docs-only push creates no run; a code push creates one.
- You can explain why the PR run shows
refs/pull/<n>/mergeand whygithub.shaon a PR is the test merge commit, not your branch head.
Hints
on:
push:
branches: [main]
paths-ignore: ['docs/**', '**.md']
pull_request:
branches: [main]
paths-ignore: ['docs/**', '**.md']branches and paths are ANDed: both must match. The PR head commit is github.event.pull_request.head.sha.
Bonus: Make the job required in branch protection, then open a docs-only PR. Note that the PR is blocked ("Expected โ Waiting for status to be reported") and write down two ways to fix that.
Assignment 2. Drive runs from the terminal with gh ๐ข
Objective: Inspect, re-run and download from workflow runs without the web UI.
Tasks
- Install the GitHub CLI and run
gh auth login, thengh auth statusto confirm theworkflowscope. - List the last 10 runs of
ci.ymlwithgh run list. - Break a test on purpose and push. Use
gh run watchto follow the run live. - Show only the failed step logs with
gh run view <id> --log-failed. - Fix the test, then re-run just the failed jobs of the old run with
gh run rerun <id> --failed. - Disable and re-enable the workflow with
gh workflow disable/gh workflow enable.
Expected outcome / acceptance criteria
- A text file containing the exact commands you used and the run IDs.
- You can explain the difference between re-running failed jobs (same commit, same workflow file version) and pushing a new commit.
Hints
gh run list --workflow ci.yml -L 10, gh run view <id> --json conclusion,jobs --jq '.jobs[] | {name, conclusion}', gh run watch <id> --exit-status. Re-runs use the workflow file and GITHUB_SHA of the original run.
Bonus: Write a one-liner that cancels every in-progress run of a workflow on a given branch.
Assignment 3. Node.js CI with the built-in dependency cache ๐ข
Objective: Build a fast, deterministic CI job for a real project.
Tasks
- Add a small Node.js app with
package.json,package-lock.json, an ESLint config and at least three tests (node --testor Jest). - Write a job with
actions/checkout@v4andactions/setup-node@v4usingnode-version: 22andcache: npm. - Install with
npm ci, then runnpm run lintandnpm test. - Run it twice and compare the "Post Run actions/setup-node" logs and install time between the two runs.
- Add
timeout-minutes: 10to the job.
Expected outcome / acceptance criteria
- The second run logs a cache hit and installs noticeably faster.
- You can explain why
npm ci(notnpm install) and why the cache key is derived from the lockfile.
Hints
The setup-node cache stores the npm cache directory (~/.npm), not node_modules, keyed on a hash of package-lock.json. Without a lockfile, cache: npm fails with "Dependencies lock file is not found".
Bonus: Read the Node version from .nvmrc with node-version-file: .nvmrc so local and CI versions cannot drift.
Assignment 4. Manual runs with typed workflow_dispatch inputs ๐ข
Objective: Build a safe, parameterized manual workflow.
Tasks
- Create
ops.ymlwithworkflow_dispatchinputs:environment(choice: dev, staging, prod),dry_run(boolean, default true),replicas(number, default 2) andreason(string, required). - Print all inputs in the job, and print
DRY RUNwhendry_runis true. - Trigger it from the Actions tab.
- Trigger it from the terminal with
gh workflow run ops.yml -f environment=staging -f dry_run=false -f replicas=3 -f reason="load test". - Try to trigger it on a branch where the file does not exist and record the error.
Expected outcome / acceptance criteria
- Both UI and CLI runs succeed with correct values.
- You can explain that the workflow must exist on the default branch to appear in the UI, and that
--refselects which branch's version runs.
Hints
Boolean inputs arrive in inputs.dry_run as a real boolean, so if: inputs.dry_run works; in github.event.inputs they are strings. Never interpolate inputs.reason directly into run:; pass it through env:.
Bonus: Add run-name: Ops ${{ inputs.environment }} by @${{ github.actor }} so the runs list is readable.
Assignment 5. Secrets vs configuration variables ๐ข
Objective: Store config at the right level and understand masking.
Tasks
- Create a repo secret
API_TOKENand a repo variableAPI_URLwithgh secret setandgh variable set. - Use them in a step through
env:and callcurl -H "Authorization: Bearer $API_TOKEN" "$API_URL"(usehttps://httpbin.org/bearer). echo "$API_TOKEN"and confirm it shows as***in the log.- Print a base64-encoded version of the secret and observe that it is not masked. Then delete that run's logs.
- Open a PR from a fork (or ask a friend) and observe that
API_TOKENis empty there.
Expected outcome / acceptance criteria
- Variable used for non-sensitive config, secret for credentials, and you can name the precedence order (environment > repository > organization).
- You can explain why derived values must be masked with
::add-mask::.
Hints
gh secret set API_TOKEN --body "abc123", gh variable set API_URL --body https://httpbin.org/bearer. Secrets are referenced as ${{ secrets.API_TOKEN }}, variables as ${{ vars.API_URL }}. Delete run logs from the run's "..." menu or gh api -X DELETE repos/OWNER/REPO/actions/runs/<id>/logs.
Bonus: Mask a value produced at runtime (for example a token returned by an API) with echo "::add-mask::$TOKEN" before anything else prints it.
Assignment 6. Hand files between jobs with artifacts v4 ๐ข
Objective: Pass build output from one job to another and understand artifact scope.
Tasks
- Job
build: create adist/folder with a file containing the commit SHA, then upload it withactions/upload-artifact@v4asapp-dist,retention-days: 3. - Job
verifywithneeds: build: downloadapp-distwithactions/download-artifact@v4and check the file contents equalgithub.sha. - Add a matrix of 3 values to the build job that each uploads
report-<value>, then download all of them into one folder in a later job. - Download the artifact locally with
gh run download.
Expected outcome / acceptance criteria
verifypasses; the merged download contains three report files.- You can explain why two matrix legs uploading the same artifact name fail in v4.
Hints
- uses: actions/download-artifact@v4
with:
pattern: report-*
merge-multiple: true
path: reportsv4 artifacts are immutable: a second upload with the same name in a run errors with "an artifact with this name already exists" unless you use overwrite: true.
Bonus: Use the artifact-id output of upload-artifact and the REST API to fetch the artifact's size and expiry date.
Assignment 7. Scheduled health check with a job summary ๐ข
Objective: Use cron triggers and write a human-readable run summary.
Tasks
- Create
health.ymltriggered byschedule(every 30 minutes, at minute 7 and 37) and byworkflow_dispatch. - Curl three public URLs and record status code and response time with
curl -o /dev/null -s -w '%{http_code} %{time_total}'. - Write a markdown table of results to
$GITHUB_STEP_SUMMARY. - Fail the job if any URL does not return 200.
- Check the run times in the runs list and note the delay vs the cron time.
Expected outcome / acceptance criteria
- A run summary page with a results table.
- You can explain that cron is UTC, runs from the default branch only, can be delayed under load, and is disabled after 60 days of no repo activity on public repos.
Hints
on:
schedule:
- cron: '7,37 * * * *'Avoid minute 0: the top of the hour is the busiest time for the scheduler.
Bonus: Open (or update) a GitHub issue automatically when the check fails, using gh issue create with GH_TOKEN: ${{ github.token }} and issues: write.
Assignment 8. Passing data: step outputs, job outputs, GITHUB_ENV, GITHUB_PATH ๐ข
Objective: Use every in-run data channel correctly.
Tasks
- Step
meta(withid: meta): compute a short SHA and a version frompackage.json, write both to$GITHUB_OUTPUT. - Use them in a later step as
steps.meta.outputs.short_sha. - Write
BUILD_DATEto$GITHUB_ENVand read it in a later step as$BUILD_DATE. - Create
./bin/hello(an executable script), add./binto$GITHUB_PATHand callhelloin the next step. - Expose
versionas a job output and print it in a second job throughneeds.<job>.outputs.version. - Write a multiline value (the last 5 commit subjects) to
$GITHUB_OUTPUTusing a delimiter.
Expected outcome / acceptance criteria
- All values appear in later steps and in the second job.
- You can explain why
$GITHUB_ENVchanges are invisible to the step that writes them.
Hints
echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
{
echo "log<<GHA_DELIM"
git log -5 --format=%s
echo "GHA_DELIM"
} >> "$GITHUB_OUTPUT"Fetch history with fetch-depth: 0 (or at least 5) or git log -5 shows one commit.
Bonus: Try to output a secret as a job output and observe that GitHub skips it with a warning. Explain why.
Assignment 9. Conditions, status functions and failure handling ๐ข
Objective: Control what runs after a failure, a cancel or a skip.
Tasks
- Create jobs
testโbuildโdeploywithneeds. - Make
deployrun only on pushes tomain:if: github.event_name == 'push' && github.ref == 'refs/heads/main'. - Add a step at the end of
testthat runsif: failure()and prints diagnostic info, and one withif: always()that cleans up. - Add a
notifyjob thatneeds: [test, build, deploy], runsif: always(), and prints each needs result. - Make a flaky lint step
continue-on-error: trueand observe how the job conclusion andsteps.<id>.outcomevsconclusiondiffer. - Cancel a run mid-step and see which steps still run.
Expected outcome / acceptance criteria
- A table of scenarios (pass, fail, cancel) and which jobs and steps ran in each.
- You can explain why
!cancelled()is usually better thanalways()for post-processing.
Hints
needs.test.result is one of success, failure, cancelled, skipped. A job with if that contains no status function implicitly gets success() && prepended.
Bonus: Add timeout-minutes: 1 to a step running sleep 120 and record what conclusion it produces.
Assignment 10. Readable logs and debug logging ๐ข
Objective: Make failures easy to diagnose.
Tasks
- Use
::group::Install/::endgroup::to fold noisy output. - Emit
::notice::,::warning file=src/app.js,line=3::and::error::annotations and find them on the run summary and on the PR "Files changed" tab. - Re-run a job with "Enable debug logging" ticked and find the
##[debug]lines. - Set a repo variable
ACTIONS_STEP_DEBUG=trueand confirm debug output on the next run, then remove it. - Use
set -euxo pipefailin a multi-linerunand compare the output with the defaultbash -e {0}shell.
Expected outcome / acceptance criteria
- A screenshot or notes showing grouped logs, annotations on a line of code, and debug output.
- You can name the difference between step debug (
ACTIONS_STEP_DEBUG) and runner diagnostic logs (ACTIONS_RUNNER_DEBUG).
Hints
The default shell on Linux runners is bash --noprofile --norc -eo pipefail {0} only when you set shell: bash explicitly; the implicit default is bash -e {0}, which does not catch failures inside pipes. Set defaults.run.shell: bash at workflow level.
Bonus: Install actionlint locally and fix every issue it reports in your workflows.
๐ก Intermediate
Assignment 11. Matrix with include/exclude and a single required gate ๐ก
Objective: Test across versions and operating systems without breaking branch protection every time the matrix changes.
Tasks
- Build a matrix:
os: [ubuntu-latest, windows-latest, macos-latest],node: [20, 22, 24]. excludeNode 20 on macOS, andincludeone extra leg{os: ubuntu-latest, node: 24, experimental: true}.- Make the experimental leg non-blocking with
continue-on-error: ${{ matrix.experimental == true }}. - Set
fail-fast: falseandmax-parallel: 4. - Add a
ci-okjob withneeds: [test],if: always(), that fails unlessneeds.test.result == 'success'. - Make only
ci-oka required status check, then add Node 26 to the matrix and confirm protection still works.
Expected outcome / acceptance criteria
- 9 legs run (8 from the product minus exclude, plus the include), visible with readable names.
- A failing leg makes
ci-okred and blocks merge; a skippedtestjob does not sneak through as green.
Hints
ci-ok:
needs: [test]
if: always()
runs-on: ubuntu-latest
steps:
- run: |
[ "${{ needs.test.result }}" = "success" ] || { echo "test: ${{ needs.test.result }}"; exit 1; }Without if: always(), a failed test makes ci-ok skipped, and a skipped required check counts as passing.
Bonus: Name each leg with name: test (${{ matrix.os }}, node ${{ matrix.node }}) and compute the monthly minute cost difference between the macOS legs and the Linux legs in a private repo.
Assignment 12. Concurrency: cancel stale PR runs, queue deployments ๐ก
Objective: Save minutes on PRs and never run two deploys to the same environment at once.
Tasks
- In
ci.yml, addconcurrency: { group: ${{ github.workflow }}-${{ github.ref }}, cancel-in-progress: true }. - Push three commits to a PR within 30 seconds and confirm only the last run completes.
- Push two commits to
mainand confirm the main-branch runs are not cancelled by PR runs (differentgithub.ref). - In a
deployjob, setconcurrency: { group: deploy-${{ inputs.environment }}, cancel-in-progress: false }and add a 60 second sleep. - Trigger the deploy four times quickly and record what happens to runs 2, 3 and 4.
Expected outcome / acceptance criteria
- PR runs cancel each other; deploys queue.
- You can explain that a group holds at most one running and one pending entry, so run 2 is replaced by run 3 and then by run 4 while run 1 is still going.
Hints
To cancel only on PRs but never on main: cancel-in-progress: ${{ github.event_name == 'pull_request' }}. Workflow-level and job-level concurrency can be combined.
Bonus: Use github.head_ref || github.run_id in the group so pushes to main each get a unique group and never cancel anything.
Assignment 13. Least-privilege GITHUB_TOKEN and a PR comment bot ๐ก
Objective: Run every workflow with the minimum token scope.
Tasks
- Set the repo default workflow permissions to read-only (Settings > Actions > General, or
gh api -X PUT repos/OWNER/REPO/actions/permissions/workflow -f default_workflow_permissions=read). - Add
permissions: contents: readat the top of every workflow. - Add a
coverage-commentjob withpermissions: { contents: read, pull-requests: write }that posts or updates a single PR comment with test coverage usinggh pr comment --edit-lastorgh api. - Remove
pull-requests: writeand record the exact error. - Show that a tag pushed by a step using
GITHUB_TOKENdoes not trigger youron: push: tagsworkflow.
Expected outcome / acceptance criteria
- Comment job works with exactly two permissions; the error text without them is
Resource not accessible by integration(HTTP 403). - You can explain why GitHub suppresses workflow runs for events created with
GITHUB_TOKEN, and what to use instead (a GitHub App token viaactions/create-github-app-token).
Hints
gh reads GH_TOKEN: set env: GH_TOKEN: ${{ github.token }}. Any permission not listed in a permissions block becomes none. On fork PRs the token is read-only regardless of what you request.
Bonus: Use gh api repos/OWNER/REPO/actions/runs/<id>/jobs and the "Set up job" log section to show the effective token permissions of a job.
Assignment 14. Environments with reviewers, wait timers and branch policies ๐ก
Objective: Gate deployments with GitHub environments, not with YAML tricks.
Tasks
- Create environments
dev,staging,prod(UI orgh api -X PUT repos/OWNER/REPO/environments/prod). staging: 2 minute wait timer.prod: one required reviewer, "prevent self-review" on, deployment branches restricted tomainand tagsv*.- Add an environment secret
DB_PASSWORDwith different values per environment and an environment variableAPP_URL. - Write a deploy workflow with three jobs chained by
needs, each withenvironment: { name: <env>, url: ${{ vars.APP_URL }} }. - Try deploying prod from a feature branch with
workflow_dispatchand record the error. - Approve the prod job from the UI and confirm the URL appears on the run graph and in the repo's Deployments page.
Expected outcome / acceptance criteria
- Each job sees only its own environment's secret.
- Prod cannot run from a non-main branch and cannot be self-approved.
Hints
The error is Branch "feature/x" is not allowed to deploy to prod due to environment protection rules. Environment secrets are only released to the job after all protection rules pass. Required reviewers on private repos need GitHub Pro/Team/Enterprise.
Bonus: Add a deployment_status or gh api repos/OWNER/REPO/deployments query that lists the last 5 prod deployments with their SHA and status.
Assignment 15. Write a composite action ๐ก
Objective: Remove copy-pasted setup steps from many workflows.
Tasks
- Create
.github/actions/setup-app/action.ymlwithruns.using: composite. - Inputs:
node-version(default22),install(default'true'). Output:cache-hit. - Steps:
actions/setup-node@v4with npm cache, thennpm cionly wheninstall == 'true'. - Every
runstep in the action must declareshell: bash. - Use it from two workflows with
uses: ./.github/actions/setup-appafteractions/checkout. - Move the action to a separate public repo, tag
v1.0.0andv1, and consume it asOWNER/setup-app@v1.
Expected outcome / acceptance criteria
- Both workflows shrink and behave the same; the action's output is readable by the caller.
- You can explain why a local action needs checkout first, and why composite steps share the caller's workspace and env.
Hints
outputs:
cache-hit:
value: ${{ steps.node.outputs.cache-hit }}
runs:
using: composite
steps:
- id: node
uses: actions/setup-node@v4
with: { node-version: '${{ inputs.node-version }}', cache: npm }
- if: inputs.install == 'true'
run: npm ci
shell: bashComposite inputs are always strings.
Bonus: Add a branding block and an author, and write a README with a usage example, as you would for the Marketplace.
Assignment 16. Write a reusable workflow with inputs, secrets and outputs ๐ก
Objective: Share whole jobs (runner, environment, permissions) across repositories.
Tasks
- Create
.github/workflows/build.ymlwithon: workflow_call, inputsnode-version(string) andrun-e2e(boolean), secretNPM_TOKEN(required: false), outputartifact-name. - Inside, run lint, test, build, upload an artifact, and set the output from a job output.
- Call it from
ci.ymlat job level:jobs.build.uses: ./.github/workflows/build.ymlwithwith:andsecrets:. - Read
needs.build.outputs.artifact-namein a following job and download the artifact. - Call the same workflow from a second repository as
OWNER/REPO/.github/workflows/build.yml@v1. - Switch to
secrets: inheritand explain the trade-off.
Expected outcome / acceptance criteria
- Two callers use one implementation; outputs flow back to the caller.
- You can state the limits: reusable workflows nest up to 10 levels total, a run can call at most 50 unique reusable workflows, and
envfrom the caller is not propagated.
Hints
Outputs are mapped twice: on.workflow_call.outputs.artifact-name.value: ${{ jobs.build.outputs.name }}. A job that calls a reusable workflow cannot have steps or runs-on. Permissions in the called workflow can only reduce what the caller grants.
Bonus: Use a matrix in the caller to call the reusable workflow three times with different inputs.
Assignment 17. Caching done right: keys, restore-keys and BuildKit type=gha ๐ก
Objective: Get real cache hits, and measure them.
Tasks
- Cache
~/.cache/pip(or Go's module cache) withactions/cache@v4, key${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}and arestore-keysprefix. - Change one dependency and confirm a partial restore followed by a save under the new key.
- Build a Docker image with
docker/setup-buildx-action@v3anddocker/build-push-action@v6usingcache-from: type=ghaandcache-to: type=gha,mode=max. - Record build time cold, warm, and after changing only application code.
- List and delete caches with
gh cache listandgh cache delete. - Explain from a PR run why it can read
main's caches butmaincannot read the PR's.
Expected outcome / acceptance criteria
- A table of timings before and after caching.
- Correct explanation of cache scope (branch, then base branch, then default branch) and eviction (7 days unused, 10 GB per repo by default).
Hints
actions/cache saves only when the primary key missed. Use actions/cache/restore and actions/cache/save separately when you need to save even on failure. In a Dockerfile, copy lockfiles and install dependencies before COPY . . or every code change busts the layer cache.
Bonus: Write a workflow that deletes caches belonging to a PR branch when the PR is closed (on: pull_request: types: [closed], actions: write).
Assignment 18. OIDC to AWS: push to ECR with zero stored keys ๐ก
Objective: Replace AWS_ACCESS_KEY_ID secrets with federated, short-lived credentials.
Tasks
- Create the IAM OIDC provider for
https://token.actions.githubusercontent.comwith audiencests.amazonaws.com. - Create a role
gha-ecr-pushwhose trust policy requiresaud = sts.amazonaws.comandsub = repo:OWNER/REPO:ref:refs/heads/main. - Attach a policy allowing ECR push to one repository only, plus
ecr:GetAuthorizationToken. - In the workflow grant
permissions: { id-token: write, contents: read }, useaws-actions/configure-aws-credentials@v4withrole-to-assume, thenaws-actions/amazon-ecr-login@v2, then build and push. - Run
aws sts get-caller-identityin the job and confirm the assumed-role ARN. - Run the same workflow from a feature branch and record the error.
Expected outcome / acceptance criteria
- Image pushed from
main; feature branch denied withNot authorized to perform sts:AssumeRoleWithWebIdentity. - No AWS secrets exist in the repo (
gh secret listshows none).
Hints
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:OWNER/REPO:ref:refs/heads/main"
}
}A job with environment: sends sub = repo:OWNER/REPO:environment:<name> instead of the ref form.
Bonus: Add a step that decodes the OIDC token's claims (request it from $ACTIONS_ID_TOKEN_REQUEST_URL with $ACTIONS_ID_TOKEN_REQUEST_TOKEN) and prints sub, aud, ref and job_workflow_ref, never the raw token.
Assignment 19. Monorepo: dynamic matrix from changed paths ๐ก
Objective: Build and test only the services that changed, with one required check.
Tasks
- Create
services/api,services/web,services/worker, each with its own tests. - Job
changes: compute the list of changed service folders vs the PR base (git diff --name-onlywithfetch-depth: 0) and output a JSON array. - Job
testwithneeds: changes,if: needs.changes.outputs.services != '[]', andstrategy.matrix.service: ${{ fromJSON(needs.changes.outputs.services) }}. - Run the tests inside
services/${{ matrix.service }}usingdefaults.run.working-directory. - Add a
ci-okgate (as in Assignment 11) that also passes whentestwas skipped because nothing changed. - Open PRs touching zero, one and all three services.
Expected outcome / acceptance criteria
- PRs run exactly the matrix legs for changed services; a docs-only PR is green through
ci-ok. - A change to a shared folder (
libs/) triggers all services.
Hints
base=${{ github.event.pull_request.base.sha }}
svcs=$(git diff --name-only "$base" HEAD | awk -F/ '$1=="services"{print $2}' | sort -u | jq -R . | jq -cs .)
echo "services=$svcs" >> "$GITHUB_OUTPUT"An empty array in fromJSON for a matrix fails with "Matrix vector does not contain any values", which is why the if guard is needed. dorny/paths-filter is a popular alternative.
Bonus: Make the ci-ok gate accept success or skipped for test but nothing else.
Assignment 20. Build and publish images to GHCR with proper tags ๐ก
Objective: Produce traceable images with branch, SHA and semver tags.
Tasks
- Grant
packages: writeand log in toghcr.iowithdocker/login-action@v3using${{ github.actor }}and${{ secrets.GITHUB_TOKEN }}. - Use
docker/metadata-action@v5to generate tags:type=sha,type=ref,event=branch,type=semver,pattern={{version}},type=semver,pattern={{major}}.{{minor}}, and OCI labels. - Build multi-arch (
linux/amd64,linux/arm64) withdocker/setup-qemu-action@v3and buildx, and push only onmainand tags (push: ${{ github.event_name != 'pull_request' }}). - Tag
v1.2.0and confirm images1.2.0,1.2andlatestexist and share one digest. - Pull the image and check
org.opencontainers.image.revisionindocker inspect.
Expected outcome / acceptance criteria
- Package visible under the repo with linked source; PRs build but never push.
- You can explain why deployments should reference
@sha256:digests, notlatest.
Hints
The GITHUB_TOKEN can push to GHCR packages linked to the repo. If the package already exists and was created elsewhere, grant the repo access in the package settings, or you get denied: permission_denied: write_package.
Bonus: Replace QEMU emulation with native ubuntu-24.04-arm runners in a matrix and merge the per-arch images into one manifest with docker buildx imagetools create.
๐ด Advanced
Assignment 21. Exploit and fix script injection and a pull_request_target pwn request ๐ด
Objective: Prove, in a throwaway repo, why two common patterns leak secrets, then fix them.
Do this only in a disposable public repository you own, with a fake secret (
FAKE_TOKEN=not-a-real-secret). Never test against other people's repositories.
Tasks
- Injection: write a workflow on
issues: [opened]withrun: echo "New issue: ${{ github.event.issue.title }}". - Open an issue titled
x"; echo "INJECTED $FAKE_TOKEN" | base64; echo "withFAKE_TOKENset in the jobenvfrom a secret. Show that your command runs and the base64 value is printed unmasked. - Fix it by passing the title through
env: TITLE: ${{ github.event.issue.title }}and using"$TITLE". Re-run the attack and show it is inert. - Pwn request: write a workflow on
pull_request_targetthat checks outgithub.event.pull_request.head.shaand runsnpm testwith a secret inenv. - From a second account (or a fork) open a PR that changes the
testscript to print the secret base64-encoded. Show the leak. - Fix it: split into an unprivileged
pull_requestworkflow that runs the code and uploads results as an artifact, and aworkflow_runworkflow that only reads that artifact as data (never executes it) and posts a comment. - Run
zizmorandactionlinton the before and after versions.
Expected outcome / acceptance criteria
- A short write-up with the four YAML files (vulnerable and fixed) and the scanner output.
- You can explain why
pull_request_targetruns the base branch's workflow with secrets and a write token, and why checking out the head turns that into code execution.
Hints
Expressions are substituted into the script text before bash ever sees it, so quoting in YAML does not help. In the workflow_run consumer, treat the artifact like hostile input: validate it is a number or a fixed format, never source it or interpolate it into run:. Also set persist-credentials: false on checkout so the token is not left in .git/config.
Bonus: Add a "Require approval for all outside collaborators" setting for fork PR workflows, and explain why it does not protect pull_request_target.
Assignment 22. Build, test and release a JavaScript action ๐ด
Objective: Ship a production-quality action that others consume by tag and SHA.
Tasks
- Create a repo with
action.yml(runs.using: node24,main: dist/index.js), inputstokenandlabel, outputpr-number. - Implement it in
src/index.jswith@actions/coreand@actions/github: find the PR for the current commit and add the label. - Unit test it with Jest or
node --test, mocking@actions/github. - Bundle with
@vercel/ncc build src/index.js -o dist --license licenses.txtand commitdist/. - Add a CI job that rebuilds
dist/and fails ifgit diff --exit-code dist/shows changes. - Add an integration test job that uses the action from the same repo with
uses: ./. - Release
v1.0.0, move the major tagv1to it, and consume it from another repo both as@v1and pinned to the full commit SHA with a# v1.0.0comment.
Expected outcome / acceptance criteria
- Tests, dist check and integration test all green; the action labels a real PR.
- You can explain why
node_modulesis not committed, whydist/is, and why consumers should pin by SHA instead ofv1.
Hints
core.getInput('token', { required: true }), core.setOutput('pr-number', n), core.setFailed(err.message). Use github.getOctokit(token).rest.repos.listPullRequestsAssociatedWithCommit. Move the major tag with git tag -fa v1 -m v1.0.0 && git push origin v1 --force.
Bonus: Convert it to TypeScript, add a Dependabot config for npm and GitHub Actions, and publish it to the Marketplace.
Assignment 23. Self-hosted runners on Kubernetes with ARC scale sets ๐ด
Objective: Run ephemeral, autoscaling runners in your own cluster.
Tasks
- Create a kind or EKS cluster and a GitHub App (or a fine-grained PAT) for runner registration.
- Install the controller:
helm install arc --namespace arc-systems --create-namespace oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller. - Store the App credentials in a Kubernetes secret in
arc-runners. - Install a scale set named
arc-linuxwithgithubConfigUrlpointing at your repo or org,minRunners: 0,maxRunners: 5. - Run a workflow with
runs-on: arc-linuxand a 10-leg matrix; watch pods withkubectl get pods -n arc-runners -w. - Configure
containerMode.type: dind(orkuberneteswith a work volume) so jobs can build containers, and set CPU/memory requests in the runner pod template. - Restrict the scale set to one runner group that only trusted repos can use.
Expected outcome / acceptance criteria
- Pods scale from 0 to 5 under load, each runner takes one job then is deleted, and scale back to 0.
- A short note on why ephemeral runners matter for security and why public repos should never use self-hosted runners.
Hints
helm install arc-linux --namespace arc-runners --create-namespace \
--set githubConfigUrl="https://github.com/OWNER/REPO" \
--set githubConfigSecret=arc-github-app \
--set minRunners=0 --set maxRunners=5 \
oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-setThe Helm release name becomes the runs-on label. Check kubectl logs -n arc-systems deploy/arc-gha-rs-controller and the listener pod when jobs stay queued.
Bonus: Give the runner pods an IAM role through EKS Pod Identity or IRSA and compare that approach with OIDC from the workflow.
Assignment 24. OIDC to Azure and GCP, and a custom sub claim ๐ด
Objective: Use keyless federation on two more clouds and tighten what the token proves.
Tasks
- Azure: create an app registration (or a user-assigned managed identity), add a federated credential with issuer
https://token.actions.githubusercontent.com, subjectrepo:OWNER/REPO:environment:prod, audienceapi://AzureADTokenExchange, and grant it a role on one resource group. - In the workflow use
azure/login@v2withclient-id,tenant-id,subscription-id(nocredssecret) and runaz group show. - GCP: create a Workload Identity Pool and an OIDC provider with an
attribute-conditionthat restrictsassertion.repository_ownerandassertion.repository. - Bind a service account with
roles/iam.workloadIdentityUserto theprincipalSetfor your repository, then usegoogle-github-actions/auth@v2withworkload_identity_providerandservice_accountand rungcloud storage ls. - Customize the repo's OIDC
subclaim template to includejob_workflow_ref, then update the AWS or Azure trust to require that only your centraldeploy.ymlreusable workflow can assume the role. - Prove a different workflow in the same repo is now denied.
Expected outcome / acceptance criteria
- Both clouds authenticated without any long-lived secret.
- A table of the
subvalue per trigger (branch push, tag, PR, environment, custom template) and which trust policy accepts it.
Hints
gh api -X PUT repos/OWNER/REPO/actions/oidc/customization/sub \
--input - <<<'{"use_default":false,"include_claim_keys":["repo","context","job_workflow_ref"]}'Azure federated credentials match the subject exactly (no wildcards), so create one per environment or branch, or use flexible federated identity credentials. Azure needs id-token: write too.
Bonus: Write Terraform for all three cloud trusts and run it from a GitHub Actions workflow that itself uses OIDC.
Assignment 25. Supply-chain hardened release pipeline with org-level guardrails ๐ด
Objective: Combine everything into a release process an auditor would sign off.
Tasks
- Pin every third-party action to a full 40-character commit SHA with a version comment; add
.github/dependabot.ymlwithpackage-ecosystem: github-actions(weekly, grouped). - Add
CODEOWNERSfor.github/and require code owner review in a ruleset onmain. - Build the image once on
main, generate an SBOM (anchore/sbom-actionortrivy image --format cyclonedx), and create provenance withactions/attest-build-provenance@v2(id-token: write,attestations: write). - Release with release-please (or semantic-release) using a GitHub App token, so the tag it creates does trigger the release workflow.
- The release workflow promotes the existing image by digest (no rebuild), publishes a GitHub Release with the SBOM attached, and deploys to a
prodenvironment with a required reviewer. - Verify the attestation from your laptop with
gh attestation verify oci://IMAGE@sha256:... --owner OWNER. - At org or repo level: allow only GitHub-owned, verified-creator and listed actions; turn on "Require actions to be pinned to a full-length commit SHA" if available to you; protect
v*tags with a tag ruleset.
Expected outcome / acceptance criteria
- A diagram (Mermaid) of the pipeline and a list of each control and the threat it addresses.
gh attestation verifysucceeds for the released digest and fails for an image built on your laptop.zizmorreports no high-severity findings.
Hints
- uses: actions/create-github-app-token@v1
id: app
with:
app-id: ${{ vars.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_KEY }}Pass ${{ steps.app.outputs.token }} to release-please. Tags created with GITHUB_TOKEN would not start the release workflow. For in-cluster enforcement, Kyverno verifyImages or Sigstore policy-controller can require the attestation.
Bonus: Make the whole CI workflow a required workflow through an org ruleset so every repository runs it, and measure the change in median PR-to-merge time.