| name: PR badges |
| |
| on: |
| pull_request_target: |
| branches: |
| - 'feature/*' |
| - 'main' |
| - '24.lts.1\+' |
| - '23.lts.1\+' |
| - '22.lts.1\+' |
| - '21.lts.1\+' |
| - '20.lts.1\+' |
| - '19.lts.1\+' |
| - 'rc_11' |
| - 'COBALT_9' |
| |
| concurrency: |
| group: '${{ github.workflow }}-${{ github.event_name }}-${{ inputs.platform }} @ ${{ github.event.pull_request.number || github.sha }}' |
| cancel-in-progress: true |
| |
| permissions: |
| pull-requests: write |
| |
| jobs: |
| comment: |
| runs-on: ubuntu-latest |
| env: |
| GITHUB_SERVER_URL: ${{github.server_url}} |
| GITHUB_REPO: ${{github.repository}} |
| GITHUB_HEAD_REF: ${{ github.head_ref }} |
| steps: |
| - uses: actions/github-script@v6 |
| with: |
| script: | |
| // Get env vars. |
| const { GITHUB_SERVER_URL, GITHUB_REPO, GITHUB_HEAD_REF } = process.env |
| // Get the existing comments. |
| const {data: comments} = await github.rest.issues.listComments({ |
| owner: context.repo.owner, |
| repo: context.repo.repo, |
| issue_number: context.payload.number, |
| }) |
| |
| // Find any comment already made by the bot. |
| const botComment = comments.find(comment => { |
| return comment.user.type === 'Bot' && comment.body.includes('Build Status') |
| }) |
| const workflows = ["lint", "android", "evergreen", "linux", "raspi-2", "stub", "win32"] |
| var commentBody = ` |
| ## Build Status |
| | Workflow | Status | |
| | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| ` |
| for (let i = 0; i < workflows.length; i++) { |
| commentBody += "| " + workflows[i] + " | [![" + workflows[i] + "](" + `${GITHUB_SERVER_URL}` + "/" + `${GITHUB_REPO}` + "/actions/workflows/" + workflows[i] + ".yaml/badge.svg?branch=" + `${GITHUB_HEAD_REF}` + ")](" + `${GITHUB_SERVER_URL}` + "/" + `${GITHUB_REPO}` + "/actions/workflows/" + workflows[i] + ".yaml?query=branch%3A" + `${GITHUB_HEAD_REF}` + ") |\n" |
| } |
| if (botComment) { |
| await github.rest.issues.deleteComment({ |
| owner: context.repo.owner, |
| repo: context.repo.repo, |
| comment_id: botComment.id, |
| }) |
| } |
| await github.rest.issues.createComment({ |
| owner: context.repo.owner, |
| repo: context.repo.repo, |
| issue_number: context.payload.number, |
| body: commentBody |
| }) |