8000 Update major version tag upon releasing by krzema12 · Pull Request #222 · typesafegithub/github-actions-typing · GitHub
[go: up one dir, main page]

Skip to content

Update major version tag upon releasing #222

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

Merged
merged 1 commit into from
Oct 13, 2024
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
35 changes: 34 additions & 1 deletion .github/workflows/release.main.kts
8000
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#!/usr/bin/env kotlin
@file:Repository("https://repo1.maven.org/maven2/")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:3.0.0")
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")

@file:Repository("https://bindings.krzeminski.it")
@file:DependsOn("actions:checkout:v4")
@file:DependsOn("gradle:actions__setup-gradle:v4")
@file:OptIn(ExperimentalKotlinLogicStep::class)

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.WorkflowDispatch
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive

workflow(
name = "Release",
Expand Down Expand Up @@ -74,13 +81,39 @@ workflow(
val versionExpr = expr { "github.event.inputs.version" }

run(
name = "Create and push tag",
name = "Create and push a patch version tag",
command = """
git tag -a "$versionExpr" -m "Release version $versionExpr"
git push origin "$versionExpr"
""".trimIndent()
)

val MAJOR_VERSION_OUTPUT_NAME = "majorVersion"

val extractMajorVersion = run {
// There should be a way to access the inputs using the DSL.
// TODO: https://github.com/typesafegithub/github-workflows-kt/issues/1685
val githubContextJson = System.getenv("GHWKT_GITHUB_CONTEXT_JSON")!!
val version: String = Json.parseToJsonElement(githubContextJson)
.jsonObject["event"]
?.jsonObject?.get("inputs")
?.jsonObject?.get("version")
?.jsonPrimitive?.contentOrNull
?: error("Version couldn't be extracted from input")
val majorVersion = version.substringBefore(".")
outputs[MAJOR_VERSION_OUTPUT_NAME] = majorVersion
}

val majorVersionExpr = expr { "steps.${extractMajorVersion.id}.outputs.$MAJOR_VERSION_OUTPUT_NAME" }

run(
name = "Create or update a major version tag",
command = """
git tag "$majorVersionExpr" -f
git push origin "$majorVersionExpr" -f
""".trimIndent()
)

run(
name = "Delete temp branch",
command = "git push origin --delete $tempBranchName"
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ jobs:
name: 'Push commit'
run: 'git push --set-upstream origin temp-branch-for-release'
- id: 'step-7'
name: 'Create and push tag'
name: 'Create and push a patch version tag'
run: |-
git tag -a "${{ github.event.inputs.version }}" -m "Release version ${{ github.event.inputs.version }}"
git push origin "${{ github.event.inputs.version }}"
- id: 'step-8'
env:
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
run: 'GHWKT_RUN_STEP=''release:step-8'' ''.github/workflows/release.main.kts'''
- id: 'step-9'
name: 'Create or update a major version tag'
run: |-
git tag "${{ steps.step-8.outputs.majorVersion }}" -f
git push origin "${{ steps.step-8.outputs.majorVersion }}" -f
- id: 'step-10'
name: 'Delete temp branch'
run: 'git push origin --delete temp-branch-for-release'
Loading
0