|
| 1 | +name: CI - PR Comments |
| 2 | + |
| 3 | + # This workflow has write permissions on the repo |
| 4 | + # It must not checkout a PR and run untrusted code |
| 5 | + |
| 6 | +# Also requesting write permissions on PR to be able to comment |
| 7 | +permissions: |
| 8 | + pull-requests: 'write' |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_run: |
| 12 | + workflows: ["CI"] |
| 13 | + types: |
| 14 | + - completed |
| 15 | + |
| 16 | +jobs: |
| 17 | + example-run: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: > |
| 20 | + github.event.workflow_run.event == 'pull_request' && |
| 21 | + github.event.workflow_run.conclusion == 'failure' |
| 22 | + steps: |
| 23 | + - name: 'Download artifact' |
| 24 | + id: find-artifact |
| 25 | + uses: actions/github-script@v6 |
| 26 | + with: |
| 27 | + result-encoding: string |
| 28 | + script: | |
| 29 | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 30 | + owner: context.repo.owner, |
| 31 | + repo: context.repo.repo, |
| 32 | + run_id: ${{github.event.workflow_run.id }}, |
| 33 | + }); |
| 34 | + var matchArtifacts = artifacts.data.artifacts.filter((artifact) => { |
| 35 | + return artifact.name == "example-run" |
| 36 | + }); |
| 37 | + if (matchArtifacts.length == 0) { return "false" } |
| 38 | + var matchArtifact = matchArtifacts[0]; |
| 39 | + var download = await github.rest.actions.downloadArtifact({ |
| 40 | + owner: context.repo.owner, |
| 41 | + repo: context.repo.repo, |
| 42 | + artifact_id: matchArtifact.id, |
| 43 | + archive_format: 'zip', |
| 44 | + }); |
| 45 | + var fs = require('fs'); |
| 46 | + fs.writeFileSync('${{github.workspace}}/example-run.zip', Buffer.from(download.data)); |
| 47 | + return "true" |
| 48 | + - run: unzip example-run.zip |
| 49 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 50 | + - name: 'Comment on PR' |
| 51 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 52 | + uses: actions/github-script@v6 |
| 53 | + with: |
| 54 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + script: | |
| 56 | + var fs = require('fs'); |
| 57 | + var issue_number = Number(fs.readFileSync('./NR')); |
| 58 | + var last_example_run = fs.readFileSync('./last_example_run'); |
| 59 | + await github.rest.issues.createComment({ |
| 60 | + owner: context.repo.owner, |
| 61 | + repo: context.repo.repo, |
| 62 | + issue_number: issue_number, |
| 63 | + body: 'Example ' + last_example_run + ' failed to run, please try running it locally and check the result.' |
| 64 | + }); |
| 65 | +
|
| 66 | + missing-examples: |
| 67 | + runs-on: ubuntu-latest |
| 68 | + if: > |
| 69 | + github.event.workflow_run.event == 'pull_request' && |
| 70 | + github.event.workflow_run.conclusion == 'failure' |
| 71 | + steps: |
| 72 | + - name: 'Download artifact' |
| 73 | + id: find-artifact |
| 74 | + uses: actions/github-script@v6 |
| 75 | + with: |
| 76 | + result-encoding: string |
| 77 | + script: | |
| 78 | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 79 | + owner: context.repo.owner, |
| 80 | + repo: context.repo.repo, |
| 81 | + run_id: ${{github.event.workflow_run.id }}, |
| 82 | + }); |
| 83 | + var matchArtifacts = artifacts.data.artifacts.filter((artifact) => { |
| 84 | + return artifact.name == "missing-examples" |
| 85 | + }); |
| 86 | + if (matchArtifacts.length == 0) { return "false" } |
| 87 | + var matchArtifact = matchArtifacts[0]; |
| 88 | + var download = await github.rest.actions.downloadArtifact({ |
| 89 | + owner: context.repo.owner, |
| 90 | + repo: context.repo.repo, |
| 91 | + artifact_id: matchArtifact.id, |
| 92 | + archive_format: 'zip', |
| 93 | + }); |
| 94 | + var fs = require('fs'); |
| 95 | + fs.writeFileSync('${{github.workspace}}/missing-examples.zip', Buffer.from(download.data)); |
| 96 | + return "true" |
| 97 | + - run: unzip missing-examples.zip |
| 98 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 99 | + - name: 'Comment on PR' |
| 100 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 101 | + uses: actions/github-script@v6 |
| 102 | + with: |
| 103 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + script: | |
| 105 | + var fs = require('fs'); |
| 106 | + var issue_number = Number(fs.readFileSync('./NR')); |
| 107 | + if (existsSync('./missing-metadata')) { |
| 108 | + await github.rest.issues.createComment({ |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + issue_number: issue_number, |
| 112 | + body: 'You added a new example but didn't add metadata for it. Please update the root Cargo.toml file.' |
| 113 | + }); |
| 114 | + } |
| 115 | + if (existsSync('./missing-update')) { |
| 116 | + await github.rest.issues.createComment({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + issue_number: issue_number, |
| 120 | + body: 'You added a new example but didn't update the readme. Please run `cargo run -p build-example-pages -- update` to update it, and commit the file change.' |
| 121 | + }); |
| 122 | + } |
| 123 | +
|
| 124 | + msrv: |
| 125 | + runs-on: ubuntu-latest |
| 126 | + if: > |
| 127 | + github.event.workflow_run.event == 'pull_request' && |
| 128 | + github.event.workflow_run.conclusion == 'failure' |
| 129 | + steps: |
| 130 | + - name: 'Download artifact' |
| 131 | + id: find-artifact |
| 132 | + uses: actions/github-script@v6 |
| 133 | + with: |
| 134 | + result-encoding: string |
| 135 | + script: | |
| 136 | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ |
| 137 | + owner: context.repo.owner, |
| 138 | + repo: context.repo.repo, |
| 139 | + run_id: ${{github.event.workflow_run.id }}, |
| 140 | + }); |
| 141 | + var matchArtifacts = artifacts.data.artifacts.filter((artifact) => { |
| 142 | + return artifact.name == "msrv" |
| 143 | + }); |
| 144 | + if (matchArtifacts.length == 0) { return "false" } |
| 145 | + var matchArtifact = matchArtifacts[0]; |
| 146 | + var download = await github.rest.actions.downloadArtifact({ |
| 147 | + owner: context.repo.owner, |
| 148 | + repo: context.repo.repo, |
| 149 | + artifact_id: matchArtifact.id, |
| 150 | + archive_format: 'zip', |
| 151 | + }); |
| 152 | + var fs = require('fs'); |
| 153 | + fs.writeFileSync('${{github.workspace}}/msrv.zip', Buffer.from(download.data)); |
| 154 | + return "true" |
| 155 | + - run: unzip msrv.zip |
| 156 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 157 | + - name: 'Comment on PR' |
| 158 | + if: ${{ steps.find-artifact.outputs.result == 'true' }} |
| 159 | + uses: actions/github-script@v6 |
| 160 | + with: |
| 161 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 162 | + script: | |
| 163 | + var fs = require('fs'); |
| 164 | + var issue_number = Number(fs.readFileSync('./NR')); |
| 165 | + await github.rest.issues.createComment({ |
| 166 | + owner: context.repo.owner, |
| 167 | + repo: context.repo.repo, |
| 168 | + issue_number: issue_number, |
| 169 | + body: 'Your PR increases Bevy Minimum Supported Rust Version. Please update the `rust-version` field in the root Cargo.toml file.' |
| 170 | + }); |
0 commit comments