Skip to content

Commit

Permalink
Create workflow for releasing (#213)
Browse files Browse the repository at this point in the history
Part of #211.
  • Loading branch information
krzema12 authored Aug 28, 2024
1 parent fb234c3 commit 5ff1deb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 66 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/build.main.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,6 @@ workflow(
) {
uses(action = Checkout())
uses(action = GradleBuildAction(arguments = "build"))

run(
name = "Check if the produced files are committed correctly",
command = """
set -euxo pipefail
unzip_jar() {
for jar in dist/github-actions-typing/lib/*.jar; do
echo "Extracting ${'$'}jar..."
filename=${'$'}(basename -- "${'$'}jar")
filename="${'$'}{filename%.*}"
targetDir="${'$'}1/${'$'}filename"
echo "Target directory: ${'$'}targetDir"
mkdir -p "${'$'}targetDir"
unzip -qq "${'$'}jar" -d "${'$'}targetDir"
done
}
unzip_jar "dist-unzipped-before"
rm -rf dist
unzip -qq build/distributions/github-actions-typing.zip -d dist
unzip_jar "dist-unzipped-after"
git diff --no-index --exit-code dist-unzipped-before dist-unzipped-after
""".trimIndent()
)
}

job(
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,6 @@ jobs:
uses: 'gradle/gradle-build-action@v3'
with:
arguments: 'build'
- id: 'step-2'
name: 'Check if the produced files are committed correctly'
run: |-
set -euxo pipefail
unzip_jar() {
for jar in dist/github-actions-typing/lib/*.jar; do
echo "Extracting $jar..."
filename=$(basename -- "$jar")
filename="${filename%.*}"
targetDir="$1/$filename"
echo "Target directory: $targetDir"
mkdir -p "$targetDir"
unzip -qq "$jar" -d "$targetDir"
done
}
unzip_jar "dist-unzipped-before"
rm -rf dist
unzip -qq build/distributions/github-actions-typing.zip -d dist
unzip_jar "dist-unzipped-after"
git diff --no-index --exit-code dist-unzipped-before dist-unzipped-after
validate-types:
runs-on: 'ubuntu-latest'
needs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ import io.github.typesafegithub.workflows.actions.actions.Checkout
import io.github.typesafegithub.workflows.actions.gradle.ActionsSetupGradle
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

workflow(
name = "Update dist",
name = "Release",
on = listOf(
WorkflowDispatch(),
WorkflowDispatch(
inputs = mapOf(
"version" to WorkflowDispatch.Input(
type = WorkflowDispatch.Type.String,
required = true,
description = "Used for the tag and the version name. E.g. v1.2.3.",
)
),
),
),
sourceFile = __FILE__,
) {
job(
id = "build",
id = "release",
runsOn = RunnerType.UbuntuLatest,
) {
uses(action = Checkout())
Expand All @@ -46,9 +55,12 @@ workflow(
""".trimIndent()
)

val tempBranchName = "temp-branch-for-release"

run(
name = "Commit changes",
command = """
git checkout -b $tempBranchName
git add .
git commit -m "Update dist"
""".trimIndent()
Expand All @@ -58,5 +70,20 @@ workflow(
name = "Push commit",
command = "git push",
)

val versionExpr = expr { "github.eventWorkflowDispatch.inputs.version" }

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

run(
name = "Delete temp branch",
command = "git push origin --delete $tempBranchName"
)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# This file was generated using Kotlin DSL (.github/workflows/update-dist.main.kts).
# 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: 'Update dist'
name: 'Release'
on:
workflow_dispatch: {}
workflow_dispatch:
inputs:
version:
description: 'Used for the tag and the version name. E.g. v1.2.3.'
type: 'string'
required: true
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand All @@ -15,11 +20,11 @@ jobs:
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/update-dist.yaml'' && ''.github/workflows/update-dist.main.kts'''
run: 'rm ''.github/workflows/release.yaml'' && ''.github/workflows/release.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/update-dist.yaml'''
build:
run: 'git diff --exit-code ''.github/workflows/release.yaml'''
release:
runs-on: 'ubuntu-latest'
needs:
- 'check_yaml_consistency'
Expand All @@ -46,8 +51,17 @@ jobs:
- id: 'step-5'
name: 'Commit changes'
run: |-
git checkout -b temp-branch-for-release
git add .
git commit -m "Update dist"
- id: 'step-6'
name: 'Push commit'
run: 'git push'
- id: 'step-7'
name: 'Create and push tag'
run: |-
git tag -a "${{ github.eventWorkflowDispatch.inputs.version }}" -m "Release version ${{ github.eventWorkflowDispatch.inputs.version }}"
git push origin "${{ github.eventWorkflowDispatch.inputs.version }}"
- id: 'step-8'
name: 'Delete temp branch'
run: 'git push origin --delete temp-branch-for-release'

0 comments on commit 5ff1deb

Please sign in to comment.