Skip to content

Commit 8b365ae

Browse files
authored
ci: add workflow for making branch runnable (#260)
Before this change, only released versions were runnable. Thanks to the new workflow, it's possible to test any branch by adding distribution files on demand.
1 parent c7e8e3a commit 8b365ae

File tree

3 files changed

+159
-56
lines changed

3 files changed

+159
-56
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file was generated using Kotlin DSL (.github/workflows/release.main.kts).
2+
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
3+
# Generated with https://github.com/typesafegithub/github-workflows-kt
4+
5+
name: 'Make branch runnable'
6+
on:
7+
workflow_dispatch: {}
8+
jobs:
9+
check_yaml_consistency:
10+
name: 'Check YAML consistency'
11+
runs-on: 'ubuntu-latest'
12+
steps:
13+
- id: 'step-0'
14+
name: 'Check out'
15+
uses: 'actions/checkout@v4'
16+
- id: 'step-1'
17+
name: 'Execute script'
18+
run: 'rm ''.github/workflows/make-branch-runnable.yaml'' && ''.github/workflows/release.main.kts'''
19+
- id: 'step-2'
20+
name: 'Consistency check'
21+
run: 'git diff --exit-code ''.github/workflows/make-branch-runnable.yaml'''
22+
make-branch-runnable:
23+
runs-on: 'ubuntu-latest'
24+
needs:
25+
- 'check_yaml_consistency'
26+
steps:
27+
- id: 'step-0'
28+
name: 'Checkout github-actions-typing'
29+
uses: 'actions/checkout@v4'
30+
with:
31+
path: 'github-actions-typing'
32+
- id: 'step-1'
33+
name: 'Checkout github-actions-typing-catalog'
34+
uses: 'actions/checkout@v4'
35+
with:
36+
repository: 'typesafegithub/github-actions-typing-catalog'
37+
path: 'github-actions-typing-catalog'
38+
- id: 'step-2'
39+
uses: 'gradle/actions/setup-gradle@v4'
40+
- id: 'step-3'
41+
working-directory: 'github-actions-typing'
42+
run: './gradlew build'
43+
- id: 'step-4'
44+
name: 'Regenerate the contents of dist directory'
45+
working-directory: 'github-actions-typing'
46+
run: |-
47+
set -euxo pipefail
48+
49+
rm -rf dist
50+
unzip -qq build/distributions/github-actions-typing.zip -d dist
51+
- id: 'step-5'
52+
name: 'Configure git'
53+
working-directory: 'github-actions-typing'
54+
run: |-
55+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
56+
git config user.name "github-actions[bot]"
57+
- id: 'step-6'
58+
name: 'Commit changes'
59+
working-directory: 'github-actions-typing'
60+
run: |-
61+
git add .
62+
git commit -m "Update dist"
63+
- id: 'step-7'
64+
name: 'Push commit'
65+
working-directory: 'github-actions-typing'
66+
run: 'git push'

.github/workflows/release.main.kts

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
1313
import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep
1414
import io.github.typesafegithub.workflows.domain.RunnerType
1515
import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch
16+
import io.github.typesafegithub.workflows.dsl.JobBuilder
1617
import io.github.typesafegithub.workflows.dsl.expressions.expr
1718
import io.github.typesafegithub.workflows.dsl.workflow
1819
import kotlinx.serialization.json.Json
@@ -39,62 +40,8 @@ workflow(
3940
id = "release",
4041
runsOn = RunnerType.UbuntuLatest,
4142
) {
42-
uses(
43-
name = "Checkout github-actions-typing",
44-
action = Checkout(
45-
path = "github-actions-typing"
46-
)
47-
)
48-
uses(
49-
name = "Checkout github-actions-typing-catalog",
50-
action = Checkout(
51-
repository = "typesafegithub/github-actions-typing-catalog",
52-
path = "github-actions-typing-catalog"
53-
)
54-
)
55-
uses(action = ActionsSetupGradle())
56-
run(
57-
workingDirectory = "github-actions-typing",
58-
command = "./gradlew build"
59-
)
60-
61-
run(
62-
name = "Regenerate the contents of dist directory",
63-
workingDirectory = "github-actions-typing",
64-
command = """
65-
set -euxo pipefail
66-
67-
rm -rf dist
68-
unzip -qq build/distributions/github-actions-typing.zip -d dist
69-
""".trimIndent()
70-
)
71-
72-
run(
73-
name = "Configure git",
74-
workingDirectory = "github-actions-typing",
75-
command = """
76-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
77-
git config user.name "github-actions[bot]"
78-
""".trimIndent()
79-
)
80-
8143
val tempBranchName = "temp-branch-for-release"
82-
83-
run(
84-
name = "Commit changes",
85-
workingDirectory = "github-actions-typing",
86-
command = """
87-
git checkout -b $tempBranchName
88-
git add .
89-
git commit -m "Update dist"
90-
""".trimIndent()
91-
)
92-
93-
run(
94-
name = "Push commit",
95-
workingDirectory = "github-actions-typing",
96-
command = "git push --set-upstream origin $tempBranchName",
97-
)
44+
buildAndCommitDist(branchName = tempBranchName)
9845

9946
val versionExpr = expr { "github.event.inputs.version" }
10047

@@ -142,3 +89,93 @@ workflow(
14289
)
14390
}
14491
}
92+
93+
workflow(
94+
name = "Make branch runnable",
95+
on = listOf(
96+
WorkflowDispatch(),
97+
),
98+
sourceFile = __FILE__,
99+
targetFileName = "make-branch-runnable.yaml",
100+
) {
101+
job(
102+
id = "make-branch-runnable",
103+
runsOn = RunnerType.UbuntuLatest,
104+
) {
105+
buildAndCommitDist()
106+
}
107+
}
108+
109+
private fun JobBuilder<*>.buildAndCommitDist(branchName: String? = null) {
110+
uses(
111+
name = "Checkout github-actions-typing",
112+
action = Checkout(
113+
path = "github-actions-typing"
114+
)
115+
)
116+
uses(
117+
name = "Checkout github-actions-typing-catalog",
118+
action = Checkout(
119+
repository = "typesafegithub/github-actions-typing-catalog",
120+
path = "github-actions-typing-catalog"
121+
)
122+
)
123+
uses(action = ActionsSetupGradle())
124+
run(
125+
workingDirectory = "github-actions-typing",
126+
command = "./gradlew build"
127+
)
128+
129+
run(
130+
name = "Regenerate the contents of dist directory",
131+
workingDirectory = "github-actions-typing",
132+
command = """
133+
set -euxo pipefail
134+
135+
rm -rf dist
136+
unzip -qq build/distributions/github-actions-typing.zip -d dist
137+
""".trimIndent()
138+
)
139+
140+
run(
141+
name = "Configure git",
142+
workingDirectory = "github-actions-typing",
143+
command = """
144+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
145+
git config user.name "github-actions[bot]"
146+
""".trimIndent()
147+
)
148+
149+
if (branchName != null) {
150+
run(
151+
name = "Commit changes to temp branch",
152+
workingDirectory = "github-actions-typing",
153+
command = """
154+
git checkout -b $branchName
155+
git add .
156+
git commit -m "Update dist"
157+
""".trimIndent()
158+
)
159+
160+
run(
161+
name = "Push commit",
162+
workingDirectory = "github-actions-typing",
163+
command = "git push --set-upstream origin $branchName",
164+
)
165+
} else {
166+
run(
167+
name = "Commit changes",
168+
workingDirectory = "github-actions-typing",
169+
command = """
170+
git add .
171+
git commit -m "Update dist"
172+
""".trimIndent()
173+
)
174+
175+
run(
176+
name = "Push commit",
177+
workingDirectory = "github-actions-typing",
178+
command = "git push",
179+
)
180+
}
181+
}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
6161
git config user.name "github-actions[bot]"
6262
- id: 'step-6'
63-
name: 'Commit changes'
63+
name: 'Commit changes to temp branch'
6464
working-directory: 'github-actions-typing'
6565
run: |-
6666
git checkout -b temp-branch-for-release

0 commit comments

Comments
 (0)