GitHub Actions
GitHub Actions is the default CI for many Spring Boot teams: workflows as YAML next to the TechLearningPRO Orders repo, marketplace actions for Java setup, caching, and registry…
Introduction
GitHub Actions is the default CI for many Spring Boot teams: workflows as YAML next to the TechLearningPRO Orders repo, marketplace actions for Java setup, caching, and registry login.
A solid Boot 3 workflow checks out code, sets up Temurin 21 with Maven cache, runs ./mvnw verify, then on main builds and publishes an image. Prefer OIDC for cloud auth over long-lived keys stored as repository secrets.
Keep workflows small, pin action versions, and separate PR verification from release deploy jobs.
This lesson implements Orders CI on GitHub Actions.
Purpose of this lesson
Author a GitHub Actions workflow that tests and publishes Boot 3 Orders images on Java 21.
Understanding the topic
Workflows are event-driven pipelines living in .github/workflows.
- Triggers: push, pull_request, workflow_dispatch.
- Jobs/steps: runners execute sequential steps.
- Cache: Maven/Gradle caches save minutes per build.
- Secrets: repository/environment secrets — never hard-code.
- OIDC: federate to cloud IAM without static keys when possible.
Step-by-step explanation
- Add
.github/workflows/ci.ymlwith Java 21 Temurin setup. - Run
./mvnw -B verifyon every PR. - On main, build-image and push to GHCR using the job token.
- Add an environment protection rule for production deploy jobs.
Informative example
Orders CI workflow (test + publish).
# .github/workflows/ci.ymlname: CIon:push:branches: [main]pull_request:jobs:build:runs-on: ubuntu-latestpermissions:contents: readpackages: writesteps:- uses: actions/checkout@v4- uses: actions/setup-java@v4with:distribution: temurinjava-version: "21"cache: maven- name: Testrun: ./mvnw -B verify- name: Login GHCRif: github.ref == 'refs/heads/main'uses: docker/login-action@v3with:registry: ghcr.iousername: ${{ github.actor }}password: ${{ secrets.GITHUB_TOKEN }}- name: Publish imageif: github.ref == 'refs/heads/main'run: >./mvnw -B spring-boot:build-image-Dspring-boot.build-image.imageName=ghcr.io/${{ github.repository }}/orders:${{ github.sha }}-Dspring-boot.build-image.publish=true
Real-world use
TechLearningPRO's first Actions workflow downloaded the internet on every run. Enabling cache: maven and pinning action SHAs cut PR feedback from 12 minutes to under 5 — reviewers actually waited for green checks instead of merging blind.
Security implications
Workflow permissions are a blast radius control.
- Set least
permissions:at job level. - Prefer
secrets.GITHUB_TOKENover personal PATs for GHCR. - Never commit cloud access keys — use OIDC or encrypted secrets stores.
Best practices
- Pin actions to full commit SHAs for high-security repos.
- Use environment approval gates for prod deploy workflows.
- Cache dependencies; fail fast on verify before image build.
Common mistakes
- Unpinned
actions/checkout@mainfloating tags. - Storing long-lived cloud access keys when OIDC is available.
- Printing env dumps that include secret values.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1BeginnerQuestionWhere do GitHub Actions workflows live?+
Answer
2BeginnerQuestionWhy cache Maven in setup-java?+
Answer
3IntermediateQuestionWhy prefer OIDC over static cloud keys?+
Answer
Hands-on exercise
Lab. Add the workflow above to Orders. Open a PR that breaks a unit test and confirm CI fails. Merge a fix to main and confirm an image tag matching the commit SHA appears in GHCR.
Summary
GitHub Actions automates TechLearningPRO Orders CI. Next: see the same ideas expressed in Jenkins for enterprise shops.