Skip to main content
Version: 2.x

ZIO SBT CI

ZioSbtCiPlugin generates the GitHub Actions workflows of a project from its build.sbt, so continuous integration (CI) is configured in one place. The default workflow builds, tests, lints and publishes the project, and every part of it can be changed with sbt settings or replaced by custom jobs. The model of workflows, jobs and steps lives in ZIO SBT GitHub Actions.

To install the plugin, add addSbtPlugin("dev.zio" % "zio-sbt-ci" % "0.8.13") to project/plugins.sbt, as described in Installation. Using SNAPSHOT versions of the plugin also needs resolvers ++= Resolver.sonatypeOssRepos("public").

The plugin declares trigger = allRequirements, so having it on the classpath is enough, and enablePlugins(ZioSbtCiPlugin) is not strictly required. Its settings are defined at ThisBuild level, so set them as ThisBuild / ciSomething := ..., or inside inThisBuild(...).

To use the plugin, install the ZIO Assistant GitHub App on the repository.

Generated Filesโ€‹

ciGenerateGithubWorkflow writes these files. Commit them and never edit them by hand. See Keep the Generated Workflow in Sync to check that they match the build.

FileGenerated when
.github/workflows/ci.ymlAlways. The file name is ciWorkflowTitle lower-cased, with non-alphanumeric characters turned into -
.github/workflows/auto-approve.ymlAlways
.github/workflows/auto-merge.ymlAlways
.github/workflows/deploy-preview.ymlciEnableDeployPreview is true
.github/workflows/release-drafter.ymlciEnableReleaseDrafter is true (the default). Scaffolds .github/release-drafter.yml once
.github/workflows/scala-steward.ymlciEnableScalaSteward is true (the default). Scaffolds .scala-steward.conf once when ciScalaStewardConfig renders content
.github/dependabot.ymlciEnableDependabot is true (the default)
.github/workflows/regenerate-workflows.ymlciEnableRegenerateWorkflows is true (the default)

Default Jobsโ€‹

The generated ci.yml contains these jobs:

JobWhat it does
buildCompiles everything, publishes locally, and builds the website. With ciCheckScaladocExamples, also compiles the Scaladoc examples
lintChecks the generated workflow is up to date, then runs sbt lint
testRuns the test suite across the target Java versions
update-readmeRegenerates README.md from docs/index.md and opens a PR
ciAggregate gate: succeeds only if the jobs above did. Point branch protection at this one
releaseRuns sbt ci-release on a published release or a manual run, and on pushes to the default branch for SNAPSHOTs
release-docsPublishes the docs to npm after a successful release, or on a manual run with docs-only set to true
notify-docs-releaseDispatches an update-docs event to zio/zio with the docs package name and version, so the ZIO website picks up the new docs

notify-docs-release takes the docs version from the release tag, or from the newest v tag on a manual docs-only run, and waits for up to five minutes until npm lists exactly that version. It fails if the version never appears. With HashVersioning as ciDocsVersioningScheme, it still reads the latest version with npm view <package> version.

The default workflow runs on workflow_dispatch, published releases, pushes (to ciEnabledBranches when set, otherwise every branch) and pull requests that do not target gh-pages.

Concurrency of the Default Workflowโ€‹

By default ciConcurrency is one run per workflow and ref, and an in-progress run is cancelled when a newer run starts in the same group. The group is ${{ github.workflow }}-${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && github.run_id || github.ref }}. On the default branch the group ends with the run id, so every run is kept. On any other ref, including a tag such as refs/tags/v1.9.2, the group ends with the ref.

A release event and the push of its tag have the same ref, so they share one group, and the run that starts later cancels the earlier one. To change this, set ciConcurrency as described in Control CI Concurrency.

Settingsโ€‹

All settings are ThisBuild-scoped.

Workflow-Levelโ€‹

