Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import java.io.File
import org.eclipse.jgit.api.Git

workflow(
name = "Update metadata",
name = "Validate/Update metadata",
consistencyCheckJobConfig = DEFAULT_CONSISTENCY_CHECK_JOB_CONFIG.copy(
checkoutActionVersion = CheckoutActionVersionSource.InferFromClasspath(),
),
sourceFile = __FILE__,
on = listOf(Push(branches = listOf("main"))),
on = listOf(Push()),
) {
job(
id = "generate",
Expand All @@ -50,12 +50,19 @@ workflow(
run(name = "Run generation logic") {
removeMetadataFiles()
generateMetadataFiles()
commitChanges(github.sha)
if (github.ref == "main") {
println("Main branch - just validating")
checkForChanges()
} else {
println("Non-main branch...")
if (commitChanges(github.sha)) {
println("Committing changes")
gitPush()
} else {
println("Nothing to commit")
}
}
}
run(
name = "Push new commit",
command = "git push",
)
}
}

Expand All @@ -77,14 +84,28 @@ fun generateMetadataFiles() {
}
}

fun commitChanges(sha: String) {
fun checkForChanges() {
require(!Git.open(File(".")).status().call().hasUncommittedChanges()) {
"Metadata files changed after regeneration — they are not up to date!"
}
}

fun commitChanges(sha: String): Boolean {
Git.open(File(".")).apply {
add().addFilepattern("typings/").call()

if (status().call().hasUncommittedChanges()) {
commit().setMessage("Update metadata for commit $sha").call()
return true
}
}
return false
}

fun gitPush() {
val process = ProcessBuilder("git", "push")
.inheritIO().start()
check(process.waitFor() == 0) { "git push failed" }
}

fun writeToMetadataFile(actionRootDir: File, versionsWithTypings: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# This file was generated using Kotlin DSL (.github/workflows/update-metadata.main.kts).
# This file was generated using Kotlin DSL (.github/workflows/validate-update-metadata.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 metadata'
name: 'Validate/Update metadata'
on:
push:
branches:
- 'main'
push: {}
jobs:
check_yaml_consistency:
name: 'Check YAML consistency'
Expand All @@ -17,10 +15,10 @@ jobs:
uses: 'actions/checkout@v6'
- id: 'step-1'
name: 'Execute script'
run: 'rm ''.github/workflows/update-metadata.yaml'' && ''.github/workflows/update-metadata.main.kts'''
run: 'rm ''.github/workflows/validate-update-metadata.yaml'' && ''.github/workflows/validate-update-metadata.main.kts'''
- id: 'step-2'
name: 'Consistency check'
run: 'git diff --exit-code ''.github/workflows/update-metadata.yaml'''
run: 'git diff --exit-code ''.github/workflows/validate-update-metadata.yaml'''
generate:
runs-on: 'ubuntu-latest'
needs:
Expand All @@ -42,7 +40,4 @@ jobs:
name: 'Run generation logic'
env:
GHWKT_GITHUB_CONTEXT_JSON: '${{ toJSON(github) }}'
run: 'GHWKT_RUN_STEP=''update-metadata.yaml:generate:step-3'' ''.github/workflows/update-metadata.main.kts'''
- id: 'step-4'
name: 'Push new commit'
run: 'git push'
run: 'GHWKT_RUN_STEP=''validate-update-metadata.yaml:generate:step-3'' ''.github/workflows/validate-update-metadata.main.kts'''