Testing and CI/CD Deployment

GitHub Actions: Workflows and Secrets

Learning Outcome

4

Apply login, tag, push, and pull to ship an image.

3

Recognize why deploying latest is risky.

2

Identify registry, namespace, repository, tag, and digest.

1

Understand what a container registry stores and why.

5

Connect registries to distributing LLM serving images.

Imagine a housing society where everything runs smoothly because there is a proper rulebook. The security guards and staff members don't depend on memory; they follow written instructions to complete their daily tasks.

When a delivery arrives, the guard checks ID and calls the flat.

On the 1st of every month, the maintenance bill goes out.

Every duty in the society has a specific set of steps. The guard or staff member simply follows those instructions to complete the assigned work.

Think About It

Imagine that every time a developer raises a pull request, they have to remember a series of tasks: run the tests, build the Docker image, and push it to the registry.

This is where GitHub Actions comes in!

Instead of depending on developers to remember and perform every task manually, we can write all the instructions in a workflow file.

Now, what happens if the developer forgets one of these steps? Or what if a different developer takes over the project?

  • Things can easily go wrong because the entire process depends on someone's memory.
  • GitHub's built-in CI/CD and automation service.

What is GitHub Actions?

  • Pipelines are YAML files in the repo's .github/workflows folder.
  • The pipeline is versioned and reviewed just like the code.
  • Runs tests on every PR, builds the image, pushes to GHCR, and triggers deployment from one file.

The Building Blocks

An automated process defined in a YAML file (e.g., ci.yml).

Workflow

The Building Blocks

What starts the workflow, such as:

  • push

  • pull_request

  • schedule (cron)

  • workflow_dispatch (manual button)

Event (Trigger)

The Building Blocks

  • A set of steps that run in parallel or sequentially.

  • Each job does a specific task.

Job

The Building Blocks

  • The machine where the job runs.

  • Examples: ubuntu-latest, self-hosted runner.

Runner

The Building Blocks

  • Individual commands or actions that run inside a job.

  • Examples: checkout, build, test.

Steps

A Complete Pipeline for the Prediction API

A Complete Pipeline for the Prediction API

A Complete Pipeline for the Prediction API

A Complete Pipeline for the Prediction API

format this code :
on:
  pull_request:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pytest -v
  build-and-push:
    needs: test
    


Create

  • Settings → Secrets and variables → Actions.

  • Once saved, the value can't be viewed, only replaced.

Use

${{secrets.DOCKERHUB_TOKEN }} as an action input or step environment variable.

Masked

Printed values appear as *** in logs.

Level

  • Repository, organisation, or environment.

Secrets in GitHub Actions


GITHUB_TOKEN, Permissions, and Variables

What is GITHUB_TOKEN?


GITHUB_TOKEN, Permissions, and Variables

What is GITHUB_TOKEN?

  • GitHub automatically generates a temporary access token for every workflow run.

  • It expires automatically when the workflow run finishes.

  • It allows workflows to interact with GitHub services without storing a personal password.

What Can It Do?

Publish Images

Push container images to GHCR for the same repository.

PR Interaction

Perform permitted actions such as adding comments to pull requests.

No Stored Password

Authentication is handled using the automatically generated token.

Least Privilege Principle

Give the token only the permissions required to complete its task.

Use the permissions block to control what the workflow can access.

What Can It Do?

Publish Images

Push container images to GHCR for the same repository.

PR Interaction

Perform permitted actions such as adding comments to pull requests.

No Stored Password

Authentication is handled using the automatically generated token.

Least Privilege Principle

Give the token only the permissions required to complete its task.

Use the permissions block to control what the workflow can access.

GitHub Variables

Store non-sensitive configuration values such as image names, Python versions, and environment names.

Access them using ${{ vars.VARIABLE_NAME }}.

Unlike secrets, variables are not intended for sensitive information and can be visible in plain text.

Code Example

permissions:
  contents: read
  packages: write

Allows the workflow to read repository contents.

Allows the workflow to publish packages to GHCR.

GitHub Variables

Store non-sensitive configuration values such as image names, Python versions, and environment names.

Access them using ${{ vars.VARIABLE_NAME }}.

Unlike secrets, variables are not intended for sensitive information and can be visible in plain text.

Code Example

permissions:
  contents: read
  packages: write

Allows the workflow to read repository contents.

Allows the workflow to publish packages to GHCR.

Scheduling and Hardening Workflows

run: vs uses:

Aspectrun:uses:
What it doesRuns shell commands on the runnerRuns a reusable action
Examplerun: pytest -vuses: actions/checkout@v4
Who writes the logicYou, in the workflowThe action's author, on the Marketplace
InputsEnv variables and argumentsNamed inputs under with:
Main riskTypos, missing setupTrusting third-party code; pin versions
AnalogyGuard following a written stepHiring a certified service for the job

Summary

4

Secrets: ${{ secrets.NAME }}, masked as ***.

3

run: for commands; uses: for actions.

2

1

5

Keep GITHUB_TOKEN permissions minimal.

Event → workflow → jobs → runners → steps.

Workflows live as YAML in the repo.

Quiz

In a workflow, the build-and-push job starts even when the test job fails. What's missing from build-and-push?

A. runs-on: ubuntu-latest

B. permissions: packages: write

C.  needs: test

D. uses: actions/checkout@v4

In a workflow, the build-and-push job starts even when the test job fails. What's missing from build-and-push?

A. runs-on: ubuntu-latest

B. permissions: packages: write

C.  needs: test

D. uses: actions/checkout@v4

Quiz-Answer

GitHub Actions: Workflows and Secrets

By Content ITV

GitHub Actions: Workflows and Secrets

  • 124