Skip to content

Commit 5ff1deb

Browse files
authored
Create workflow for releasing (#213)
Part of #211.
1 parent fb234c3 commit 5ff1deb

File tree

4 files changed

+50
-66
lines changed

4 files changed

+50
-66
lines changed

.github/workflows/build.main.kts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,6 @@ workflow(
3131
) {
3232
uses(action = Checkout())
3333
uses(action = GradleBuildAction(arguments = "build"))
34-
35-
run(
36-
name = "Check if the produced files are committed correctly",
37-
command = """
38-
set -euxo pipefail
39-
40-
unzip_jar() {
41-
for jar in dist/github-actions-typing/lib/*.jar; do
42-
echo "Extracting ${'$'}jar..."
43-
filename=${'$'}(basename -- "${'$'}jar")
44-
filename="${'$'}{filename%.*}"
45-
46-
targetDir="${'$'}1/${'$'}filename"
47-
echo "Target directory: ${'$'}targetDir"
48-
49-
mkdir -p "${'$'}targetDir"
50-
unzip -qq "${'$'}jar" -d "${'$'}targetDir"
51-
done
52-
}
53-
54-
unzip_jar "dist-unzipped-before"
55-
56-
rm -rf dist
57-
unzip -qq build/distributions/github-actions-typing.zip -d dist
58-
59-
unzip_jar "dist-unzipped-after"
60-
61-
git diff --no-index --exit-code dist-unzipped-before dist-unzipped-after
62-
""".trimIndent()
63-
)
6434
}
6535

6636
job(

.github/workflows/build.yaml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,6 @@ jobs:
3333
uses: 'gradle/gradle-build-action@v3'
3434
with:
3535
arguments: 'build'
36-
- id: 'step-2'
37-
name: 'Check if the produced files are committed correctly'
38-
run: |-
39-
set -euxo pipefail
40-
41-
unzip_jar() {
42-
for jar in dist/github-actions-typing/lib/*.jar; do
43-
echo "Extracting $jar..."
44-
filename=$(basename -- "$jar")
45-
filename="${filename%.*}"
46-
47-
targetDir="$1/$filename"
48-
echo "Target directory: $targetDir"
49-
50-
mkdir -p "$targetDir"
51-
unzip -qq "$jar" -d "$targetDir"
52-
done
53-
}
54-
55-
unzip_jar "dist-unzipped-before"
56-
57-
rm -rf dist
58-
unzip -qq build/distributions/github-actions-typing.zip -d dist
59-
60-
unzip_jar "dist-unzipped-after"
61-
62-
git diff --no-index --exit-code dist-unzipped-before dist-unzipped-after
6336
validate-types:
6437
runs-on: 'ubuntu-latest'
6538
needs:
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@ import io.github.typesafegithub.workflows.actions.actions.Checkout
1010
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
1111
import io.github.typesafegithub.workflows.domain.RunnerType
1212
import io.github.typesafegithub.workflows.domain.triggers.WorkflowDispatch
13+
import io.github.typesafegithub.workflows.dsl.expressions.expr
1314
import io.github.typesafegithub.workflows.dsl.workflow
1415

1516
workflow(
16-
name = "Update dist",
17+
name = "Release",
1718
on = listOf(
18-
WorkflowDispatch(),
19+
WorkflowDispatch(
20+
inputs = mapOf(
21+
"version" to WorkflowDispatch.Input(
22+
type = WorkflowDispatch.Type.String,
23+
required = true,
24+
description = "Used for the tag and the version name. E.g. v1.2.3.",
25+
)
26+
),
27+
),
1928
),
2029
sourceFile = __FILE__,
2130
) {
2231
job(
23-
id = "build",
32+
id = "release",
2433
runsOn = RunnerType.UbuntuLatest,
2534
) {
2635
uses(action = Checkout())
@@ -46,9 +55,12 @@ workflow(
4655
""".trimIndent()
4756
)
4857

58+
val tempBranchName = "temp-branch-for-release"
59+
4960
run(
5061
name = "Commit changes",
5162
command = """
63+
git checkout -b $tempBranchName
5264
git add .
5365
git commit -m "Update dist"
5466
""".trimIndent()
@@ -58,5 +70,20 @@ workflow(
5870
name = "Push commit",
5971
command = "git push",
6072
)
73+
74+
val versionExpr = expr { "github.eventWorkflowDispatch.inputs.version" }
75+
76+
run(
77+
name = "Create and push tag",
78+
command = """
79+
git tag -a "$versionExpr" -m "Release version $versionExpr"
80+
git push origin "$versionExpr"
81+
""".trimIndent()
82+
)
83+
84+
run(
85+
name = "Delete temp branch",
86+
command = "git push origin --delete $tempBranchName"
87+
)
6188
}
6289
}
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# This file was generated using Kotlin DSL (.github/workflows/update-dist.main.kts).
1+
# This file was generated using Kotlin DSL (.github/workflows/release.main.kts).
22
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
33
# Generated with https://github.com/typesafegithub/github-workflows-kt
44

5-
name: 'Update dist'
5+
name: 'Release'
66
on:
7-
workflow_dispatch: {}
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: 'Used for the tag and the version name. E.g. v1.2.3.'
11+
type: 'string'
12+
required: true
813
jobs:
914
check_yaml_consistency:
1015
name: 'Check YAML consistency'
@@ -15,11 +20,11 @@ jobs:
1520
uses: 'actions/checkout@v4'
1621
- id: 'step-1'
1722
name: 'Execute script'
18-
run: 'rm ''.github/workflows/update-dist.yaml'' && ''.github/workflows/update-dist.main.kts'''
23+
run: 'rm ''.github/workflows/release.yaml'' && ''.github/workflows/release.main.kts'''
1924
- id: 'step-2'
2025
name: 'Consistency check'
21-
run: 'git diff --exit-code ''.github/workflows/update-dist.yaml'''
22-
build:
26+
run: 'git diff --exit-code ''.github/workflows/release.yaml'''
27+
release:
2328
runs-on: 'ubuntu-latest'
2429
needs:
2530
- 'check_yaml_consistency'
@@ -46,8 +51,17 @@ jobs:
4651
- id: 'step-5'
4752
name: 'Commit changes'
4853
run: |-
54+
git checkout -b temp-branch-for-release
4955
git add .
5056
git commit -m "Update dist"
5157
- id: 'step-6'
5258
name: 'Push commit'
5359
run: 'git push'
60+
- id: 'step-7'
61+
name: 'Create and push tag'
62+
run: |-
63+
git tag -a "${{ github.eventWorkflowDispatch.inputs.version }}" -m "Release version ${{ github.eventWorkflowDispatch.inputs.version }}"
64+
git push origin "${{ github.eventWorkflowDispatch.inputs.version }}"
65+
- id: 'step-8'
66+
name: 'Delete temp branch'
67+
run: 'git push origin --delete temp-branch-for-release'

0 commit comments

Comments
 (0)