@@ -22,11 +22,10 @@ jobs:
2222 - name : List available artifacts with detailed logs
2323 uses : actions/github-script@v7
2424 with :
25- github-token : ${{secrets.GITHUB_TOKEN}}
25+ github-token : ${{ secrets.GITHUB_TOKEN }}
2626 script : |
2727 const runId = ${{ github.event.workflow_run.id }};
2828 console.log(`Fetching artifacts for workflow run ID: ${runId}`);
29-
3029 const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
3130 owner: context.repo.owner,
3231 repo: context.repo.repo,
@@ -40,68 +39,76 @@ jobs:
4039 - name : Download PR Number Artifact
4140 uses : actions/github-script@v7
4241 with :
43- github-token : ${{secrets.GITHUB_TOKEN}}
42+ github-token : ${{ secrets.GITHUB_TOKEN }}
4443 script : |
4544 const fs = require('fs');
4645 const path = require('path');
4746 const runId = ${{ github.event.workflow_run.id }};
4847 const artifactName = 'pr-number';
49-
50- console.log(`Downloading artifact ${artifactName} from workflow run ID: ${runId}`);
51- const artifactData = await github.rest.actions.downloadArtifact({
52- owner: context.repo.owner,
53- repo: context.repo.repo,
54- artifact_id: (await github.rest.actions.listWorkflowRunArtifacts({
48+ console.log(`Checking for artifact ${artifactName} from workflow run ID: ${runId}`);
49+ try {
50+ const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
5551 owner: context.repo.owner,
5652 repo: context.repo.repo,
5753 run_id: runId
58- })).data.artifacts.find(a => a.name === artifactName).id,
59- archive_format: 'zip',
60- });
61-
62- const artifactPath = path.join(process.env.GITHUB_WORKSPACE, `${artifactName}.zip`);
63- fs.writeFileSync(artifactPath, Buffer.from(artifactData.data));
64-
65- console.log(`Artifact ${artifactName} downloaded to ${artifactPath}`);
66- require('child_process').execSync(`unzip -o ${artifactPath} -d ${process.env.GITHUB_WORKSPACE}`);
67- const prNumber = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'pr_number.txt'), 'utf8').trim();
68- console.log(`PR Number: ${prNumber}`);
54+ });
55+ const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);
56+ if (!artifact) {
57+ console.log(`Artifact '${artifactName}' not found, skipping download.`);
58+ return;
59+ }
60+ const artifactData = await github.rest.actions.downloadArtifact({
61+ owner: context.repo.owner,
62+ repo: context.repo.repo,
63+ artifact_id: artifact.id,
64+ archive_format: 'zip',
65+ });
66+ const artifactPath = path.join(process.env.GITHUB_WORKSPACE, `${artifactName}.zip`);
67+ fs.writeFileSync(artifactPath, Buffer.from(artifactData.data));
68+ console.log(`Artifact ${artifactName} downloaded to ${artifactPath}`);
69+ require('child_process').execSync(`unzip -o ${artifactPath} -d ${process.env.GITHUB_WORKSPACE}`);
70+ const prNumber = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'pr_number.txt'), 'utf8').trim();
71+ console.log(`PR Number: ${prNumber}`);
72+ } catch (error) {
73+ console.log(`Error occurred: ${error.message}`);
74+ console.log('Continuing workflow execution despite the error.');
75+ }
6976
7077 - name : Download Plagiarism Report Artifact from Another Workflow Run
7178 uses : actions/github-script@v7
7279 with :
73- github-token : ${{secrets.GITHUB_TOKEN}}
80+ github-token : ${{ secrets.GITHUB_TOKEN }}
7481 script : |
7582 const fs = require('fs');
7683 const path = require('path');
7784 const runId = ${{ github.event.workflow_run.id }};
7885 const artifactName = 'plagiarism-report';
79-
80- console.log(`Fetching artifacts for workflow run ID: ${runId}`);
81- const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
82- owner: context.repo.owner,
83- repo: context.repo.repo,
84- run_id: runId,
85- });
86-
87- const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);
88- if (!artifact) {
89- throw new Error(`Artifact with name ${artifactName} not found`);
86+ console.log(`Downloading artifact '${artifactName}' from workflow run ID: ${runId}`);
87+ try {
88+ const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
89+ owner: context.repo.owner,
90+ repo: context.repo.repo,
91+ run_id: runId
92+ });
93+ const artifact = artifacts.data.artifacts.find(a => a.name === artifactName);
94+ if (!artifact) {
95+ console.log(`Artifact '${artifactName}' not found, skipping download.`);
96+ return;
97+ }
98+ const artifactData = await github.rest.actions.downloadArtifact({
99+ owner: context.repo.owner,
100+ repo: context.repo.repo,
101+ artifact_id: artifact.id,
102+ archive_format: 'zip',
103+ });
104+ const artifactPath = path.join(process.env.GITHUB_WORKSPACE, `${artifactName}.zip`);
105+ fs.writeFileSync(artifactPath, Buffer.from(artifactData.data));
106+ console.log(`Artifact ${artifactName} downloaded to ${artifactPath}`);
107+ require('child_process').execSync(`unzip -o ${artifactPath} -d ${process.env.GITHUB_WORKSPACE}`);
108+ } catch (error) {
109+ console.log(`Error occurred: ${error.message}`);
110+ console.log('Continuing workflow execution despite the error.');
90111 }
91-
92- console.log(`Downloading artifact ${artifactName} from workflow run ID: ${runId}`);
93- const artifactData = await github.rest.actions.downloadArtifact({
94- owner: context.repo.owner,
95- repo: context.repo.repo,
96- artifact_id: artifact.id,
97- archive_format: 'zip',
98- });
99-
100- const artifactPath = path.join(process.env.GITHUB_WORKSPACE, `${artifactName}.zip`);
101- fs.writeFileSync(artifactPath, Buffer.from(artifactData.data));
102-
103- console.log(`Artifact ${artifactName} downloaded to ${artifactPath}`);
104- require('child_process').execSync(`unzip -o ${artifactPath} -d ${process.env.GITHUB_WORKSPACE}`);
105112
106113 - name : Check if Plagiarism Report Exists
107114 id : check-report
@@ -110,6 +117,7 @@ jobs:
110117 echo "REPORT_EXISTS=true" >> $GITHUB_ENV
111118 else
112119 echo "REPORT_EXISTS=false" >> $GITHUB_ENV
120+ fi
113121
114122 - name : Unzip Plagiarism Report Artifact
115123 if : env.REPORT_EXISTS == 'true'
@@ -119,7 +127,7 @@ jobs:
119127 id : fetch-comments
120128 uses : actions/github-script@v7
121129 with :
122- github-token : ${{secrets.GITHUB_TOKEN}}
130+ github-token : ${{ secrets.GITHUB_TOKEN }}
123131 script : |
124132 const fs = require('fs');
125133 const path = require('path');
@@ -137,21 +145,16 @@ jobs:
137145 if : env.REPORT_EXISTS == 'true' && steps.fetch-comments.outputs.result != 'true'
138146 uses : actions/github-script@v7
139147 with :
140- github-token : ${{secrets.GITHUB_TOKEN}}
148+ github-token : ${{ secrets.GITHUB_TOKEN }}
141149 script : |
142150 const fs = require('fs');
143151 const path = require('path');
144-
145152 const prNumber = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'pr_number.txt'), 'utf8').trim();
146153 const markdownPath = path.join(process.env.GITHUB_WORKSPACE, 'plagiarism-report.md');
147154 console.log(`Reading the Markdown report from: ${markdownPath}`);
148155 let markdownContent = fs.readFileSync(markdownPath, 'utf8');
149-
150- markdownContent = '[Plagiarism Check Result]\n\n' + markdownContent;
151-
152156 console.log("Fetching associated pull request...");
153157 console.log(`Found associated pull request: #${prNumber}`);
154-
155158 console.log("Posting the Markdown content as a comment...");
156159 const commentResponse = await github.rest.issues.createComment({
157160 issue_number: prNumber,
0 commit comments