Skip to content

Commit e418f9b

Browse files
authored
Merge pull request #731 from Kotlin/kdocs-gh-action-2
KDocs GH actions
2 parents 76091c7 + 670fab3 commit e418f9b

10 files changed

+133
-55
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ max_line_length=120
99
[*.json]
1010
indent_size=2
1111

12-
[*.yaml]
12+
[{*.yaml,*.yml}]
1313
indent_size=2
1414

1515
[*.ipynb]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Auto-commit generated code
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v3
15+
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: '11'
21+
22+
- name: Run Gradle task
23+
run: ./gradlew :core:processKDocsMain
24+
25+
- name: Commit changes
26+
run: |
27+
git config --global user.name 'github-actions[bot]'
28+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
29+
git add ./core/generated-sources
30+
git diff --staged --quiet || git commit -m "Automated commit of generated code"
31+
git push
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Show generated code in PR
2+
3+
on:
4+
pull_request:
5+
types:
6+
- edited
7+
- opened
8+
- synchronize
9+
- converted_to_draft
10+
- ready_for_review
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
steps:
18+
- name: Cancel Previous Runs
19+
uses: styfle/[email protected]
20+
with:
21+
access_token: ${{ github.token }}
22+
23+
- name: Checkout repository
24+
uses: actions/checkout@v3
25+
26+
- name: Set up JDK 11
27+
uses: actions/setup-java@v4
28+
with:
29+
distribution: 'temurin'
30+
java-version: '11'
31+
32+
- name: Configure Git User
33+
run: |
34+
git config --global user.email "[email protected]"
35+
git config --global user.name "GitHub Actions"
36+
37+
- name: Run Gradle task
38+
run: ./gradlew :core:processKDocsMain
39+
40+
- name: Check for changes in generated sources
41+
id: git-diff
42+
run: echo "::set-output name=changed::$(if git diff --quiet './core/generated-sources'; then echo 'false'; else echo 'true'; fi)"
43+
44+
- name: Commit and push if changes
45+
id: git-commit
46+
if: steps.git-diff.outputs.changed == 'true'
47+
run: |
48+
git checkout -b generated-sources/docs-update-${{ github.run_number }}
49+
git add './core/generated-sources'
50+
git commit -m "Update generated sources with recent changes"
51+
git push origin generated-sources/docs-update-${{ github.run_number }}
52+
echo "::set-output name=commit::$(git rev-parse HEAD)"
53+
54+
- name: Remove old comments
55+
uses: actions/github-script@v5
56+
if: steps.git-diff.outputs.changed == 'true'
57+
with:
58+
# language=js
59+
script: |
60+
const issue_number = context.issue.number;
61+
const {owner, repo} = context.repo;
62+
63+
const comments = await github.rest.issues.listComments({
64+
issue_number,
65+
owner,
66+
repo,
67+
});
68+
69+
const botComments = comments.data.filter(
70+
(comment) => comment.user.login === 'github-actions[bot]'
71+
);
72+
73+
for (const comment of botComments) {
74+
await github.rest.issues.deleteComment({
75+
comment_id: comment.id,
76+
owner,
77+
repo,
78+
});
79+
}
80+
81+
- name: Add comment to PR
82+
uses: actions/github-script@v5
83+
if: steps.git-diff.outputs.changed == 'true'
84+
with:
85+
# language=js
86+
script: |
87+
github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
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 }}).",
92+
});

core/build.gradle.kts

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import nl.jolanrensen.docProcessor.gradle.creatingProcessDocTask
66
import org.gradle.jvm.tasks.Jar
77
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
88
import org.jmailen.gradle.kotlinter.tasks.LintTask
9-
import xyz.ronella.gradle.plugin.simple.git.OSType
109
import xyz.ronella.gradle.plugin.simple.git.task.GitTask
1110

