From 9fa9502fec5554a3efdf16ffd0f7f4bcbc50fae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Thu, 7 Nov 2024 14:30:24 +0100 Subject: [PATCH 1/2] Add a autorelease workflow for patches (x.y.{z+1}) --- .github/workflows/autorelease.yml | 16 +++++++++++++++- build.sbt | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index fcd9049ad..e529c5d1a 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 'bumpMinorVersion' -error) + else + full_output=$(sbt 'bumpPatchVersion' -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, From 99eacd57a76f0a3b66863120eafbd8be28a8e0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Bene=C5=A1?= Date: Thu, 7 Nov 2024 14:40:47 +0100 Subject: [PATCH 2/2] Fix a typo --- .github/workflows/autorelease.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index e529c5d1a..0c5fc4a0e 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -82,9 +82,9 @@ jobs: id: set-version run: | if [ "${{ github.event.inputs.version_type }}" = "patch" ]; then - full_output=$(sbt 'bumpMinorVersion' -error) - else 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)