Skip to content

Commit 9f368e9

Browse files
committed
adding two GH actions:
one which comments on PRs showing changed generated-sources, and a second one that commits changed generated-sources to the master branch on push
1 parent 6e1fa46 commit 9f368e9

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
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/cancel-workflow-action@0.9.1
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 "actions@github.com"
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+
});

0 commit comments

Comments
 (0)