@@ -13,6 +13,7 @@ import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
1313import io.github.typesafegithub.workflows.annotations.ExperimentalKotlinLogicStep
1414import io.github.typesafegithub.workflows.domain.RunnerType
1515import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch
16+ import io.github.typesafegithub.workflows.dsl.JobBuilder
1617import io.github.typesafegithub.workflows.dsl.expressions.expr
1718import io.github.typesafegithub.workflows.dsl.workflow
1819import 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+ }
0 commit comments