Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
WojciechMazur committed Jul 5, 2023
1 parent af685cc commit aaf3281
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
36 changes: 22 additions & 14 deletions .github/workflows/buildBisect.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Open CB: bisect"
run-name: ${{ inputs.build-name != '' && inputs.build-name || format('{0} - Scala {1} @ {2} / {3} {4}{5}', inputs.project-name, inputs.published-scala-version != '' && inputs.published-scala-version || 'snapshot', inputs.repository-url, inputs.repository-branch, inputs.extra-scalac-options != '' && format('extraScalacOptions={0} ', inputs.extra-scalac-options) || '', inputs.disabled-scalac-options != '' && format('disabledScalacOptions={0}', inputs.disabled-scalac-options) || '' ) }}
run-name: ${{ inputs.build-name != '' && inputs.build-name || format('Bisect {1}', inputs.project-name) }}

on:
workflow_dispatch:
Expand All @@ -11,9 +11,13 @@ on:
project-name:
type: string
description: "Name of a project to build using GitHub coordinates <org>/<repo> eg. VirtusLab/scala-cli"
project-targets:
type: string
description: "List of project targets to builds (comma deliomited)"
default: "*"
repository-url:
type: string
description: "GitHub repository URL for compiler to build, ignored when published-scala-version is defined"
description: "GitHub repository URL for compiler to build"
default: "lampepfl/dotty"
scala-version-start:
type: string
Expand All @@ -31,13 +35,19 @@ on:
type: string
description: "List of scalacOptions which should be filtered out when building projects."
default: ""

jobs:
run-bisect:
runs-on: ubuntu-22.04
continue-on-error: false
timeout-minutes: 60
steps:
- name: "Git Checkout"
uses: actions/checkout@v3
with:
path: opencb

- name: "Git Checkout compiler"
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository-url }}
Expand All @@ -54,15 +64,13 @@ jobs:
echo "java-version=$javaVersion" >> $GITHUB_ENV
echo "JavaVersion set to $javaVersion"
- name: "Build project"
uses: ./.github/actions/build-project
with:
project-name: ${{ inputs.project-name }}
extra-scalac-options: ${{ inputs.extra-scalac-options }}
disabled-scalac-options: ${{ inputs.disabled-scalac-options }}
scala-version: ${{ needs.setup-build.outputs.scala-version }}
maven-repo-url: https://scala3.westeurope.cloudapp.azure.com/maven2/bisect/
elastic-user: ${{ secrets.OPENCB_ELASTIC_USER }}
elastic-password: ${{ secrets.OPENCB_ELASTIC_PSWD }}
github-key: ${{ secrets.OPENCB_GITHUB_KEY }}
- name: "Bisect project"
shell: bash
run: |
${{ github.workspace }}/opencb/scripts/bisect.scala -- \
--releases ${{ inputs.scala-version-start}}..${{ inputs.scala-version-end}} \
--extra-scalac-options ${{ inputs.extra-scalac-options }} \
--disabled-scalac-options ${{ inputs.disabled-scalac-options }} \
--community-build-dir ${{ github.workspace }}/opencb \
--compiler-dir ${{ github.workspace }}/compiler \
${{ inputs.project-name }} ${{ inputs.project-targets }}
44 changes: 28 additions & 16 deletions scripts/bisect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ Look at the `usageMessage` below for more details.
*/




import sys.process._
import scala.io.Source
import java.io.File
import java.nio.file.attribute.PosixFilePermissions
import java.nio.charset.StandardCharsets
import java.nio.file.Files

// --extra-scalac-options ${{ inputs.extra-scalac-options }} \
// --disabled-scalac-options ${{ inputs.disabled-scalac-options }} \
// --community-build-dir ${{ github.workspace }}/opencb

