From bc97a11d7aa119a9f34e7b6840dd959017d2f162 Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Thu, 30 Jan 2025 22:04:18 +0100 Subject: [PATCH 1/2] ci: add workflow for making branch runnable --- .github/workflows/make-branch-runnable.yaml | 66 +++++++++ .github/workflows/release.main.kts | 148 ++++++++++++-------- .github/workflows/release.yaml | 2 +- 3 files changed, 160 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/make-branch-runnable.yaml diff --git a/.github/workflows/make-branch-runnable.yaml b/.github/workflows/make-branch-runnable.yaml new file mode 100644 index 00000000..b09082d6 --- /dev/null +++ b/.github/workflows/make-branch-runnable.yaml @@ -0,0 +1,66 @@ +# This file was generated using Kotlin DSL (.github/workflows/release.main.kts). +# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file. +# Generated with https://github.com/typesafegithub/github-workflows-kt + +name: 'Make branch runnable' +on: + push: {} +jobs: + check_yaml_consistency: + name: 'Check YAML consistency' + runs-on: 'ubuntu-latest' + steps: + - id: 'step-0' + name: 'Check out' + uses: 'actions/checkout@v4' + - id: 'step-1' + name: 'Execute script' + run: 'rm ''.github/workflows/make-branch-runnable.yaml'' && ''.github/workflows/release.main.kts''' + - id: 'step-2' + name: 'Consistency check' + run: 'git diff --exit-code ''.github/workflows/make-branch-runnable.yaml''' + make-branch-runnable: + runs-on: 'ubuntu-latest' + needs: + - 'check_yaml_consistency' + steps: + - id: 'step-0' + name: 'Checkout github-actions-typing' + uses: 'actions/checkout@v4' + with: + path: 'github-actions-typing' + - id: 'step-1' + name: 'Checkout github-actions-typing-catalog' + uses: 'actions/checkout@v4' + with: + repository: 'typesafegithub/github-actions-typing-catalog' + path: 'github-actions-typing-catalog' + - id: 'step-2' + uses: 'gradle/actions/setup-gradle@v4' + - id: 'step-3' + working-directory: 'github-actions-typing' + run: './gradlew build' + - id: 'step-4' + name: 'Regenerate the contents of dist directory' + working-directory: 'github-actions-typing' + run: |- + set -euxo pipefail + + rm -rf dist + unzip -qq build/distributions/github-actions-typing.zip -d dist + - id: 'step-5' + name: 'Configure git' + working-directory: 'github-actions-typing' + run: |- + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + - id: 'step-6' + name: 'Commit changes' + working-directory: 'github-actions-typing' + run: |- + git add . + git commit -m "Update dist" + - id: 'step-7' + name: 'Push commit' + working-directory: 'github-actions-typing' + run: 'git push' diff --git a/.github/workflows/release.main.kts b/.github/workflows/release.main.kts index da4f5ef9..30e80943 100755 --- a/.github/workflows/release.main.kts +++ b/.github/workflows/release.main.kts @@ -12,7 +12,9 @@ import io.github.typesafegithub.workflows.actions.actions.Checkout import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep import io.github.typesafegithub.workflows.domain.RunnerType +import io.github.typesafegithub.workflows.domain.triggers.Push import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch +import io.github.typesafegithub.workflows.dsl.JobBuilder import io.github.typesafegithub.workflows.dsl.expressions.expr import io.github.typesafegithub.workflows.dsl.workflow import kotlinx.serialization.json.Json @@ -39,62 +41,8 @@ workflow( id = "release", runsOn = RunnerType.UbuntuLatest, ) { - uses( - name = "Checkout github-actions-typing", - action = Checkout( - path = "github-actions-typing" - ) - ) - uses( - name = "Checkout github-actions-typing-catalog", - action = Checkout( - repository = "typesafegithub/github-actions-typing-catalog", - path = "github-actions-typing-catalog" - ) - ) - uses(action = ActionsSetupGradle()) - run( - workingDirectory = "github-actions-typing", - command = "./gradlew build" - ) - - run( - name = "Regenerate the contents of dist directory", - workingDirectory = "github-actions-typing", - command = """ - set -euxo pipefail - - rm -rf dist - unzip -qq build/distributions/github-actions-typing.zip -d dist - """.trimIndent() - ) - - run( - name = "Configure git", - workingDirectory = "github-actions-typing", - command = """ - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git config user.name "github-actions[bot]" - """.trimIndent() - ) - val tempBranchName = "temp-branch-for-release" - - run( - name = "Commit changes", - workingDirectory = "github-actions-typing", - command = """ - git checkout -b $tempBranchName - git add . - git commit -m "Update dist" - """.trimIndent() - ) - - run( - name = "Push commit", - workingDirectory = "github-actions-typing", - command = "git push --set-upstream origin $tempBranchName", - ) + buildAndCommitDist(branchName = tempBranchName) val versionExpr = expr { "github.event.inputs.version" } @@ -142,3 +90,93 @@ workflow( ) } } + +workflow( + name = "Make branch runnable", + on = listOf( + Push(), + ), + sourceFile = __FILE__, + targetFileName = "make-branch-runnable.yaml", +) { + job( + id = "make-branch-runnable", + runsOn = RunnerType.UbuntuLatest, + ) { + buildAndCommitDist() + } +} + +private fun JobBuilder<*>.buildAndCommitDist(branchName: String? = null) { + uses( + name = "Checkout github-actions-typing", + action = Checkout( + path = "github-actions-typing" + ) + ) + uses( + name = "Checkout github-actions-typing-catalog", + action = Checkout( + repository = "typesafegithub/github-actions-typing-catalog", + path = "github-actions-typing-catalog" + ) + ) + uses(action = ActionsSetupGradle()) + run( + workingDirectory = "github-actions-typing", + command = "./gradlew build" + ) + + run( + name = "Regenerate the contents of dist directory", + workingDirectory = "github-actions-typing", + command = """ + set -euxo pipefail + + rm -rf dist + unzip -qq build/distributions/github-actions-typing.zip -d dist + """.trimIndent() + ) + + run( + name = "Configure git", + workingDirectory = "github-actions-typing", + command = """ + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + """.trimIndent() + ) + + if (branchName != null) { + run( + name = "Commit changes to temp branch", + workingDirectory = "github-actions-typing", + command = """ + git checkout -b $branchName + git add . + git commit -m "Update dist" + """.trimIndent() + ) + + run( + name = "Push commit", + workingDirectory = "github-actions-typing", + command = "git push --set-upstream origin $branchName", + ) + } else { + run( + name = "Commit changes", + workingDirectory = "github-actions-typing", + command = """ + git add . + git commit -m "Update dist" + """.trimIndent() + ) + + run( + name = "Push commit", + workingDirectory = "github-actions-typing", + command = "git push", + ) + } +} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6f5f1ed4..563aaed1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -60,7 +60,7 @@ jobs: git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" - id: 'step-6' - name: 'Commit changes' + name: 'Commit changes to temp branch' working-directory: 'github-actions-typing' run: |- git checkout -b temp-branch-for-release From 4e3b6b0462fc62481dacf6a8921d0c059200d5fd Mon Sep 17 00:00:00 2001 From: Piotr Krzeminski Date: Thu, 30 Jan 2025 22:05:55 +0100 Subject: [PATCH 2/2] On demand --- .github/workflows/make-branch-runnable.yaml | 2 +- .github/workflows/release.main.kts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/make-branch-runnable.yaml b/.github/workflows/make-branch-runnable.yaml index b09082d6..045960f6 100644 --- a/.github/workflows/make-branch-runnable.yaml +++ b/.github/workflows/make-branch-runnable.yaml @@ -4,7 +4,7 @@ name: 'Make branch runnable' on: - push: {} + workflow_dispatch: {} jobs: check_yaml_consistency: name: 'Check YAML consistency' diff --git a/.github/workflows/release.main.kts b/.github/workflows/release.main.kts index 30e80943..5d5cc93a 100755 --- a/.github/workflows/release.main.kts +++ b/.github/workflows/release.main.kts @@ -12,7 +12,6 @@ import io.github.typesafegithub.workflows.actions.actions.Checkout import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep import io.github.typesafegithub.workflows.domain.RunnerType -import io.github.typesafegithub.workflows.domain.triggers.Push import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch import io.github.typesafegithub.workflows.dsl.JobBuilder import io.github.typesafegithub.workflows.dsl.expressions.expr @@ -94,7 +93,7 @@ workflow( workflow( name = "Make branch runnable", on = listOf( - Push(), + WorkflowDispatch(), ), sourceFile = __FILE__, targetFileName = "make-branch-runnable.yaml",