Git & GitHub Interview Question #100

How do you design a basic pull-request CI workflow on GitHub?

GitHub Collaboration, Repository Rules, Issues, Releases & Actions CI/CD Mid-Level Intermediate

Quick Interview Answer

A basic pull-request CI workflow should run automatically for relevant pull requests, check out the exact proposed code, configure the required toolchain, restore dependencies, build the project, and execute automated tests.

Detailed Explanation

A basic pull-request CI workflow should run automatically for relevant pull requests, check out the exact proposed code, configure the required toolchain, restore dependencies, build the project, and execute automated tests.

For a .NET repository, the workflow should use the project's supported SDK version and fail when restore, build, or tests fail. The resulting check can then be required by branch rules before merge. Additional projects may add linting, security analysis, coverage, or integration tests.

Code Example

name: Pull Request CI

on:
  pull_request:
    branches: [ main ]

jobs:
  validate:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "8.0.x"

      - run: dotnet restore
      - run: dotnet build --no-restore
      - run: dotnet test --no-build