GitHub Actions Flashcards

(50 cards)

1
Q

Where must you place a GitHub Actions workflow file?

A

In the repository’s .github/workflows/ directory, named with a .yml (or .yaml) extension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What top‐level YAML keys are required in a basic workflow?

A

name, on, and jobs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is the key called name:?

A

Because it’s a human‐readable label for the workflow shown in the Actions UI.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the on: key represent?

A

The events (e.g., push, pull_request, schedule) that trigger the workflow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you restrict a workflow to run only on pushes to specific branches?

A

Under on: → push: add branches: with a list (e.g., - main, - ‘feat/**’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What key do you use to ignore certain file paths from triggering a workflow?

A

paths-ignore: under the event (e.g., push:).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the jobs: section define?

A

A mapping of one or more isolated “jobs,” each running on its own runner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you name a job, and what are the rules?

A

Use a YAML key under jobs: (e.g., test-and-build:). It must be unique, without spaces, typically kebab‐case or snake_case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does runs-on: specify for a job?

A

Which runner image to use (e.g., ubuntu-latest, windows-latest, macos-latest, or self-hosted).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Name four common GitHub‐hosted runner labels.

A

ubuntu-latest, ubuntu-22.04, windows-latest, macos-latest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the purpose of the steps: list in a job?

A

It defines the ordered actions (or shell commands) to execute on that job’s runner.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

In a step, what’s the difference between uses: and run:?

A

uses: invokes a reusable Action (from Marketplace or local), while run: executes a shell command directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does actions/checkout@v4 do?

A

Clones (checks out) your repository’s code into the runner, so subsequent steps can access it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What’s the role of actions/setup-node@v4?

A

Installs a specified Node.js version (e.g., node-version: ‘18’) and can enable package caching (e.g., cache: ‘npm’).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why would you use actions/cache@v3?

A

To save and restore directories (e.g., node_modules, .nuxt/.cache) between workflow runs, speeding up builds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you configure actions/cache to cache node_modules?

A
  • uses: actions/cache@v3
    with:
    path: ~/.npm # or path: node_modules/
    key: ${{ runner.os }}-npm-${{ hashFiles(‘**/package-lock.json’) }}
    restore-keys: |
    ${{ runner.os }}-npm-
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you run a shell command in a step?

A

Use - name: … followed by run: your-command (e.g., run: npm ci). Optionally specify shell: if not using the default.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are “contexts” in GitHub Actions?

A

Built‐in objects (e.g., github, env, runner) that provide data about the workflow run, branch name, commit SHA, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you use an expression to reference a context value?

A

Wrap it in ${{ }} (e.g., ${{ github.ref }}, ${{ secrets.MY_SECRET }}).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you set an environment variable only for a single step?

A
  • name: Example
    run: echo “Value: $MY_VAR”
    env:
    MY_VAR: “123”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the if: key used for in a step?

A

To conditionally run or skip that step based on an expression (e.g., if: success() && github.ref == ‘refs/heads/main’).

22
Q

How do you grant a step permission to write logs or check out private submodules?

A

Use uses: actions/checkout@v4 with persist-credentials: true (default) or set permissions: at the workflow or job level.

23
Q

What does a “matrix strategy” accomplish?

A

Runs the same job multiple times with different configurations (e.g., Node versions or OS) in parallel.

24
Q

How do you define a matrix to run tests on Node16, 18, and 20?

A

strategy:
matrix:
node-version: [16, 18, 20]
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: ‘npm’
# …

