Fix CI code for comment.yml (#404)

This commit is contained in:
hanbings
2024-06-23 18:29:26 -04:00
committed by GitHub
parent d329702b69
commit 5b19ea2125
2 changed files with 80 additions and 30 deletions
+27 -28
View File
@@ -1,15 +1,17 @@
on:
workflow_run:
workflows: [External testsuites]
types: [completed]
workflow_run:
workflows: [External-testsuites]
types: [completed]
name: Comment Test results on the PR
permissions: {}
jobs:
upload-pr-comment:
if: ${{ github.event.workflow_run.event == 'pull_request' }}
name: Upload PR comment
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
permissions:
actions: read
pull-requests: write
@@ -19,41 +21,37 @@ jobs:
uses: actions/github-script@v7
with:
script: |
let runs = await github.rest.checks.listForRef({
let artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
ref: '${{ github.event.pull_request.head.sha }}'
run_id: ${{ github.event.workflow_run.id }},
});
let names = ['Run GNU findutils tests', 'Run BFS tests'];
let results = [];
runs.data.check_runs.filter(check => names.includes(check.name)).forEach(run => results.push(run));
// List all artifacts
let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "comment"
})[0];
let annotations = { data: []};
for (let result of results) {
let run = await github.rest.checks.listAnnotations({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: result.id
});
run.data.forEach(data => {
annotations.data.push({
run: result.name,
annotation: data
});
});
}
// Download the artifact to github.workspace
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/annotations.json', JSON.stringify(annotations));
fs.writeFileSync('${{ github.workspace }}/comment.zip', Buffer.from(download.data));
- run: unzip comment.zip
- name: Comment on PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let annotations = JSON.parse(fs.readFileSync('${{ github.workspace }}/annotations.json', 'utf8'));
let annotations = JSON.parse(fs.readFileSync('./annotations.json', 'utf8'));
let annotationContent = annotations
.data
@@ -62,9 +60,10 @@ jobs:
console.log(annotationContent);
// Comment on the PR
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.number }},
body: 'GNU testsuite comparison:\n```\n' + annotationContent + '```'
issue_number: annotations.pull_request_number,
body: 'GNU testsuite comparison:\n```\n' + annotationContent + '\n```\n'
});
+53 -2
View File
@@ -1,6 +1,6 @@
on: [push, pull_request]
name: External testsuites
name: External-testsuites
jobs:
gnu-tests:
@@ -146,4 +146,55 @@ jobs:
shell: bash
run: |
mv dl/bfs-result.json latest-bfs-result.json
python findutils/util/compare_bfs_result.py
python findutils/util/compare_bfs_result.py
upload-annotations:
name: Upload annotations
runs-on: ubuntu-latest
needs: [gnu-tests, bfs-tests]
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: List Annotations
uses: actions/github-script@v7
with:
script: |
let runs = await github.rest.checks.listForRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: '${{ github.event.pull_request.head.sha }}'
});
let names = ['Run GNU findutils tests', 'Run BFS tests'];
let results = [];
runs.data.check_runs.filter(check => names.includes(check.name)).forEach(run => results.push(run));
let annotations = { data: [], pull_request_number: '${{ github.event.number }}' };
for (let result of results) {
let run = await github.rest.checks.listAnnotations({
owner: context.repo.owner,
repo: context.repo.repo,
check_run_id: result.id
});
run.data.forEach(data => {
annotations.data.push({
run: result.name,
annotation: data
});
});
}
// Remove duplicate items.
annotations.data = annotations.data.filter((value, index, self) =>
self.findIndex(v => v.annotation.message === value.annotation.message) === index);
let fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/annotations.json', JSON.stringify(annotations));
- name: Upload annotations
uses: actions/upload-artifact@v4
with:
name: comment
path: annotations.json