8000 ci: add workflow for making branch runnable by krzema12 · Pull Request #260 · typesafegithub/github-actions-typing · GitHub
[go: up one dir, main page]

Skip to content

ci: add workflow for making branch runnable #260

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 2 commits into from
Jan 30, 2025
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
66 changes: 66 additions & 0 deletions .github/workflows/make-branch-runnable.yaml
Original file line number Diff line number Diff line change
@@ -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:
workflow_dispatch: {}
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'
147 changes: 92 additions & 55 deletions .github/workflows/release.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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.JobBuilder
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import kotlinx.serialization.json.Json
Expand All @@ -39,62 +40,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" }

Expand Down Expand Up @@ -142,3 +89,93 @@ workflow(
)
}
}

workflow(
name = "Make branch runnable",
on = listOf(
WorkflowDispatch(),
),
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",
)
}
}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
0