val usageMessage = """
|Usage:
| > scala-cli project/scripts/bisect.scala -- [<bisect-options>] <projectName> <targets>*
Expand All @@ -23,17 +29,26 @@ val usageMessage = """
|* --dry-run
| Don't try to bisect - just make sure the validation command works correctly
|
|* --extra-scalac-options <options>
| Comma delimited of additional scalacOptions passed to project build
|
|* --disabled-scalac-options <options>
| Comma delimited of disabled scalacOptions passed to project build
|
|* --community-build-dir <path>
| Directory with community build project from which the project config would be resolved
|
|* --compiler-dir <path>
| Directory containing Scala compiler repository, required for commit-based bissect
|
|* --releases <releases-range>
| Bisect only releases from the given range (defaults to all releases).
| The range format is <first>...<last>, where both <first> and <last> are optional, e.g.
| The range format is <first>..<last>, where both <first> and <last> are optional, e.g.
| * 3.1.0-RC1-bin-20210827-427d313-NIGHTLY..3.2.1-RC1-bin-20220716-bb9c8ff-NIGHTLY
| * 3.2.1-RC1-bin-20220620-de3a82c-NIGHTLY..
| * ..3.3.0-RC1-bin-20221124-e25362d-NIGHTLY
| The ranges are treated as inclusive.
|
|* --bootstrapped
| Publish locally and test a bootstrapped compiler rather than a nonboostrapped one.
|
|* --should-fail
| Expect the validation command to fail rather that succeed. This can be used e.g. to find out when some illegal code started to compile.
|
Expand All @@ -60,17 +75,16 @@ val usageMessage = """
println(s"First bad release: ${firstBadRelease.version}")
println("\nFinished bisecting releases\n")

val commitBisect = CommitBisect(validationScript, shouldFail = scriptOptions.shouldFail, bootstrapped = scriptOptions.bootstrapped, lastGoodRelease.hash, firstBadRelease.hash)
val commitBisect = CommitBisect(validationScript, shouldFail = scriptOptions.shouldFail, lastGoodRelease.hash, firstBadRelease.hash)
commitBisect.bisect()


case class ScriptOptions(validationCommand: ValidationCommand, dryRun: Boolean, bootstrapped: Boolean, releasesRange: ReleasesRange, shouldFail: Boolean)
case class ScriptOptions(validationCommand: ValidationCommand, dryRun: Boolean, releasesRange: ReleasesRange, shouldFail: Boolean)
object ScriptOptions:
def fromArgs(args: Seq[String]) =
val defaultOptions = ScriptOptions(
validationCommand = null,
dryRun = false,
bootstrapped = false,
ReleasesRange(first = None, last = None),
shouldFail = false
)
Expand All @@ -80,17 +94,15 @@ object ScriptOptions:
println(s"parse: $args")
args match
case "--dry-run" :: argsRest => parseArgs(argsRest, options.copy(dryRun = true))
case "--bootstrapped" :: argsRest => parseArgs(argsRest, options.copy(bootstrapped = true))
case "--releases" :: argsRest =>
val range = ReleasesRange.tryParse(argsRest.head).get
parseArgs(argsRest.tail, options.copy(releasesRange = range))
case "--should-fail" :: argsRest => parseArgs(argsRest, options.copy(shouldFail = true))
case args =>
println(s"command: $args")
val command = ValidationCommand.fromArgs(args)
options.copy(validationCommand = command)

case class ValidationCommand(projectName: String, openCommunityBuildDir: File, targets: Seq[String]):
case class ValidationCommand(projectName: String, openCommunityBuildDir: File, targets: Seq[String]):
val remoteValidationScript: File = ValidationScript.buildProject(
projectName = projectName,
targets = Option.when(targets.nonEmpty)(targets.mkString(" ")),
Expand All @@ -104,7 +116,6 @@ case class ValidationCommand(projectName: String, openCommunityBuildDir: File, t

object ValidationCommand:
def fromArgs(args: Seq[String]) =
println(args)
args match
case Seq(projectName, openCBDir, targets*) => ValidationCommand(projectName, new File(openCBDir), targets)

Expand All @@ -119,7 +130,7 @@ object ValidationScript:
|#!/usr/bin/env bash
|set -e
|
|scalaVersion="$$1" # e.g. 3.0.0-RC3
|scalaVersion="$$1" # e.g. 3.3.3
|
|DefaultConfig='{"memoryRequestMb":4096}'
|ConfigFile="/opencb/.github/workflows/buildConfig.json"
Expand Down Expand Up @@ -217,7 +228,7 @@ case class ReleasesRange(first: Option[String], last: Option[String]):
object ReleasesRange:
def all = ReleasesRange(None, None)
def tryParse(range: String): Option[ReleasesRange] = range match
case s"${first}...${last}" => Some(ReleasesRange(
case s"${first}..${last}" => Some(ReleasesRange(
Some(first).filter(_.nonEmpty),
Some(last).filter(_.nonEmpty)
))
Expand Down Expand Up @@ -287,11 +298,12 @@ class ReleaseBisect(validationScript: File, shouldFail: Boolean, allReleases: Ve
isGood
})

class CommitBisect(validationScript: File, shouldFail: Boolean, bootstrapped: Boolean, lastGoodHash: String, fistBadHash: String):
class CommitBisect(validationScript: File, shouldFail: Boolean, lastGoodHash: String, fistBadHash: String):
def bisect(): Unit =
println(s"Starting bisecting commits $lastGoodHash..$fistBadHash\n")
val scala3CompilerProject = if bootstrapped then "scala3-compiler-bootstrapped" else "scala3-compiler"
val scala3Project = if bootstrapped then "scala3-bootstrapped" else "scala3"
// Always bootstrapped
val scala3CompilerProject = "scala3-compiler-bootstrapped"
val scala3Project = "scala3-bootstrapped"
val mavenRepo = "https://scala3.westeurope.cloudapp.azure.com/maven2/bisect/"
val validationCommandStatusModifier = if shouldFail then "! " else "" // invert the process status if failure was expected
val bisectRunScript = raw"""
Expand Down

0 comments on commit aaf3281

Please sign in to comment.