Skip to content

Commit 6f3edde

Browse files
authored
fix: fixed comments on test ALL workflows (#592)
By default, GH API returns 30 results... it is possible the final `results.md` file is not part of the first 30 artifacts....
1 parent e5e22e0 commit 6f3edde

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

.github/workflows/comment-all.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Comment on test ALL PR
2+
3+
on:
4+
workflow_run:
5+
workflows:
6+
- "Test"
7+
types:
8+
- completed
9+
10+
jobs:
11+
comment:
12+
timeout-minutes: 30
13+
runs-on: ubuntu-latest
14+
if: >
15+
(github.event.workflow_run.event == 'pull_request' || github.event.workflow_run.event == 'workflow_run') &&
16+
github.event.workflow_run.conclusion == 'success'
17+
steps:
18+
- name: Download Artifacts
19+
uses: actions/github-script@v7
20+
id: download_artifacts
21+
with:
22+
script: |
23+
var prArtifactInfo = await github.rest.actions.listWorkflowRunArtifacts({
24+
owner: context.repo.owner,
25+
repo: context.repo.repo,
26+
run_id: ${{ github.event.workflow_run.id }},
27+
name: 'pr'
28+
});
29+
var prArtifact = prArtifactInfo.data.artifacts.filter((artifact) => {
30+
return artifact.name == "pr"
31+
})[0];
32+
var downloadedPrArtifact = await github.rest.actions.downloadArtifact({
33+
owner: context.repo.owner,
34+
repo: context.repo.repo,
35+
artifact_id: prArtifact.id,
36+
archive_format: 'zip',
37+
});
38+
var fs = require('fs');
39+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadedPrArtifact.data));
40+
41+
var resultArtifactInfo = await github.rest.actions.listWorkflowRunArtifacts({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
run_id: ${{ github.event.workflow_run.id }},
45+
name: 'results.md'
46+
});
47+
var compatibilityResult = resultArtifactInfo.data.artifacts.filter((artifact) => {
48+
return artifact.name.startsWith("results") && artifact.name.endsWith(".md")
49+
})[0];
50+
var downloadedResultsArtifact = await github.rest.actions.downloadArtifact({
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
artifact_id: compatibilityResult.id,
54+
archive_format: 'zip',
55+
});
56+
fs.writeFileSync('${{github.workspace}}/results.zip', Buffer.from(downloadedResultsArtifact.data));
57+
58+
core.setOutput('results_file_name', compatibilityResult.name);
59+
- name: Unpack artifacts
60+
run: |
61+
unzip pr.zip
62+
unzip results.zip
63+
- name: Comment on PR
64+
uses: actions/github-script@v7
65+
with:
66+
github-token: ${{ secrets.GITHUB_TOKEN }}
67+
script: |
68+
const fs = require('fs');
69+
var issue_number = Number(fs.readFileSync('./pr_info'));
70+
const results = fs.readFileSync('${{ steps.download_artifacts.outputs.results_file_name }}', 'utf-8');
71+
const commentBody = `## Apollo Federation Subgraph Compatibility Results\n${results}\n`;
72+
github.rest.issues.createComment({
73+
issue_number: issue_number,
74+
owner: context.repo.owner,
75+
repo: context.repo.repo,
76+
body: commentBody
77+
});

.github/workflows/comment.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: Comment on PR
33
on:
44
workflow_run:
55
workflows:
6-
- "Test"
76
- "Absinthe Federation Test"
87
- "Apollo Server Test"
98
- "Ariadne Test"
@@ -60,26 +59,25 @@ jobs:
6059
var prArtifact = artifacts.data.artifacts.filter((artifact) => {
6160
return artifact.name == "pr"
6261
})[0];
63-
var downloadPrArtifact = await github.rest.actions.downloadArtifact({
62+
var downloadedPrArtifact = await github.rest.actions.downloadArtifact({
6463
owner: context.repo.owner,
6564
repo: context.repo.repo,
6665
artifact_id: prArtifact.id,
6766
archive_format: 'zip',
6867
});
6968
var fs = require('fs');
70-
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadPrArtifact.data));
69+
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(downloadedPrArtifact.data));
7170
7271
var compatibilityResult = artifacts.data.artifacts.filter((artifact) => {
7372
return artifact.name.startsWith("results") && artifact.name.endsWith(".md")
7473
})[0];
75-
var downloadResultsArtifact = await github.rest.actions.downloadArtifact({
74+
var downloadedResultsArtifact = await github.rest.actions.downloadArtifact({
7675
owner: context.repo.owner,
7776
repo: context.repo.repo,
7877
artifact_id: compatibilityResult.id,
7978
archive_format: 'zip',
8079
});
81-
var fs = require('fs');
82-
fs.writeFileSync('${{github.workspace}}/results.zip', Buffer.from(downloadResultsArtifact.data));
80+
fs.writeFileSync('${{github.workspace}}/results.zip', Buffer.from(downloadedResultsArtifact.data));
8381
8482
core.setOutput('results_file_name', compatibilityResult.name);
8583
- name: Unpack artifacts

0 commit comments

Comments
 (0)