diff --git a/.editorconfig b/.editorconfig index 6a1207f47..1144196bb 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ max_line_length=120 [*.json] indent_size=2 -[*.yaml] +[{*.yaml,*.yml}] indent_size=2 [*.ipynb] diff --git a/.github/workflows/generated-sources-master.yml b/.github/workflows/generated-sources-master.yml new file mode 100644 index 000000000..197dc4ddc --- /dev/null +++ b/.github/workflows/generated-sources-master.yml @@ -0,0 +1,33 @@ +name: Auto-commit generated code + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - name: Run Gradle task + run: ./gradlew :core:processKDocsMain + + - name: Commit changes + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add ./core/generated-sources + git diff --staged --quiet || git commit -m "Automated commit of generated code" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/generated-sources.yml b/.github/workflows/generated-sources.yml new file mode 100644 index 000000000..99c8f84aa --- /dev/null +++ b/.github/workflows/generated-sources.yml @@ -0,0 +1,92 @@ +name: Show generated code in PR + +on: + pull_request: + types: + - edited + - opened + - synchronize + - converted_to_draft + - ready_for_review + +jobs: + build: + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '11' + + - name: Configure Git User + run: | + git config --global user.email "actions@github.com" + git config --global user.name "GitHub Actions" + + - name: Run Gradle task + run: ./gradlew :core:processKDocsMain + + - name: Check for changes in generated sources + id: git-diff + run: echo "::set-output name=changed::$(if git diff --quiet './core/generated-sources'; then echo 'false'; else echo 'true'; fi)" + + - name: Commit and push if changes + id: git-commit + if: steps.git-diff.outputs.changed == 'true' + run: | + git checkout -b generated-sources/docs-update-${{ github.run_number }} + git add './core/generated-sources' + git commit -m "Update generated sources with recent changes" + git push origin generated-sources/docs-update-${{ github.run_number }} + echo "::set-output name=commit::$(git rev-parse HEAD)" + + - name: Remove old comments + uses: actions/github-script@v5 + if: steps.git-diff.outputs.changed == 'true' + with: + # language=js + script: | + const issue_number = context.issue.number; + const {owner, repo} = context.repo; + + const comments = await github.rest.issues.listComments({ + issue_number, + owner, + repo, + }); + + const botComments = comments.data.filter( + (comment) => comment.user.login === 'github-actions[bot]' + ); + + for (const comment of botComments) { + await github.rest.issues.deleteComment({ + comment_id: comment.id, + owner, + repo, + }); + } + + - name: Add comment to PR + uses: actions/github-script@v5 + if: steps.git-diff.outputs.changed == 'true' + with: + # language=js + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Generated sources will be updated after merging this PR.\nPlease inspect the changes in [here](https://github.com/${{ github.repository }}/commit/${{ steps.git-commit.outputs.commit }}).", + }); diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 3642a81dd..354afd0dd 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -6,7 +6,6 @@ import nl.jolanrensen.docProcessor.gradle.creatingProcessDocTask import org.gradle.jvm.tasks.Jar import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jmailen.gradle.kotlinter.tasks.LintTask -import xyz.ronella.gradle.plugin.simple.git.OSType import xyz.ronella.gradle.plugin.simple.git.task.GitTask plugins { @@ -141,7 +140,8 @@ val clearSamplesOutputs by tasks.creating { doFirst { delete { - val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets")).exclude("**/manual/**") + val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets")) + .exclude("**/manual/**", "**/kdocs/**") delete(generatedSnippets) } } @@ -170,41 +170,9 @@ tasks.withType { dependsOn(copySamplesOutputs) } -// This task installs the pre-commit hook to the local machine the first time the project is built -// The pre-commit hook contains the command to run processKDocsMain before each commit -val installGitPreCommitHook by tasks.creating(Copy::class) { - doNotTrackState(/* reasonNotToTrackState = */ "Fails on TeamCity otherwise.") - - val gitHooksDir = File(rootProject.rootDir, ".git/hooks") - if (gitHooksDir.exists()) { - from(File(rootProject.rootDir, "gradle/scripts/pre-commit")) - into(gitHooksDir) - fileMode = 755 - - // Workaround for https://github.com/Kotlin/dataframe/issues/612 - if (OSType.identify() in listOf(OSType.Mac, OSType.Linux)) doLast { - exec { - workingDir(gitHooksDir) - commandLine("chmod", "755", "pre-commit") - } - } - } else { - logger.lifecycle("'.git/hooks' directory not found. Skipping installation of pre-commit hook.") - } -} -tasks.named("assemble") { - dependsOn(installGitPreCommitHook) -} - // region docPreprocessor -// This task is used to add all generated sources (from processKDocsMain) to git val generatedSourcesFolderName = "generated-sources" -val addGeneratedSourcesToGit by tasks.creating(GitTask::class) { - directory.set(file(".")) - command.set("add") - args.set(listOf("-A", generatedSourcesFolderName)) -} // Backup the kotlin source files location val kotlinMainSources: FileCollection = kotlin.sourceSets.main.get().kotlin.sourceDirectories @@ -221,14 +189,10 @@ val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) { target = file(generatedSourcesFolderName) arguments += ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false exportAsHtml { - dir = file("../docs/StardustDocs/snippets") + dir = file("../docs/StardustDocs/snippets/kdocs") } task { group = "KDocs" - doLast { - // ensure generated sources are added to git - addGeneratedSourcesToGit.executeCommand() - } } } diff --git a/docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html b/docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html similarity index 100% rename from docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html rename to docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html diff --git a/docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html b/docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html similarity index 100% rename from docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html rename to docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html diff --git a/docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html b/docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html similarity index 100% rename from docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html rename to docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html diff --git a/docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html b/docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html similarity index 100% rename from docs/StardustDocs/snippets/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html rename to docs/StardustDocs/snippets/kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html diff --git a/docs/StardustDocs/topics/ColumnSelectors.md b/docs/StardustDocs/topics/ColumnSelectors.md index 7e079fb10..bbed8a921 100644 --- a/docs/StardustDocs/topics/ColumnSelectors.md +++ b/docs/StardustDocs/topics/ColumnSelectors.md @@ -25,17 +25,17 @@ df.move { name.firstName and name.lastName }.after { city } **Definitions** - + - + - + - + diff --git a/gradle/scripts/pre-commit b/gradle/scripts/pre-commit deleted file mode 100644 index 0ddcd1992..000000000 --- a/gradle/scripts/pre-commit +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -echo "*****Running Doc Preprocessor******" - -./gradlew processKDocsMain - -status=$? - -echo "*****Done running Doc Preprocessor******" - -exit $status