From 7e3ed47ae073ec0f32c390befdb95174f53a3ba7 Mon Sep 17 00:00:00 2001 From: Jolan Rensen Date: Tue, 22 Oct 2024 17:52:33 +0200 Subject: [PATCH] added "update status to PR" step for gh action bot --- .github/workflows/generated-sources.yml | 84 +++++++++++++++++++------ 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/.github/workflows/generated-sources.yml b/.github/workflows/generated-sources.yml index a6cae497d..95ac75794 100644 --- a/.github/workflows/generated-sources.yml +++ b/.github/workflows/generated-sources.yml @@ -11,15 +11,13 @@ on: jobs: build: + 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/cancel-workflow-action@0.9.1 - with: - access_token: ${{ github.token }} - - name: Checkout repository uses: actions/checkout@v4 @@ -34,12 +32,35 @@ jobs: git config --global user.email "actions@github.com" git config --global user.name "GitHub Actions" + - name: TEST! Update status to PR + uses: actions/github-script@v7 + 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: "build", + head_sha: context.sha, + conclusion: "success", + details_url: $parameter_url, + status: "completed", + output: { + title: "Check 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 }})." + }, + }); + - 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)" + 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,7 +70,7 @@ 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)" + echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: Remove old comments uses: actions/github-script@v7 @@ -61,32 +82,55 @@ jobs: const {owner, repo} = context.repo; const comments = await github.rest.issues.listComments({ - issue_number, - owner, - repo, + issue_number, + owner, + repo, }); const botComments = comments.data.filter( - (comment) => comment.user.login === 'github-actions[bot]' + (comment) => comment.user.login === 'github-actions[bot]' ); for (const comment of botComments) { - await github.rest.issues.deleteComment({ - comment_id: comment.id, - owner, - repo, - }); + await github.rest.issues.deleteComment({ + comment_id: comment.id, + owner, + repo, + }); } - - name: Add comment to PR + # - 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: | - github.rest.issues.createComment({ - issue_number: context.issue.number, + 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: "build", + head_sha: context.sha, + conclusion: "success", + status: "completed", + output: { + title: "Check 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 }})." + }, });