Skip to content

Artiweb Comment

Artiweb Comment #49

Workflow file for this run

name: Artiweb Comment
on:
workflow_run:
workflows: [Tests]
types:
- completed
# taken from https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#using-data-from-the-triggering-workflow
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
id: da
uses: actions/github-script@v7
with:
script: |
if (context.payload.workflow_run === undefined) {
core.setFailed("No workflow run found");
}
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
const testArtifact = allArtifacts.data.artifacts.find((artifact) => {
return artifact.name == "test-results"
});
if (testArtifact !== undefined) {
core.info("Found test-results artifact id: " + testArtifact.id);
core.setOutput("test-artifact-id", testArtifact.id);
} else {
core.info("Artifact test-results was not found");
}
const numberArtifact = allArtifacts.data.artifacts.find((artifact) => {
return artifact.name == "pr-number"
});
if (numberArtifact !== undefined) {
core.info("Found pr-number artifact id: " + numberArtifact.id);
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: numberArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/pr_number.zip`, Buffer.from(download.data));
} else {
core.setFailed("Artifact pr-number was not found");
}
- name: 'Unzip artifact'
run: unzip pr_number.zip
- name: 'Read pr number'
id: rpn
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let fs = require('fs');
let issue_number_text = fs.readFileSync('./pr_number', 'utf8');
core.info("Found pr number \"" + issue_number_text + "\"");
core.setOutput("pr-number", issue_number_text === "" ? "" : Number(issue_number_text));
- name: Find Comment
if: ${{ steps.rpn.outputs.pr-number != '' }}
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ steps.rpn.outputs.pr-number }}
comment-author: 'github-actions[bot]'
body-includes: Artiweb
- name: Create or update comment
if: ${{ steps.rpn.outputs.pr-number != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ steps.rpn.outputs.pr-number }}
body: |
Thank you for your contribution.
The test artifacts are available on [Artiweb](e8e3f762-a110-4e21-bc41-cacb5f3a3a50.ka.bw-cloud-instance.org/${{steps.rpn.outputs.pr-number}}/).
The newest artifact is [here](e8e3f762-a110-4e21-bc41-cacb5f3a3a50.ka.bw-cloud-instance.org/${{steps.rpn.outputs.pr-number}}/${{steps.da.outputs.test-artifact-id}}/).
edit-mode: replace