Add CI for Scala projects with GitHub Actions
Table of Contents
- Introduction
- Setting Up the GitHub Actions Workflow
- Running Tests and Building the Project
1. Introduction
GitHub Actions is a powerful tool for automating workflows, including Continuous Integration (CI) for Scala projects. This guide will walk you through setting up a GitHub Actions workflow to ensure your Scala code is tested and built automatically whenever you push changes to your repository.
2. Setting Up the GitHub Actions Workflow
According to Github on Dec 2024, they dropped support for sbt in ubuntu-latest runners, so we will use sbt/setup-sbt@v1 to run our scala tests
name: Scala CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: 'sbt'
- uses: sbt/setup-sbt@v1
- name: Run tests
shell: bash
run: sbt -v +test
- Running Tests and Building the Project
This workflow is triggered on pushes and pull requests to the main
branch. It checks out the code, sets up JDK 21, and uses sbt/setup-sbt@v1
to ensure that SBT is available in the environment. Finally, it runs the tests using sbt -v +test
.