Skip to content

Add artifact links to pull request #134

Add artifact links to pull request

Add artifact links to pull request #134

Workflow file for this run

name: Add artifact links to pull request
on:
workflow_run:
workflows: ["Build IITC Button"]
types: [completed]
workflow_dispatch:
jobs:
comment-links:
runs-on: ubuntu-latest
steps:
- name: Get artifact list from API
id: get-artifacts
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const runId = ${{ github.event.workflow_run.id }};
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
artifacts.data.artifacts.forEach((artifact, index) => {
const nameVar = `artifact${index + 1}`;
const displayNameVar = `displayArtifact${index + 1}`;
const urlVar = `url${index + 1}`;
let displayName = artifact.name.endsWith('-artifacts') ? `**${artifact.name}**` : artifact.name;
core.exportVariable(nameVar, artifact.name);
core.exportVariable(displayNameVar, displayName);
core.exportVariable(urlVar, `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/artifacts/${artifact.id}`);
});
core.exportVariable("firstArtifactId", artifacts.data.artifacts[0].id);
- name: Download first artifact
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: ${{ env.firstArtifactId }},
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/build.zip`, Buffer.from(download.data));
- name: Extract PR number from artifact
run: |
unzip build.zip
if [ -f ".metadata/pr_number" ]; then
PR_NUMBER=$(cat .metadata/pr_number)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
fi
- name: Comment with artifact links for PR
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ env.PR_NUMBER != '' }}
with:
header: pr_artifacts
number: ${{ env.PR_NUMBER }}
message: |
Build completed successfully. Below are the download links for the build artifacts:
| Artifact Name | Download Link |
| ------------- | ------------- |
| ${{ env.displayArtifact1 }} | [Download](${{ env.url1 }}) |
| ${{ env.displayArtifact2 }} | [Download](${{ env.url2 }}) |
| ${{ env.displayArtifact3 }} | [Download](${{ env.url3 }}) |
| ${{ env.displayArtifact4 }} | [Download](${{ env.url4 }}) |
| ${{ env.displayArtifact5 }} | [Download](${{ env.url5 }}) |
Artifacts will only be retained for 90 days.