mirror of
https://github.com/uutils/findutils.git
synced 2026-06-10 15:48:30 -07:00
Fix CI code for comment.yml (#404)
This commit is contained in:
@@ -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'
|
||||
});
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user