-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added "update status to PR" step for gh action bot
- Loading branch information
1 parent
f410705
commit 6e904e4
Showing
1 changed file
with
20 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
name: Show generated code in PR | ||
name: Preview Generated Code | ||
|
||
permissions: | ||
contents: write | ||
statuses: write | ||
|
||
on: | ||
pull_request: | ||
|
@@ -10,16 +14,15 @@ on: | |
- ready_for_review | ||
|
||
jobs: | ||
build: | ||
build_preview_generated_code: | ||
name: Build Preview of Generated Code | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ github.token }} | ||
|
||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
|
@@ -39,7 +42,7 @@ jobs: | |
|
||
- 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)" | ||
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 | ||
|
@@ -49,44 +52,21 @@ jobs: | |
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 | ||
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, | ||
}); | ||
} | ||
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | ||
- name: Add comment to PR | ||
- name: Update status 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, | ||
await github.rest.repos.createCommitStatus({ | ||
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 }}).", | ||
sha: context.payload.pull_request.head.sha, | ||
state: "success", | ||
target_url: "https://github.com/${{ github.repository }}/commit/${{ steps.git-commit.outputs.commit }}", | ||
context: "Generated sources will change, merging this PR", | ||
description: "Check 'Details' to inspect changes ->" | ||
}); | ||