diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index fcd9049ad..0c5fc4a0e 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -5,6 +5,15 @@ on: schedule: - cron: '0 3 * * 1' # Every Monday at 3am UTC workflow_dispatch: # For manual triggering + inputs: + version_type: + description: 'Version type: minor / patch' + required: true + default: 'minor' + type: choice + options: + - 'minor' + - 'patch' env: JAVA_VERSION: '11' @@ -72,7 +81,12 @@ jobs: - name: Bump Effekt version using sbt id: set-version run: | - full_output=$(sbt 'bumpMinorVersion' -error) + if [ "${{ github.event.inputs.version_type }}" = "patch" ]; then + full_output=$(sbt 'bumpPatchVersion' -error) + else + full_output=$(sbt 'bumpMinorVersion' -error) + fi + new_version=$(echo "$full_output" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | tail -n 1) new_version=$(echo "$new_version" | xargs) if [[ ! $new_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then diff --git a/build.sbt b/build.sbt index a4dd03c09..e0ff124f8 100644 --- a/build.sbt +++ b/build.sbt @@ -13,6 +13,7 @@ lazy val assembleJS = taskKey[Unit]("Assemble the JS file in out/effekt.js") lazy val assembleBinary = taskKey[Unit]("Assembles the effekt binary in bin/effekt") lazy val generateDocumentation = taskKey[Unit]("Generates some documentation.") lazy val bumpMinorVersion = taskKey[Unit]("Bumps the minor version number (used in CI).") +lazy val bumpPatchVersion = taskKey[Unit]("Bumps the patch version number (used in CI).") lazy val noPublishSettings = Seq( publish := {}, @@ -161,6 +162,7 @@ lazy val effekt: CrossProject = crossProject(JSPlatform, JVMPlatform).in(file("e Process(s"${mvn.value} versions:set -DnewVersion=${effektVersion} -DgenerateBackupPoms=false").!! }, + // TODO: reduce duplication between `bumpMinorVersion' and 'bumpPatchVersion' bumpMinorVersion := { val versionPattern = """(\d+)\.(\d+)\.(\d+)""".r val newVersion = effektVersion match { @@ -181,6 +183,26 @@ lazy val effekt: CrossProject = crossProject(JSPlatform, JVMPlatform).in(file("e println(newVersion) }, + bumpPatchVersion := { + val versionPattern = """(\d+)\.(\d+)\.(\d+)""".r + val newVersion = effektVersion match { + case versionPattern(major, minor, patch) => + s"$major.$minor.${patch.toInt + 1}" + case _ => + sys.error(s"Invalid version format: $effektVersion") + } + + val versionFile = (ThisBuild / baseDirectory).value / "project" / "EffektVersion.scala" + IO.write(versionFile, + s"""// Don't change this file without changing the CI too! + |import sbt.* + |import sbt.Keys.* + |object EffektVersion { lazy val effektVersion = "$newVersion" } + |""".stripMargin) + + println(newVersion) + }, + generateDocumentation := TreeDocs.replacer.value, Compile / sourceGenerators += versionGenerator.taskValue, Compile / sourceGenerators += TreeDocs.generator.taskValue,