liveBook · Manning

GitHub Actions

As explained in Automating API Delivery

GitHub Actions is a GitHub service for automating software development workflows, including continuous integration and continuous delivery.

GitHub Actions automates repository workflows and provides CI/CD capabilities. For an API project, a pull request can trigger checks on source code and API artifacts before a merge. Automated minimum design review criteria can support, but do not replace, governance-team approval. section 8.4 section 8.3

Define a workflow in a YAML file under `.github/workflows`. Repository events, a schedule, or a manual request can trigger it; triggers can target particular branches. A runner executes its jobs. Each job contains sequential steps, either shell commands or reusable actions. Jobs run in parallel by default unless dependencies are configured. GitHub provides Ubuntu, Windows, and macOS runners; self-hosted runners are also possible. section 8.4

Listing 8.1 The PR build workflow
name: PR build workflow
on: 
  pull_request:
    branches: [main]      #1
  workflow_dispatch:            #2
jobs:
  pr-code-build:               #3
    name: Build and test source code
    runs-on: ubuntu-latest             #4
    steps:
      - name: Checkout out pr branch
        uses: actions/checkout@v3      #5
      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: maven
      - name: Compile
        run: |
          cd chapter8
          mvn --batch-mode clean compile      #6
      - name: Unit test
        run: |
          cd chapter8
          mvn --batch-mode test

The PR build workflow runs for pull requests against `main` or by manual dispatch. On an Ubuntu runner, it checks out code, sets up JDK 17, then compiles and tests the Java project with Maven. section 8.4

To add source-stage API governance, extend the existing workflow with a separate minimum-review-criteria job. Its planned checks are:

Listing 8.3 Workflow job for minimum API review criteria
…  
  pr-api-minimum-review-criteria:
    name: Minimum API design review criteria
    runs-on: ubuntu-latest
    steps:
      - name: Checkout out pr branch
        uses: actions/checkout@v3
        with:
          path: pr-branch
      - name: Check PR title
        run: ./pr-branch/chapter8/pr-title.sh 
 "'${{ github.event.pull_request.title }}'"

The example job checks out the pull-request branch into `pr-branch`, then passes `${{ github.event.pull_request.title }}` to a shell script. It is appended to, not substituted for, the existing build job. section 8.5.1

Test a failing gate

Make `pr-title.sh` executable and have it exit with status 1 when the title lacks a `DEV-` reference followed by four digits. Open a pull request without that reference to see the job fail. Change its title to begin with `[DEV-1234]`, then update the pull request to retrigger the job and confirm it passes. The script checks the title’s pattern; validating that the ticket exists in Jira would require an additional REST API check. section 8.5.1

GitHub Actions can also run later pipeline work that generates and publishes API artifacts. API gateway configuration deployment and implemented-API conformance testing belong to the broader deployment pipeline; they are not performed by the pull-request title job. section 9.0 section 8.5.1

How Automating API Delivery covers it

How deep it goes
Defines triggers, runners, jobs, and steps, then implements a PR-title check; the other proposed review checks are not implemented here.
Examples
Uses a Java PR-build YAML workflow and a shell-script ticket-reference check tested with failing and passing pull-request titles.
What it assumes
Introduces GitHub Actions workflow components before extending a sample Java project's existing PR build; Docker and Kubernetes are not essential to the later pipeline work.
What you can do after
Operate/configure it to run a pull-request title gate alongside an existing compile-and-test job.
How it connects
Connects pull requests, CI/CD, API linting, breaking-change detection, prose linting, and API artifact publishing.

Also explained in

Compare how 10 books explain GitHub Actions →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Automating API Delivery. The section links point to the parts of the book it draws on.