mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 23:59:08 +00:00
feat: add automated PR comments for build artifacts (#1100)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
103
.github/workflows/artifact-comment.yml
vendored
103
.github/workflows/artifact-comment.yml
vendored
@@ -1,12 +1,17 @@
|
||||
name: 📝 Artifact Comment on PR
|
||||
|
||||
concurrency:
|
||||
group: artifact-comment-${{ github.event.workflow_run.head_branch }}
|
||||
cancel-in-progress: true
|
||||
group: artifact-comment-${{ github.event.workflow_run.id }}
|
||||
cancel-in-progress: false
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
workflow_run:
|
||||
workflows: ["🤖 iOS IPA Build (Phone + TV)", "🤖 Android APK Build (Phone + TV)"]
|
||||
workflows:
|
||||
- "🏗️ Build iOS IPA (phone)"
|
||||
- "🏗️ Build iOS IPA (tv)"
|
||||
- "🏗️ Build Android APK (phone)"
|
||||
- "🏗️ Build Android APK (tv)"
|
||||
types:
|
||||
- completed
|
||||
|
||||
@@ -24,33 +29,39 @@ jobs:
|
||||
uses: actions/github-script@v8
|
||||
with:
|
||||
script: |
|
||||
console.log('Workflow run event:', JSON.stringify(github.event.workflow_run, null, 2));
|
||||
|
||||
// Find PR associated with this commit
|
||||
const { data: pullRequests } = await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
commit_sha: "${{ github.event.workflow_run.head_sha }}"
|
||||
});
|
||||
|
||||
|
||||
if (pullRequests.length === 0) {
|
||||
core.setFailed('No pull request found for this commit');
|
||||
console.log('No pull request found for commit: ${{ github.event.workflow_run.head_sha }}');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const pr = pullRequests[0];
|
||||
const runId = "${{ github.event.workflow_run.id }}";
|
||||
|
||||
|
||||
console.log(`Found PR #${pr.number} for commit ${pr.head.sha.substring(0, 7)}`);
|
||||
|
||||
// Get artifacts from the workflow run
|
||||
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
run_id: runId
|
||||
});
|
||||
|
||||
if (artifacts.artifacts.length === 0) {
|
||||
|
||||
console.log(`Found ${artifacts?.artifacts?.length || 0} artifacts`);
|
||||
|
||||
if (!artifacts || artifacts.artifacts.length === 0) {
|
||||
console.log('No artifacts found for this run');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Sort and categorize artifacts
|
||||
const androidArtifacts = artifacts.artifacts
|
||||
.filter(a => a.name.includes('android'))
|
||||
@@ -58,51 +69,59 @@ jobs:
|
||||
const iosArtifacts = artifacts.artifacts
|
||||
.filter(a => a.name.includes('ios'))
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
|
||||
console.log(`Android artifacts: ${androidArtifacts.length}, iOS artifacts: ${iosArtifacts.length}`);
|
||||
|
||||
// Build comment body with table format
|
||||
let commentBody = `## 📱 Build Artifacts Ready!\n\n`;
|
||||
commentBody += `✅ **Workflow completed successfully** for PR #${pr.number}\n`;
|
||||
commentBody += `📦 **${artifacts.artifacts.length} artifacts** generated from commit [\`${pr.head.sha.substring(0, 7)}\`](https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${pr.head.sha})\n\n`;
|
||||
|
||||
// Create table for better organization
|
||||
commentBody += `| Platform | Device Type | Download Link |\n`;
|
||||
commentBody += `|----------|-------------|---------------|\n`;
|
||||
|
||||
// Add Android artifacts
|
||||
androidArtifacts.forEach(artifact => {
|
||||
const isTV = artifact.name.includes('tv');
|
||||
const deviceType = isTV ? '📺 Android TV' : '📱 Android Phone';
|
||||
const nightlyLink = `https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/${artifact.name}.zip`;
|
||||
commentBody += `| 🤖 Android | ${deviceType} | [📥 Download APK](${nightlyLink}) |\n`;
|
||||
});
|
||||
|
||||
// Add iOS artifacts
|
||||
iosArtifacts.forEach(artifact => {
|
||||
const isTV = artifact.name.includes('tv');
|
||||
const deviceType = isTV ? '📺 Apple TV' : '📱 iPhone/iPad';
|
||||
const nightlyLink = `https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/${artifact.name}.zip`;
|
||||
commentBody += `| 🍎 iOS | ${deviceType} | [📥 Download IPA](${nightlyLink}) |\n`;
|
||||
});
|
||||
|
||||
commentBody += `\n`;
|
||||
commentBody += `### 🔧 Installation Instructions\n\n`;
|
||||
commentBody += `- **Android APK**: Download and install directly on your device (enable "Install from unknown sources")\n`;
|
||||
commentBody += `- **iOS IPA**: Install using [AltStore](https://altstore.io/), [Sideloadly](https://sideloadly.io/), or Xcode\n\n`;
|
||||
commentBody += `> ⚠️ **Note**: Artifacts expire in 7 days from build date\n\n`;
|
||||
commentBody += `<sub>*Auto-generated by [GitHub Actions](${context.payload.workflow_run.html_url})*</sub>`;
|
||||
|
||||
|
||||
if (androidArtifacts.length === 0 && iosArtifacts.length === 0) {
|
||||
commentBody += `⚠️ No mobile app artifacts found in this build.\n\n`;
|
||||
} else {
|
||||
// Create table for better organization
|
||||
commentBody += `| Platform | Device Type | Download Link |\n`;
|
||||
commentBody += `|----------|-------------|---------------|\n`;
|
||||
|
||||
// Add Android artifacts
|
||||
androidArtifacts.forEach(artifact => {
|
||||
const isTV = artifact.name.includes('tv');
|
||||
const deviceType = isTV ? '📺 Android TV' : '📱 Android Phone';
|
||||
const nightlyLink = `https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/${artifact.name}.zip`;
|
||||
commentBody += `| 🤖 Android | ${deviceType} | [📥 Download APK](${nightlyLink}) |\n`;
|
||||
});
|
||||
|
||||
// Add iOS artifacts
|
||||
iosArtifacts.forEach(artifact => {
|
||||
const isTV = artifact.name.includes('tv');
|
||||
const deviceType = isTV ? '📺 Apple TV' : '📱 iPhone/iPad';
|
||||
const nightlyLink = `https://nightly.link/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}/${artifact.name}.zip`;
|
||||
commentBody += `| 🍎 iOS | ${deviceType} | [📥 Download IPA](${nightlyLink}) |\n`;
|
||||
});
|
||||
|
||||
commentBody += `\n`;
|
||||
commentBody += `### 🔧 Installation Instructions\n\n`;
|
||||
commentBody += `- **Android APK**: Download and install directly on your device (enable "Install from unknown sources")\n`;
|
||||
commentBody += `- **iOS IPA**: Install using [AltStore](https://altstore.io/), [Sideloadly](https://sideloadly.io/), or Xcode\n\n`;
|
||||
commentBody += `> ⚠️ **Note**: Artifacts expire in 7 days from build date\n\n`;
|
||||
}
|
||||
|
||||
commentBody += `<sub>*Auto-generated by [GitHub Actions](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId})*</sub>`;
|
||||
commentBody += `\n<!-- streamyfin-artifact-comment -->`;
|
||||
|
||||
// Find existing bot comment to update
|
||||
const { data: comments } = await github.rest.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number
|
||||
});
|
||||
|
||||
|
||||
const botComment = comments.find(comment =>
|
||||
comment.user.type === 'Bot' &&
|
||||
comment.body.includes('Build Artifacts Ready!')
|
||||
comment.body.includes('<!-- streamyfin-artifact-comment -->')
|
||||
);
|
||||
|
||||
|
||||
if (botComment) {
|
||||
// Update existing comment
|
||||
await github.rest.issues.updateComment({
|
||||
|
||||
Reference in New Issue
Block a user