mirror of
https://github.com/unraid/webgui.git
synced 2026-05-07 04:41:03 -05:00
233 lines
9.2 KiB
YAML
233 lines
9.2 KiB
YAML
name: Build PR Plugin
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'emhttp/**'
|
|
- '.github/workflows/pr-plugin-build.yml'
|
|
- '.github/scripts/**'
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
actions: read
|
|
|
|
jobs:
|
|
build-plugin:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Get changed files
|
|
id: changed-files
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# Get list of changed files in emhttp directory using PR SHAs
|
|
git diff --name-only "${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}" | grep '^emhttp/' > changed_files.txt || true
|
|
|
|
# Output for debugging
|
|
echo "Changed files:"
|
|
cat changed_files.txt
|
|
|
|
# Check if we have any changes
|
|
if [ ! -s "changed_files.txt" ]; then
|
|
echo "No emhttp files changed"
|
|
echo "has_changes=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "has_changes=true" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Generate plugin version
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
id: version
|
|
run: |
|
|
# Generate version with proper timestamp format: YYYY.MM.DD.HHMM
|
|
VERSION=$(date -u +"%Y.%m.%d.%H%M")
|
|
# Also keep PR info for reference
|
|
PR_VERSION="pr.${{ github.event.pull_request.number }}.$(git rev-parse --short HEAD)"
|
|
|
|
# Generate URLs with versioned TXZ to prevent SHA conflicts
|
|
S3_BASE_URL="${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_BASE_URL }}/pr-plugins/pr-${{ github.event.pull_request.number }}"
|
|
|
|
# Define filenames
|
|
LOCAL_TXZ_NAME="webgui-pr-${{ github.event.pull_request.number }}.tar.gz"
|
|
REMOTE_TXZ_NAME="webgui-pr-${{ github.event.pull_request.number }}-${VERSION}.tar.gz"
|
|
PLUGIN_NAME="webgui-pr-${{ github.event.pull_request.number }}.plg"
|
|
|
|
# TXZ gets unique versioned path to prevent SHA conflicts on updates
|
|
TXZ_URL="${S3_BASE_URL}/${REMOTE_TXZ_NAME}"
|
|
PLUGIN_URL="${S3_BASE_URL}/${PLUGIN_NAME}"
|
|
TXZ_KEY="pr-plugins/pr-${{ github.event.pull_request.number }}/${REMOTE_TXZ_NAME}"
|
|
PLUGIN_KEY="pr-plugins/pr-${{ github.event.pull_request.number }}/${PLUGIN_NAME}"
|
|
|
|
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
echo "pr_version=$PR_VERSION" >> $GITHUB_OUTPUT
|
|
echo "local_txz=$LOCAL_TXZ_NAME" >> $GITHUB_OUTPUT
|
|
echo "remote_txz=$REMOTE_TXZ_NAME" >> $GITHUB_OUTPUT
|
|
echo "plugin_name=$PLUGIN_NAME" >> $GITHUB_OUTPUT
|
|
echo "txz_url=$TXZ_URL" >> $GITHUB_OUTPUT
|
|
echo "plugin_url=$PLUGIN_URL" >> $GITHUB_OUTPUT
|
|
echo "txz_key=$TXZ_KEY" >> $GITHUB_OUTPUT
|
|
echo "plugin_key=$PLUGIN_KEY" >> $GITHUB_OUTPUT
|
|
echo "Generated version: $VERSION (PR: $PR_VERSION)"
|
|
|
|
- name: Create plugin package
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
run: |
|
|
# Create build directory
|
|
mkdir -p build/usr/local
|
|
|
|
# Copy changed files preserving directory structure
|
|
while IFS= read -r file; do
|
|
if [ -f "$file" ]; then
|
|
# Create directory structure in build
|
|
dir=$(dirname "$file")
|
|
mkdir -p "build/usr/local/$dir"
|
|
cp "$file" "build/usr/local/$dir/"
|
|
echo "Added: $file"
|
|
fi
|
|
done < changed_files.txt
|
|
|
|
# Create tarball - consistent filename for updates
|
|
cd build
|
|
echo "Creating tarball with contents:"
|
|
find usr/ -type f
|
|
tar -czf ../${{ steps.version.outputs.local_txz }} usr/
|
|
cd ..
|
|
|
|
# Generate file list for plugin
|
|
find build/usr/local/emhttp -type f | sed 's|^build||' > file_list.txt
|
|
echo "File list for plugin:"
|
|
cat file_list.txt
|
|
|
|
# Verify tarball contents
|
|
echo "Tarball contents:"
|
|
tar -tzf ${{ steps.version.outputs.local_txz }}
|
|
|
|
- name: Configure AWS CLI for R2
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
run: |
|
|
aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_PREVIEW_ACCESS_KEY_ID }}
|
|
aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_PREVIEW_SECRET_ACCESS_KEY }}
|
|
aws configure set region auto
|
|
|
|
- name: Upload TXZ to R2
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
id: upload-txz
|
|
run: |
|
|
# Upload to R2 with versioned filename to prevent SHA conflicts
|
|
aws s3 cp "${{ steps.version.outputs.local_txz }}" \
|
|
"s3://${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_NAME }}/${{ steps.version.outputs.txz_key }}" \
|
|
--endpoint-url "${{ secrets.CLOUDFLARE_S3_URL }}" \
|
|
--acl public-read
|
|
|
|
echo "Uploaded TXZ to: ${{ steps.version.outputs.txz_url }}"
|
|
|
|
- name: Generate plugin file with R2 URL
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
run: |
|
|
# Local file is non-versioned, but remote URL is versioned
|
|
# Pass local filename for SHA calculation and remote filename for download
|
|
bash .github/scripts/generate-pr-plugin.sh \
|
|
"${{ steps.version.outputs.version }}" \
|
|
"${{ github.event.pull_request.number }}" \
|
|
"$(git rev-parse --short HEAD)" \
|
|
"${{ steps.version.outputs.local_txz }}" \
|
|
"${{ steps.version.outputs.remote_txz }}" \
|
|
"${{ steps.version.outputs.txz_url }}" \
|
|
"${{ steps.version.outputs.plugin_url }}"
|
|
|
|
- name: Upload PLG to R2
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
id: upload-plg
|
|
run: |
|
|
# Upload PLG - overwrite existing for updates (consistent filename)
|
|
aws s3 cp "${{ steps.version.outputs.plugin_name }}" \
|
|
"s3://${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_NAME }}/${{ steps.version.outputs.plugin_key }}" \
|
|
--endpoint-url "${{ secrets.CLOUDFLARE_S3_URL }}" \
|
|
--acl public-read
|
|
|
|
echo "Uploaded PLG to: ${{ steps.version.outputs.plugin_url }}"
|
|
|
|
- name: Upload artifacts to GitHub (backup)
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: webgui-pr-plugin-${{ github.event.pull_request.number }}
|
|
path: |
|
|
webgui-pr-*.plg
|
|
webgui-pr-*.tar.gz
|
|
retention-days: 30
|
|
|
|
- name: Format changed files list
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
id: format-files
|
|
run: |
|
|
# Format the file list for the comment
|
|
echo "files<<EOF" >> $GITHUB_OUTPUT
|
|
cat changed_files.txt >> $GITHUB_OUTPUT
|
|
echo "EOF" >> $GITHUB_OUTPUT
|
|
|
|
# Debug output
|
|
echo "Changed files found:"
|
|
cat changed_files.txt
|
|
|
|
- name: Comment on PR
|
|
if: steps.changed-files.outputs.has_changes == 'true'
|
|
uses: marocchino/sticky-pull-request-comment@v2
|
|
with:
|
|
header: pr-plugin
|
|
message: |
|
|
## 🔧 PR Test Plugin Available
|
|
|
|
A test plugin has been generated for this PR that includes the modified files.
|
|
|
|
**Version:** `${{ steps.version.outputs.version }}`
|
|
**Build:** [View Workflow Run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
|
|
|
|
### 📥 Installation Instructions:
|
|
|
|
**Install via Unraid Web UI:**
|
|
1. Go to **Plugins → Install Plugin**
|
|
2. Copy and paste this URL:
|
|
```
|
|
${{ steps.version.outputs.plugin_url }}
|
|
```
|
|
3. Click **Install**
|
|
|
|
**Alternative: Direct Download**
|
|
- [📦 Download PLG](${{ steps.version.outputs.plugin_url }})
|
|
- [📦 Download TXZ](${{ steps.version.outputs.txz_url }})
|
|
|
|
### ⚠️ Important Notes:
|
|
|
|
- **Testing only:** This plugin is for testing PR changes
|
|
- **Backup included:** Original files are automatically backed up
|
|
- **Easy removal:** Files are restored when plugin is removed
|
|
- **Conflicts:** Remove this plugin before installing production updates
|
|
|
|
### 📝 Modified Files:
|
|
|
|
<details>
|
|
<summary>Click to expand file list</summary>
|
|
|
|
```
|
|
${{ steps.format-files.outputs.files }}
|
|
```
|
|
|
|
</details>
|
|
|
|
### 🔄 To Remove:
|
|
|
|
Navigate to Plugins → Installed Plugins and remove `webgui-pr-${{ steps.version.outputs.version }}`, or run:
|
|
```bash
|
|
plugin remove webgui-pr-${{ steps.version.outputs.version }}
|
|
```
|
|
|
|
---
|
|
<sub>🤖 This comment is automatically generated and will be updated with each new push to this PR.</sub> |