diff --git a/.github/workflows/build.main.kts b/.github/workflows/build.main.kts index 48b270b..3e2f8e1 100755 --- a/.github/workflows/build.main.kts +++ b/.github/workflows/build.main.kts @@ -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( diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8a846ec..279ef03 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -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: diff --git a/.github/workflows/update-dist.main.kts b/.github/workflows/release.main.kts similarity index 63% rename from .github/workflows/update-dist.main.kts rename to .github/workflows/release.main.kts index c085787..71984d4 100755 --- a/.github/workflows/update-dist.main.kts +++ b/.github/workflows/release.main.kts @@ -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()) @@ -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() @@ -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" + ) } } diff --git a/.github/workflows/update-dist.yaml b/.github/workflows/release.yaml similarity index 60% rename from .github/workflows/update-dist.yaml rename to .github/workflows/release.yaml index 77d4622..51399b2 100644 --- a/.github/workflows/update-dist.yaml +++ b/.github/workflows/release.yaml @@ -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' @@ -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' @@ -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'