2023-01-29 17:16:29 +00:00
name : CI - PR Comments
# This workflow has write permissions on the repo
# It must not checkout a PR and run untrusted code
# Also requesting write permissions on PR to be able to comment
permissions :
pull-requests : 'write'
on :
workflow_run :
workflows : [ "CI" ]
types :
- completed
jobs :
missing-examples :
runs-on : ubuntu-latest
if : >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps :
- name : 'Download artifact'
id : find-artifact
uses : actions/github-script@v6
with :
result-encoding : string
script : |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : ${{github.event.workflow_run.id }},
});
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "missing-examples"
});
if (matchArtifacts.length == 0) { return "false" }
var matchArtifact = matchArtifacts[0];
var download = await github.rest.actions.downloadArtifact({
owner : context.repo.owner,
repo : context.repo.repo,
artifact_id : matchArtifact.id,
archive_format : 'zip' ,
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/missing-examples.zip', Buffer.from(download.data));
return "true"
- run : unzip missing-examples.zip
if : ${{ steps.find-artifact.outputs.result == 'true' }}
- name : 'Comment on PR'
if : ${{ steps.find-artifact.outputs.result == 'true' }}
uses : actions/github-script@v6
with :
github-token : ${{ secrets.GITHUB_TOKEN }}
script : |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./NR'));
2023-01-29 23:05:33 +00:00
if (fs.existsSync('./missing-metadata')) {
2023-01-29 17:16:29 +00:00
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
2023-01-29 23:05:33 +00:00
body : 'You added a new example but didn\'t add metadata for it. Please update the root Cargo.toml file.'
2023-01-29 17:16:29 +00:00
});
}
2023-01-29 23:05:33 +00:00
if (fs.existsSync('./missing-update')) {
2023-01-29 17:16:29 +00:00
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
2023-08-07 23:08:19 +00:00
body : 'The generated `examples/README.md` is out of sync with the example metadata in `Cargo.toml` or the example readme template. Please run `cargo run -p build-templated-pages -- update examples` to update it, and commit the file change.'
2023-02-28 14:24:47 +00:00
});
}
missing-features :
runs-on : ubuntu-latest
if : >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps :
- name : 'Download artifact'
id : find-artifact
uses : actions/github-script@v6
with :
result-encoding : string
script : |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : ${{github.event.workflow_run.id }},
});
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "missing-features"
});
if (matchArtifacts.length == 0) { return "false" }
var matchArtifact = matchArtifacts[0];
var download = await github.rest.actions.downloadArtifact({
owner : context.repo.owner,
repo : context.repo.repo,
artifact_id : matchArtifact.id,
archive_format : 'zip' ,
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/missing-features.zip', Buffer.from(download.data));
return "true"
- run : unzip missing-features.zip
if : ${{ steps.find-artifact.outputs.result == 'true' }}
- name : 'Comment on PR'
if : ${{ steps.find-artifact.outputs.result == 'true' }}
uses : actions/github-script@v6
with :
github-token : ${{ secrets.GITHUB_TOKEN }}
script : |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./NR'));
if (fs.existsSync('./missing-features')) {
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
body : 'You added a new feature but didn\'t add a description for it. Please update the root Cargo.toml file.'
});
}
if (fs.existsSync('./missing-update')) {
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
body : 'You added a new feature but didn\'t update the readme. Please run `cargo run -p build-templated-pages -- update features` to update it, and commit the file change.'
2023-01-29 17:16:29 +00:00
});
}
msrv :
runs-on : ubuntu-latest
if : >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'failure'
steps :
- name : 'Download artifact'
id : find-artifact
uses : actions/github-script@v6
with :
result-encoding : string
script : |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner : context.repo.owner,
repo : context.repo.repo,
run_id : ${{github.event.workflow_run.id }},
});
var matchArtifacts = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "msrv"
});
if (matchArtifacts.length == 0) { return "false" }
var matchArtifact = matchArtifacts[0];
var download = await github.rest.actions.downloadArtifact({
owner : context.repo.owner,
repo : context.repo.repo,
artifact_id : matchArtifact.id,
archive_format : 'zip' ,
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/msrv.zip', Buffer.from(download.data));
return "true"
- run : unzip msrv.zip
if : ${{ steps.find-artifact.outputs.result == 'true' }}
- name : 'Comment on PR'
if : ${{ steps.find-artifact.outputs.result == 'true' }}
uses : actions/github-script@v6
with :
github-token : ${{ secrets.GITHUB_TOKEN }}
script : |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('./NR'));
await github.rest.issues.createComment({
owner : context.repo.owner,
repo : context.repo.repo,
issue_number : issue_number,
body : 'Your PR increases Bevy Minimum Supported Rust Version. Please update the `rust-version` field in the root Cargo.toml file.'
});