SettingTypeDefaultDescription
ciWorkflowTitleString"CI"Workflow name. The file name is its lower-cased form with each run of non-alphanumeric characters replaced by - (ci.yml for CI). Named this way to avoid colliding with zio-sbt-website's ciWorkflowName, which sets the README badge
ciEnabledBranchesSeq[String]Seq.emptyBranches the workflow runs on. Empty means every branch
ciWorkflowEnvMap[String, String]derived from ciJvmOptions/ciNodeOptionsWorkflow-level environment. Assigning replaces the derived map, which is how a build opts out of JDK_JAVA_OPTIONS
ciJvmOptionsSeq[String]Seq.emptyAppended to JDK_JAVA_OPTIONS
ciNodeOptionsSeq[String]Seq.emptySets NODE_OPTIONS when non-empty
ciConcurrencyOption[Concurrency]one run per ref, cancelling in progress, except that every run on the default branch is keptConcurrency group, or None to omit the block. See Concurrency of the Default Workflow
ciWorkflowPermissionsOption[Map[String, String]]Some(id-token: write, contents: read)Workflow-level permissions. None omits the block, so the workflow runs with the repository's default token permissions; Some(Map.empty) instead renders permissions: {}, which grants nothing
ciSwapSizeGBInt0Adds a swap-space step to every job when greater than zero
ciBackgroundJobsSeq[String]Seq.emptyCommands prefixed to each run, for daemons a job needs
ciCheckScaladocExamplesBooleanfalseAdds a "Check Scaladoc examples" step to build that runs sbt +scaladocCheck. Needs the ZIO SBT Scaladoc plugin
ciEnableDeployPreviewBooleanfalseAdds website-artifact upload steps to build and generates deploy-preview.yml. Requires NETLIFY_AUTH_TOKEN/NETLIFY_SITE_ID secrets
ciDeployPreviewModeDeployPreviewModeDeployPreviewMode.AutomaticOnly used with ciEnableDeployPreview. Automatic deploys every successful pull-request CI run; OnDemand posts a "Deploy preview" checkbox comment and deploys only when it is ticked
ciEnableReleaseDrafterBooleantrueGenerates release-drafter.yml and scaffolds .github/release-drafter.yml (once). Overwrites a hand-written release-drafter.yml when on; when off, only deletes a copy it generated itself
ciReleaseDrafterCategoriesSeq[ReleaseDrafterCategory]Features/Bug Fixes/Maintenance/Dependency UpdatesCategories written into the scaffolded config on first generation only
ciReleaseDrafterVersionResolverOption[ReleaseDrafterVersionResolver]NoneOptional version-resolver block for the scaffolded config
ciReleaseDrafterAutolabelerSeq[ReleaseDrafterAutolabelerRule]Seq.emptyOptional autolabeler rules for the scaffolded config
ciReleaseDrafterExcludeLabelsSeq[String]Seq("skip-changelog")exclude-labels for the scaffolded config
ciReleaseDrafterBranchOption[Branch]NoneBranch release-drafter.yml's push trigger runs on. Falls back to the first of ciEnabledBranches, then "main"
ciEnableScalaStewardBooleantrueGenerates scala-steward.yml and scaffolds .scala-steward.conf (once, only if non-empty). Overwrites a hand-written scala-steward.yml when on; when off, only deletes a copy it generated itself
ciScalaStewardScheduleString"0 0 * * *"Cron schedule for scala-steward.yml's schedule trigger
ciScalaStewardTimeoutMinutesInt45timeout-minutes for the scala-steward job
ciScalaStewardPermissionsMap[String, String]contents: readPermissions block for scala-steward.yml; the action authenticates via the GitHub App's installation token, not GITHUB_TOKEN, so no write scope is needed by default
ciScalaStewardWorkflowEnvMap[String, String]Map.emptyExtra env vars for the scala-steward job
ciScalaStewardConfigScalaStewardConfigScalaStewardConfig()Settings scaffolded into .scala-steward.conf on first non-empty render
ciEnableDependabotBooleantrueGenerates .github/dependabot.yml. Overwrites a hand-written one when on; when off, only deletes a copy it generated itself
ciEnableRegenerateWorkflowsBooleantrueGenerates regenerate-workflows.yml, which re-runs ciGenerateGithubWorkflow on bot PRs and pushes the result to the PR branch. When off, only deletes a copy it generated itself
ciDependabotConfigDependabotConfigone weekly github-actions update at /Content of the generated dependabot.yml
ciDependabotExcludeGeneratedBooleantrueAdds the generated workflows to the exclude-paths of each github-actions update, since their action versions come from the plugin

Test Matrixโ€‹

