From 683f07c38614fadcd6abb955f883e87a80896e53 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Wed, 10 Sep 2025 12:00:07 -0400 Subject: [PATCH] chore: enhance PR plugin generation and workflow for TXZ uploads - Updated `generate-pr-plugin.sh` to include a new parameter for TXZ URL and modified usage instructions. - Enhanced the GitHub Actions workflow to upload the TXZ file to R2 and generate the corresponding public URL. - Improved installation instructions in the PR comment to provide direct download links for the PLG and TXZ files. --- .github/scripts/generate-pr-plugin.sh | 15 ++-- .github/workflows/pr-plugin-build.yml | 113 ++++++++++++++------------ 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/.github/scripts/generate-pr-plugin.sh b/.github/scripts/generate-pr-plugin.sh index 93727abf2..96ad7787f 100755 --- a/.github/scripts/generate-pr-plugin.sh +++ b/.github/scripts/generate-pr-plugin.sh @@ -1,15 +1,16 @@ #!/bin/bash # Generate PR plugin file for Unraid -# Usage: ./generate-pr-plugin.sh +# Usage: ./generate-pr-plugin.sh VERSION=$1 PR_NUMBER=$2 COMMIT_SHA=$3 TARBALL_NAME=$4 +TXZ_URL=$5 -if [ -z "$VERSION" ] || [ -z "$PR_NUMBER" ] || [ -z "$COMMIT_SHA" ] || [ -z "$TARBALL_NAME" ]; then - echo "Usage: $0 " +if [ -z "$VERSION" ] || [ -z "$PR_NUMBER" ] || [ -z "$COMMIT_SHA" ] || [ -z "$TARBALL_NAME" ] || [ -z "$TXZ_URL" ]; then + echo "Usage: $0 " exit 1 fi @@ -68,9 +69,9 @@ echo "Created plugin directories" - + -/boot/config/plugins/webgui-pr/&tarball; +TXZ_URL_PLACEHOLDER &sha256; @@ -168,7 +169,9 @@ fi # Clean up echo "Cleaning up plugin files..." +# Remove the plugin directory (which includes the tarball and backups) rm -rf "/boot/config/plugins/&name;" +# Remove the plugin file itself rm -f "/boot/config/plugins/webgui-pr-&version;.plg" echo "" @@ -188,6 +191,7 @@ if [[ "$OSTYPE" == "darwin"* ]]; then sed -i '' "s/SHA256_PLACEHOLDER/${TARBALL_SHA256}/g" "$PLUGIN_NAME" sed -i '' "s/PR_PLACEHOLDER/${PR_NUMBER}/g" "$PLUGIN_NAME" sed -i '' "s/COMMIT_PLACEHOLDER/${COMMIT_SHA}/g" "$PLUGIN_NAME" + sed -i '' "s|TXZ_URL_PLACEHOLDER|${TXZ_URL}|g" "$PLUGIN_NAME" else # Linux sed sed -i "s/VERSION_PLACEHOLDER/${VERSION}/g" "$PLUGIN_NAME" @@ -195,6 +199,7 @@ else sed -i "s/SHA256_PLACEHOLDER/${TARBALL_SHA256}/g" "$PLUGIN_NAME" sed -i "s/PR_PLACEHOLDER/${PR_NUMBER}/g" "$PLUGIN_NAME" sed -i "s/COMMIT_PLACEHOLDER/${COMMIT_SHA}/g" "$PLUGIN_NAME" + sed -i "s|TXZ_URL_PLACEHOLDER|${TXZ_URL}|g" "$PLUGIN_NAME" fi echo "Plugin generated: $PLUGIN_NAME" \ No newline at end of file diff --git a/.github/workflows/pr-plugin-build.yml b/.github/workflows/pr-plugin-build.yml index 6e7173cd9..81d0930bf 100644 --- a/.github/workflows/pr-plugin-build.yml +++ b/.github/workflows/pr-plugin-build.yml @@ -25,19 +25,19 @@ jobs: - name: Get changed files id: changed-files run: | - # Get list of changed files in emhttp directory - git diff --name-only origin/${{ github.base_ref }}...HEAD | grep '^emhttp/' > changed_files.txt || true + # 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 + if [ ! -s "changed_files.txt" ]; then echo "No emhttp files changed" - echo "has_changes=false" >> $GITHUB_OUTPUT + echo "has_changes=false" >> "$GITHUB_OUTPUT" else - echo "has_changes=true" >> $GITHUB_OUTPUT + echo "has_changes=true" >> "$GITHUB_OUTPUT" fi - name: Generate plugin version @@ -74,18 +74,57 @@ jobs: # Generate file list for plugin find build/usr/local/emhttp -type f | sed 's|^build||' > file_list.txt - - name: Generate plugin file + - 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 a path that's easy to prune (pr-plugins/pr-NUMBER/files) + aws s3 cp webgui-pr-${{ steps.version.outputs.version }}.tar.gz \ + s3://${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_NAME }}/pr-plugins/pr-${{ github.event.pull_request.number }}/ \ + --endpoint-url ${{ secrets.CLOUDFLARE_S3_URL }} \ + --acl public-read + + # Construct the public URL + TXZ_URL="${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_BASE_URL }}/pr-plugins/pr-${{ github.event.pull_request.number }}/webgui-pr-${{ steps.version.outputs.version }}.tar.gz" + + echo "txz_url=$TXZ_URL" >> $GITHUB_OUTPUT + echo "Uploaded TXZ to: $TXZ_URL" + + - name: Generate plugin file with R2 URL if: steps.changed-files.outputs.has_changes == 'true' run: | bash .github/scripts/generate-pr-plugin.sh \ "${{ steps.version.outputs.version }}" \ "${{ github.event.pull_request.number }}" \ "$(git rev-parse --short HEAD)" \ - "webgui-pr-${{ steps.version.outputs.version }}.tar.gz" + "webgui-pr-${{ steps.version.outputs.version }}.tar.gz" \ + "${{ steps.upload-txz.outputs.txz_url }}" - - name: Upload plugin artifact + - name: Upload PLG to R2 + if: steps.changed-files.outputs.has_changes == 'true' + id: upload-plg + run: | + # Upload PLG to same PR folder + aws s3 cp webgui-pr-${{ steps.version.outputs.version }}.plg \ + s3://${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_NAME }}/pr-plugins/pr-${{ github.event.pull_request.number }}/ \ + --endpoint-url ${{ secrets.CLOUDFLARE_S3_URL }} \ + --acl public-read + + # Construct the public URL + PLG_URL="${{ secrets.CLOUDFLARE_PREVIEW_BUCKET_BASE_URL }}/pr-plugins/pr-${{ github.event.pull_request.number }}/webgui-pr-${{ steps.version.outputs.version }}.plg" + + echo "plg_url=$PLG_URL" >> $GITHUB_OUTPUT + echo "Uploaded PLG to: $PLG_URL" + + - name: Upload artifacts to GitHub (backup) if: steps.changed-files.outputs.has_changes == 'true' - id: upload-artifact uses: actions/upload-artifact@v4 with: name: webgui-pr-plugin-${{ github.event.pull_request.number }} @@ -103,38 +142,6 @@ jobs: cat changed_files.txt echo "EOF" >> $GITHUB_OUTPUT - - name: Get artifact download URL - if: steps.changed-files.outputs.has_changes == 'true' - id: artifact-url - uses: actions/github-script@v7 - with: - script: | - // Wait a moment for artifact to be registered - await new Promise(resolve => setTimeout(resolve, 5000)); - - const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.runId, - }); - - const artifact = artifacts.data.artifacts.find(a => - a.name === `webgui-pr-plugin-${{ github.event.pull_request.number }}` - ); - - if (artifact) { - // For public repos, we can use the GitHub API download URL - const apiUrl = `https://api.github.com/repos/${context.repo.owner}/${context.repo.repo}/actions/artifacts/${artifact.id}/zip`; - const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}/artifacts/${artifact.id}`; - core.setOutput('api_url', apiUrl); - core.setOutput('artifact_url', artifactUrl); - core.setOutput('artifact_id', artifact.id); - console.log(`Artifact ID: ${artifact.id}`); - console.log(`Artifact URL: ${artifactUrl}`); - } else { - console.log('Artifact not found yet'); - } - - name: Comment on PR if: steps.changed-files.outputs.has_changes == 'true' uses: peter-evans/create-or-update-comment@v4 @@ -150,19 +157,17 @@ jobs: ### 📥 Installation Instructions: - 1. **Download the plugin files:** - - [📦 Download from GitHub Artifacts](${{ steps.artifact-url.outputs.artifact_url }}) - - Or use: `curl -L -o plugin.zip "${{ steps.artifact-url.outputs.api_url }}"` - - Extract the downloaded ZIP file + **Install via Unraid Web UI:** + 1. Go to **Plugins → Install Plugin** + 2. Copy and paste this URL: + ``` + ${{ steps.upload-plg.outputs.plg_url }} + ``` + 3. Click **Install** - 2. **Copy files to your Unraid server:** - - Create directory: `mkdir -p /boot/config/plugins/webgui-pr/` - - `webgui-pr-${{ steps.version.outputs.version }}.plg` → `/boot/config/plugins/` - - `webgui-pr-${{ steps.version.outputs.version }}.tar.gz` → `/boot/config/plugins/webgui-pr/` - - 3. **Install the plugin:** - - Via Plugins tab: Navigate to Install Plugin, use the file browser to select the .plg file - - Via command line: `installplg /boot/config/plugins/webgui-pr-${{ steps.version.outputs.version }}.plg` + **Alternative: Direct Download** + - [📦 Download PLG](${{ steps.upload-plg.outputs.plg_url }}) + - [📦 Download TXZ](${{ steps.upload-txz.outputs.txz_url }}) ### ⚠️ Important Notes: @@ -186,7 +191,7 @@ jobs: Navigate to Plugins → Installed Plugins and remove `webgui-pr-${{ steps.version.outputs.version }}`, or run: ```bash - removepkg webgui-pr-${{ steps.version.outputs.version }} + plugin remove webgui-pr-${{ steps.version.outputs.version }} ``` ---