Skip to content

Commit

Permalink
added "update status to PR" step for gh action bot
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Oct 23, 2024
1 parent 5dfa3e0 commit f1c437e
Showing 1 changed file with 111 additions and 54 deletions.
165 changes: 111 additions & 54 deletions .github/workflows/generated-sources.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
name: Show generated code in PR
name: Preview Generated Code

permissions:
contents: write
checks: write
statuses: write
pull-requests: write

on:
pull_request:
Expand All @@ -11,15 +17,15 @@ on:

jobs:
build:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout repository
uses: actions/checkout@v4

Expand All @@ -34,59 +40,110 @@ jobs:
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
- name: Run Gradle task
run: ./gradlew :core:processKDocsMain korro

- name: Check for changes in generated sources
id: git-diff
run: echo "::set-output name=changed::$(if git diff --quiet './core/generated-sources' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'; 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' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'
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
- name: TEST! Update status to PR
uses: actions/github-script@v7
if: steps.git-diff.outputs.changed == 'true'
with:
debug: true
# 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 name = "Some Test Name, Click Here!";
const message = "Custom message!";
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@v7
if: steps.git-diff.outputs.changed == 'true'
with:
# language=js
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
const checkRun = await github.rest.checks.create({
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 }}).",
name: name,
head_sha: context.payload.pull_request.head.sha,
conclusion: "success",
status: "completed",
output: {
title: "Custom Title!",
summary: message,
text: message
}
});
console.log("Check run created:", checkRun);
console.log("head sha:", context.payload.pull_request.head.sha);
console.log("Check run output:", checkRun.data.output);
# - name: Run Gradle task
# run: ./gradlew :core:processKDocsMain korro
#
# - name: Check for changes in generated sources
# id: git-diff
# run: echo "changed=$(if git diff --quiet './core/generated-sources' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'; then echo 'false'; else echo 'true'; fi)" >> $GITHUB_OUTPUT
#
# - 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' './docs/StardustDocs/snippets' './docs/StardustDocs/topics'
# git commit -m "Update generated sources with recent changes"
# git push origin generated-sources/docs-update-${{ github.run_number }}
# echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
#
## - name: Remove old comments
## uses: actions/github-script@v7
## 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@v7
# # 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 }}).",
# # });
#
# - name: Update status to PR
# uses: actions/github-script@v7
# if: steps.git-diff.outputs.changed == 'true'
# env:
# parameter_url: '${{ github.event.workflow_run.html_url }}'
# with:
# debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }}
# # language=js
# script: |
# await github.rest.checks.create({
# owner: context.repo.owner,
# repo: context.repo.repo,
# name: "Click here!",
# head_sha: context.sha,
# conclusion: "success",
# status: "completed",
# output: {
# title: "Check 'Details' to see changes in generated sources",
# summary: "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 }}).",
# text: "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 }})."
# },
# });

0 comments on commit f1c437e

Please sign in to comment.