SettingTypeDefaultDescription
ciTargetJavaVersionsSeq[String]Seq("17", "21", "25")Java versions in the test matrix
ciDefaultJavaVersionString"17"Java version for the non-matrix jobs
ciTargetScalaVersionsMap[String, Seq[String]]Map.emptyModule to Scala versions. Empty runs a plain sbt +test
ciTargetMinJavaVersionsMap[String, String]Map.emptyModule to minimum Java version, gating modules per matrix entry
ciGroupSimilarTestsBooleanfalseGroups by Java and Scala version instead of one entry per module
ciMatrixMaxParallelOption[Int]Nonestrategy.max-parallel

Jobs and Stepsโ€‹

SettingTypeDefaultDescription
ciBuildJobsSeq[Job]one build jobReplaces or extends the build jobs
ciLintJobsSeq[Job]one lint job
ciTestJobsSeq[Job]one test job
ciUpdateReadmeJobsSeq[Job]one update-readme jobSet to Seq.empty if the README is maintained by hand
ciReportSuccessfulJobsSeq[Job]the aggregate ci jobSet to Seq.empty for a workflow made up entirely of custom jobs that does not want one
ciReleaseJobsSeq[Job]one release job
ciPostReleaseJobsSeq[Job]release-docs, notify-docs-release
ciPullRequestApprovalJobsSeq[String]the ids of ciLintJobs, ciTestJobs and ciBuildJobsJob ids the aggregate ci job waits on. Follows the jobs those three settings produce, so renaming or adding one is picked up without touching this
ciReleaseApprovalJobsSeq[String]Seq("ci")Job ids the release waits on
ciCheckArtifactsCompilationStepsSeq[Step]sbt +Test/compile
ciCheckArtifactsBuildStepsSeq[Step]sbt +publishLocal
ciCheckWebsiteBuildProcessSeq[Step]sbt docs/clean; sbt docs/buildWebsite, then sbt docs/checkDocsOnFreshWebsiteSet to Seq.empty in a build with no docs project
ciCheckGithubWorkflowStepsSeq[Step]sbt ciCheckGithubWorkflow

Release and Docsโ€‹

SettingTypeDefaultDescription
ciPublishSnapshotsBooleantrueAlso publish SNAPSHOTs on pushes to the default branch
ciUpdateReadmeConditionOption[Condition]NoneWhen to run the README job. Defaults to published releases
ciDocsVersioningSchemeDocsVersioningSemanticVersioningSemanticVersioning or HashVersioning
ciDependencyUpdateBotsSeq[DependencyBot]Dependabot, Renovate, ScalaSteward("zio-scala-steward"), Custom("zio-assistant[bot]")Bots whose PRs are auto-approved and auto-merged

Tasksโ€‹

TaskDescription
ciGenerateGithubWorkflowWrites ci.yml, auto-approve.yml and auto-merge.yml, plus deploy-preview.yml when ciEnableDeployPreview is true and release-drafter.yml (and scaffolds .github/release-drafter.yml once) when ciEnableReleaseDrafter is true, and scala-steward.yml (and scaffolds .scala-steward.conf once, when ciScalaStewardConfig renders non-empty content) when ciEnableScalaSteward is true, .github/dependabot.yml when ciEnableDependabot is true, and regenerate-workflows.yml when ciEnableRegenerateWorkflows is true
ciCheckGithubWorkflowRegenerates and fails if the committed files are stale
ciGenerateAutoApproveWorkflowWrites auto-approve.yml only
ciGenerateAutoMergeWorkflowWrites auto-merge.yml only

Types Used in Settingsโ€‹

The types that the settings above take, such as Job, Step, Concurrency, DependencyBot and DeployPreviewMode, are described in ZIO SBT GitHub Actions. They live in zio.sbt.githubactions and are not exported through autoImport, so import them explicitly. The reusable steps live in zio.sbt.ZioSbtCiPlugin.

Helper Methodsโ€‹

targetScalaVersionsFor(projects*) takes a list of projects and returns a Map from each project id to its crossScalaVersions. It is meant for ciTargetScalaVersions, as shown in Test Against Several Scala and Java Versions.

ZIO Chat

Hi there! ๐Ÿ‘‹ I'm ZIO Chat, your friendly neighborhood ZIO expert. I'm here to help you navigate the world of ZIO. Whether you're a seasoned pro or just starting out, fire away with your ZIO questions. I will hit you back with the best insights I've got. Let's dive into the world of ZIO together!