1211
plugins {
@@ -141,7 +140,8 @@ val clearSamplesOutputs by tasks.creating {
141140

142141
doFirst {
143142
delete {
144-
val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets")).exclude("**/manual/**")
143+
val generatedSnippets = fileTree(file("../docs/StardustDocs/snippets"))
144+
.exclude("**/manual/**", "**/kdocs/**")
145145
delete(generatedSnippets)
146146
}
147147
}
@@ -170,41 +170,9 @@ tasks.withType<KorroTask> {
170170
dependsOn(copySamplesOutputs)
171171
}
172172

173-
// This task installs the pre-commit hook to the local machine the first time the project is built
174-
// The pre-commit hook contains the command to run processKDocsMain before each commit
175-
val installGitPreCommitHook by tasks.creating(Copy::class) {
176-
doNotTrackState(/* reasonNotToTrackState = */ "Fails on TeamCity otherwise.")
177-
178-
val gitHooksDir = File(rootProject.rootDir, ".git/hooks")
179-
if (gitHooksDir.exists()) {
180-
from(File(rootProject.rootDir, "gradle/scripts/pre-commit"))
181-
into(gitHooksDir)
182-
fileMode = 755
183-
184-
// Workaround for https://github.com/Kotlin/dataframe/issues/612
185-
if (OSType.identify() in listOf(OSType.Mac, OSType.Linux)) doLast {
186-
exec {
187-
workingDir(gitHooksDir)
188-
commandLine("chmod", "755", "pre-commit")
189-
}
190-
}
191-
} else {
192-
logger.lifecycle("'.git/hooks' directory not found. Skipping installation of pre-commit hook.")
193-
}
194-
}
195-
tasks.named("assemble") {
196-
dependsOn(installGitPreCommitHook)
197-
}
198-
199173
// region docPreprocessor
200174

201-
// This task is used to add all generated sources (from processKDocsMain) to git
202175
val generatedSourcesFolderName = "generated-sources"
203-
val addGeneratedSourcesToGit by tasks.creating(GitTask::class) {
204-
directory.set(file("."))
205-
command.set("add")
206-
args.set(listOf("-A", generatedSourcesFolderName))
207-
}
208176

209177
// Backup the kotlin source files location
210178
val kotlinMainSources: FileCollection = kotlin.sourceSets.main.get().kotlin.sourceDirectories
@@ -221,14 +189,10 @@ val processKDocsMain by creatingProcessDocTask(processKDocsMainSources) {
221189
target = file(generatedSourcesFolderName)
222190
arguments += ARG_DOC_PROCESSOR_LOG_NOT_FOUND to false
223191
exportAsHtml {
224-
dir = file("../docs/StardustDocs/snippets")
192+
dir = file("../docs/StardustDocs/snippets/kdocs")
225193
}
226194
task {
227195
group = "KDocs"
228-
doLast {
229-
// ensure generated sources are added to git
230-
addGeneratedSourcesToGit.executeCommand()
231-
}
232196
}
233197
}
234198

docs/StardustDocs/topics/ColumnSelectors.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ df.move { name.firstName and name.lastName }.after { city }
2525

2626
**Definitions**
2727

28-
<dataFrame src="org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html"/>
28+
<dataFrame src="kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.DefinitionsPartOfGrammar.html"/>
2929

3030
<tabs>
3131
<tab title="Directly in the DSL">
32-
<dataFrame src="org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html"/>
32+
<dataFrame src="kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.PlainDslPartOfGrammar.html"/>
3333
</tab>
3434
<tab title="On a Column Set">
35-
<dataFrame src="org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html"/>
35+
<dataFrame src="kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnSetPartOfGrammar.ForHtml.html"/>
3636
</tab>
3737
<tab title="On a Column Group">
38-
<dataFrame src="org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html"/>
38+
<dataFrame src="kdocs/org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.DslGrammar.ColumnGroupPartOfGrammar.ForHtml.html"/>
3939
</tab>
4040
</tabs>
4141

gradle/scripts/pre-commit

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)