25
What does the needs: key do in a job?
Makes the job depend on the successful completion of another job (e.g., needs: [lint, test]).
26
What is concurrency: used for?
To limit parallel runs of the same workflow or group cancel‐in‐progress runs for a given group.
27
What event triggers a manual workflow run?
workflow_dispatch: under on: enables manual triggers from the Actions tab.
28
How do you schedule a workflow to run nightly at 3 AM UTC?
on: schedule: - cron: '0 3 * * *'
29
Where do you store sensitive API_KEY values for use in Actions?
In the repository’s Settings → Secrets → Actions; reference it as ${{ secrets.API_KEY }}.
30
How do you output a value from one step so another step can reference it?
- id: step1 run: echo "::set-output name=myvar::hello" - run: echo "${{ steps.step1.outputs.myvar }}"
31
How do you pass an output from one job to another?
In job A: outputs: result: ${{ steps.step1.outputs.myvar }} In job B: needs: jobA run: echo "${{ needs.jobA.outputs.result }}"
32
What are service containers, and why use them?
Docker containers (e.g., services: mysql or services: redis) that run alongside your job—for integration tests against databases, caches, etc.
33
How do you mount a MySQL service container in a job?
services: mysql: image: mysql:8 env: MYSQL_ROOT_PASSWORD: root ports: - 3306:3306 options: >- --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
34
How do you deploy to GitHub Pages from a workflow?
Use peaceiris/actions-gh-pages@v3 (or a similar action) with a publish_dir: parameter, plus a GITHUB_TOKEN secret.
35
How do you publish an npm package in Actions?
- uses: actions/setup-node@v4 with: node-version: '18' registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm publish env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
36
How do you invoke a third‑party Action from GitHub Marketplace?
Under a step, write uses: owner/repo@version (e.g., uses: actions/upload-artifact@v3).
37
What is a composite action, and how is it defined?
A reusable custom Action made of multiple shell commands or sub‑steps; defined in action.yml with runs: using: "composite" and steps: inside.
38
How does a Docker container Action differ from a composite Action?
A Docker Action packages a custom Docker image and defines runs: using: "docker" vs. a composite Action which runs steps on the GitHub runner directly.
39
What is a reusable workflow, and how do you call it?
A workflow defined with on: workflow_call that other workflows invoke via uses: owner/repo/.github/workflows/name.yml@ref with with: inputs.
40
How do you pass inputs to a called reusable workflow?
jobs: call-other: uses: owner/repo/.github/workflows/other.yml@main with: myInput: 'value' secrets: MY_SECRET: ${{ secrets.MY_SECRET }}
41
How do you reference an output from a called workflow?
If the reusable workflow sets outputs: { foo: … }, then in the caller: ${{ jobs.call-other.outputs.foo }}.
42
What’s the default shell for run: on an Ubuntu runner?
Bash (/bin/bash -e {0}).
43
How do you override the shell in a run: step?
- run: echo "hello" shell: pwsh # PowerShell on Windows or cross‐platform
44
What does continue-on-error: true do for a step?
Allows the step to fail without failing the entire job (job status becomes “neutral” or “success with warnings”).
45
How do you set a custom timeout for a job?
timeout-minutes: 10 under the job definition (so the runner kills it after 10 minutes).
46
How do you retain artifacts (e.g., test reports) longer than the default 90 days?
Use retention-days: when uploading artifacts: - uses: actions/upload-artifact@v3 with: name: test-report path: report.xml retention-days: 30
47
How do you upload and then download build artifacts between jobs or workflows?
Upload: - uses: actions/upload-artifact@v3 with: name: my-artifact path: path/to/files/* Download: - uses: actions/download-artifact@v3 with: name: my-artifact path: ./restored-files
48
How can you debug a failing step?
Add ACTIONS_STEP_DEBUG: true as a secret to your repo → rerun the workflow to see verbose logs. Insert echo "::debug::message" in your run: commands.
49
What is the GITHUB_TOKEN, and why is it special?
An automatically generated token for each workflow run; used to authenticate API calls (checkout, creating PR comments, publishing releases) with least privilege to that repo.
50
Name two common security best practices for GitHub Actions.
Use least‐privileged permissions in permissions: to scope what GITHUB_TOKEN can do. Pin third‑party Actions to a specific commit SHA (e.g., actions/checkout@e3a92c8…) to prevent supply‑chain attacks.