forked from hackclub/sprig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Post Message After Plagiarism Workflow
Added more logs on both workflows for better readability. Added a workaround as @grymmy suggested on sending results to artifact and download and post with another waiting GitHub job action. A New Workflow To Download Artifact And Post On Comment.
- Loading branch information
Showing
3 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Send Plagiarism Result On CI Complete | ||
|
||
on: | ||
workflow_run: | ||
workflows: ["Plagiarism Checker"] | ||
types: | ||
- completed | ||
|
||
jobs: | ||
on_pr_finish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Download Plagiarism Report Artifact | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: plagiarism-report | ||
|
||
- name: Post Markdown as Comment | ||
uses: actions/github-script@v7 | ||
env: | ||
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }} | ||
with: | ||
github-token: ${{secrets.GITHUB_TOKEN}} | ||
script: | | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
console.log("Reading the Markdown report from the artifact..."); | ||
const markdownContent = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'plagiarism_report.md'), 'utf8'); | ||
console.log("Fetching associated workflow run..."); | ||
const runId = process.env.WORKFLOW_RUN_ID; | ||
const runs = await github.actions.listWorkflowRuns({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
workflow_id: '73252545', | ||
}); | ||
const associatedRun = runs.data.workflow_runs.find(run => run.id == runId); | ||
if (!associatedRun || !associatedRun.pull_requests || associatedRun.pull_requests.length == 0) { | ||
console.log("No associated pull request found."); | ||
return; | ||
} | ||
const prNumber = associatedRun.pull_requests[0].number; | ||
console.log(`Found associated pull request: #${prNumber}`); | ||
console.log("Posting the Markdown content as a comment..."); | ||
await github.issues.createComment({ | ||
issue_number: prNumber, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: markdownContent | ||
}); | ||
console.log("Comment posted successfully."); |