Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a pagefile fix which for windows workflows #146

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ Any and all settings which affect the behavior of the generative plugin should b
- `githubWorkflowPublish` : `Seq[WorkflowStep]` – The steps which will be invoked to publish your project. This defaults to `[sbt +publish]`.
- `githubWorkflowPublishTargetBranches` : `Seq[RefPredicate]` – A list of branch predicates which will be applied to determine whether the `publish` job will run. Defaults to just `== main`. The supports all of the predicate types currently [allowed by GitHub Actions](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#functions). This exists because, while you usually want to run the `build` job on *every* branch, `publish` is obviously much more limited in applicability. If this list is empty, then the `publish` job will be omitted entirely from the workflow.
- `githubWorkflowPublishCond` : `Option[String]` – This is an optional added conditional check on the publish branch, which must be defined using [GitHub Actions expression syntax](https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#about-contexts-and-expressions), which will be conjoined to determine the `if:` predicate on the `publish` job. Defaults to `None`.

#### Windows related

- `githubWorkflowWindowsPagefileFix` : `Option[windows.PagefileFix]` - Due to the fact that Windows is more strict in how it treats pagefile size compared to *unix systems, certain windows related workflows (typically scala-native) can run out of memory without this fix. Defaults to `Some(windows.PagefileFix(2GB,8GB))`.
3 changes: 3 additions & 0 deletions src/main/scala/sbtghactions/GenerativeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ trait GenerativeKeys {
lazy val githubWorkflowEnv = settingKey[Map[String, String]](s"A map of static environment variable assignments global to the workflow (default: { GITHUB_TOKEN: $${{ secrets.GITHUB_TOKEN }} })")
lazy val githubWorkflowPermissions = settingKey[Option[Permissions]](s"Permissions to use for the global workflow (default: None)")
lazy val githubWorkflowAddedJobs = settingKey[Seq[WorkflowJob]]("A list of additional jobs to add to the CI workflow (default: [])")

// Windows related settings
lazy val githubWorkflowWindowsPagefileFix = settingKey[Option[windows.PagefileFix]]("If defined adds a workflow step that increases the pagefile size for Windows workflow's which can sometimes necessary in certain cases, i.e. when using scala-native (default: windows.PagefileFix(2GB,8GB))")
}

object GenerativeKeys extends GenerativeKeys
21 changes: 19 additions & 2 deletions src/main/scala/sbtghactions/GenerativePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,11 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}

githubWorkflowEnv := Map("GITHUB_TOKEN" -> s"$${{ secrets.GITHUB_TOKEN }}"),
githubWorkflowPermissions := None,
githubWorkflowAddedJobs := Seq())
githubWorkflowAddedJobs := Seq(),
githubWorkflowWindowsPagefileFix := Some(
windows.PagefileFix("2GB", "8GB")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

)
)

private lazy val internalTargetAggregation = settingKey[Seq[File]]("Aggregates target directories from all subprojects")

Expand Down Expand Up @@ -656,11 +660,24 @@ ${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}

githubWorkflowJobSetup := {
val autoCrlfOpt = if (githubWorkflowOSes.value.exists(_.contains("windows"))) {
val optionalPagefileFix = githubWorkflowWindowsPagefileFix.value.map(pageFileFix =>
WorkflowStep.Use(
name = Some("Configure pagefile for Windows"),
ref = UseRef.Public("al-cheb", "configure-pagefile-action", "v1.3"),
params = Map(
"minimum-size" -> s"${pageFileFix.minSize}",
"maximum-size" -> s"${pageFileFix.maxSize}"
),
cond = windowsGuard
)
).toList

List(
WorkflowStep.Run(
List("git config --global core.autocrlf false"),
name = Some("Ignore line ending differences in git"),
cond = windowsGuard))
cond = windowsGuard)
) ++ optionalPagefileFix
} else {
Nil
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/sbtghactions/windows/PagefileFix.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package sbtghactions.windows

case class PagefileFix(minSize: String, maxSize: String)