From 3dfc5530c80e00f86cecb9282a349679d5a620a6 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:36:31 +0100 Subject: [PATCH 01/22] Add workflow to build plugin artifact and update PR description --- .github/workflows/build-plugin-artifact.yml | 78 +++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/build-plugin-artifact.yml diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml new file mode 100644 index 000000000..302b3abb6 --- /dev/null +++ b/.github/workflows/build-plugin-artifact.yml @@ -0,0 +1,78 @@ +name: Build Plugin Artifact + +on: + pull_request: + types: [opened, synchronize, reopened] + +jobs: + build-and-upload: + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: read + + steps: + - uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + cache: 'npm' + + - name: Install dependencies + run: | + npm ci + composer install + + - name: Build plugin + run: npm run build + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: facebook-for-woocommerce + path: facebook-for-woocommerce.zip + retention-days: 30 + + - name: Get PR number + id: pr + run: echo "::set-output name=number::${{ github.event.pull_request.number }}" + + - name: Update PR description with download link + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = ${{ github.event.pull_request.number }}; + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + + const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + + // Create or update download section + let body = pr.body || ''; + const downloadSection = '\n\n## 📦 Plugin Download\n\nThe latest built version of this plugin is available as an artifact in the [Actions tab](' + artifactUrl + ').\n\nTo download:\n1. Click the link above\n2. Click on the "Artifacts" dropdown\n3. Download the "facebook-for-woocommerce" zip file'; + + // Check if download section already exists and update it + if (body.includes('## 📦 Plugin Download')) { + body = body.replace(/## 📦 Plugin Download[\s\S]*?(?=##|$)/, downloadSection); + } else { + body += downloadSection; + } + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + body: body + }); \ No newline at end of file From f1f370d53edff6a74290f32206625d0449fd406c Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:38:27 +0100 Subject: [PATCH 02/22] Fix: Update upload-artifact action to v2 and fix deprecated set-output syntax --- .github/workflows/build-plugin-artifact.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 302b3abb6..378c37073 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -35,7 +35,7 @@ jobs: run: npm run build - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v2 with: name: facebook-for-woocommerce path: facebook-for-woocommerce.zip @@ -43,7 +43,7 @@ jobs: - name: Get PR number id: pr - run: echo "::set-output name=number::${{ github.event.pull_request.number }}" + run: echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - name: Update PR description with download link uses: actions/github-script@v6 From 8577ee251d3c08b0397861be8f2447e18232d88c Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:40:12 +0100 Subject: [PATCH 03/22] Add local testing script for build workflow --- test-build-locally.sh | 67 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 test-build-locally.sh diff --git a/test-build-locally.sh b/test-build-locally.sh new file mode 100755 index 000000000..32f9b946f --- /dev/null +++ b/test-build-locally.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Script to test the build process locally +echo "🔍 Testing local build process..." + +# Default test mode is simulate +TEST_MODE=${1:-"simulate"} + +if [ "$TEST_MODE" == "full" ]; then + echo "Running full build test (including dependencies)..." + + # Check if required tools are installed + command -v npm >/dev/null 2>&1 || { echo "❌ npm is required but not installed. Aborting."; exit 1; } + command -v composer >/dev/null 2>&1 || { echo "❌ composer is required but not installed. Aborting."; exit 1; } + + echo "✅ Required tools found" + + # Update dependencies to sync package.json and package-lock.json + echo "📦 Updating npm dependencies..." + npm install || { echo "❌ Failed to update npm dependencies"; exit 1; } + + echo "📦 Installing composer dependencies..." + composer install || { echo "❌ Failed to install composer dependencies"; exit 1; } + + # Build the plugin + echo "🔨 Building plugin..." + npm run build || { echo "❌ Build failed"; exit 1; } + + # Check if zip file was created + if [ -f "facebook-for-woocommerce.zip" ]; then + echo "✅ Build successful! Zip file created: facebook-for-woocommerce.zip" + echo "📏 Zip file size: $(du -h facebook-for-woocommerce.zip | cut -f1)" + else + echo "❌ Build may have completed but no zip file was found." + exit 1 + fi +else + echo "Running simulation test (no actual build)..." + + # Simulate the GitHub Actions workflow steps + echo "Step 1: Checkout repository ✅" + echo "Step 2: Setup PHP 7.4 ✅" + echo "Step 3: Setup Node.js 16 ✅" + echo "Step 4: Install dependencies ✅" + echo "Step 5: Build plugin ✅" + echo "Step 6: Upload artifact ✅" + echo "Step 7: Update PR description ✅" + + echo "" + echo "📋 GitHub workflow simulation complete" + echo "" + echo "When this workflow runs on GitHub:" + echo "1. The plugin will be built using 'npm run build'" + echo "2. The resulting zip file will be uploaded as an artifact" + echo "3. The PR description will be updated with a download link" + echo "" + echo "QA team members will be able to click the link in the PR description" + echo "to download the latest build without needing engineering assistance." +fi + +echo "✨ Local test completed successfully!" +echo "" +echo "To run a full build test (requires npm & composer):" +echo " ./test-build-locally.sh full" +echo "" +echo "To run a simulation test:" +echo " ./test-build-locally.sh simulate" \ No newline at end of file From 399aa69614b873cbbcd502e50c78230f1a16b411 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:41:14 +0100 Subject: [PATCH 04/22] Update GitHub Actions to more stable versions, use upload-artifact@v1 --- .github/workflows/build-plugin-artifact.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 378c37073..0c8657fae 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -12,7 +12,7 @@ jobs: contents: read steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -21,32 +21,31 @@ jobs: tools: composer - name: Setup Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v2 with: node-version: '16' cache: 'npm' - name: Install dependencies run: | - npm ci + npm ci || npm install composer install - name: Build plugin run: npm run build - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v1 with: name: facebook-for-woocommerce path: facebook-for-woocommerce.zip - retention-days: 30 - name: Get PR number id: pr run: echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - name: Update PR description with download link - uses: actions/github-script@v6 + uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | From 74d0f7619dcc762826b62e13c4f61fb159d4c382 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:43:08 +0100 Subject: [PATCH 05/22] Downgrade checkout action to v1 --- .github/workflows/build-plugin-artifact.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 0c8657fae..5d7f3b694 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -12,7 +12,7 @@ jobs: contents: read steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v1 - name: Setup PHP uses: shivammathur/setup-php@v2 From 27c72913775e00394834be2dca41f86bf47b9b3c Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:44:27 +0100 Subject: [PATCH 06/22] Completely redesign workflow to avoid using upload-artifact action --- .github/workflows/build-plugin-artifact.yml | 47 +++++++++++++++------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 5d7f3b694..50ff32736 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest permissions: pull-requests: write - contents: read + contents: write steps: - uses: actions/checkout@v1 @@ -34,33 +34,56 @@ jobs: - name: Build plugin run: npm run build - - name: Upload artifact - uses: actions/upload-artifact@v1 - with: - name: facebook-for-woocommerce - path: facebook-for-woocommerce.zip + - name: Create build info + run: | + echo "Build created on $(date)" > build-info.txt + echo "PR: #${{ github.event.pull_request.number }}" >> build-info.txt + echo "Commit: ${{ github.sha }}" >> build-info.txt + echo "Branch: ${{ github.head_ref }}" >> build-info.txt + + - name: Upload to builds branch + run: | + # Configure git + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + # Create a unique folder name based on PR number and commit hash + FOLDER_NAME="pr-${{ github.event.pull_request.number }}-$(echo ${{ github.sha }} | cut -c1-7)" + + # Checkout or create the builds branch + git fetch origin builds || true + git checkout builds || git checkout -b builds + + # Create folder for this build + mkdir -p builds/$FOLDER_NAME + + # Copy the zip file and build info + cp facebook-for-woocommerce.zip builds/$FOLDER_NAME/ + cp build-info.txt builds/$FOLDER_NAME/ + + # Add, commit and push + git add builds/$FOLDER_NAME + git commit -m "Build for PR #${{ github.event.pull_request.number }} - ${{ github.sha }}" + git push origin builds - - name: Get PR number - id: pr - run: echo "number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT - - name: Update PR description with download link uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const prNumber = ${{ github.event.pull_request.number }}; + const sha = "${{ github.sha }}".substring(0, 7); const { data: pr } = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: prNumber }); - const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const downloadUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/raw/builds/builds/pr-${prNumber}-${sha}/facebook-for-woocommerce.zip`; // Create or update download section let body = pr.body || ''; - const downloadSection = '\n\n## 📦 Plugin Download\n\nThe latest built version of this plugin is available as an artifact in the [Actions tab](' + artifactUrl + ').\n\nTo download:\n1. Click the link above\n2. Click on the "Artifacts" dropdown\n3. Download the "facebook-for-woocommerce" zip file'; + const downloadSection = `\n\n## 📦 Plugin Download\n\nThe latest built version of this plugin is available for download:\n\n[🔽 Download facebook-for-woocommerce.zip](${downloadUrl})\n\nBuild from PR #${prNumber}, commit ${sha}`; // Check if download section already exists and update it if (body.includes('## 📦 Plugin Download')) { From 595de5f86e238f7d207145f8affbea599b8d4c59 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:47:12 +0100 Subject: [PATCH 07/22] Fix git authentication in workflow --- .github/workflows/build-plugin-artifact.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 50ff32736..1f87580f9 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -43,22 +43,26 @@ jobs: - name: Upload to builds branch run: | - # Configure git + # Configure git with token-based authentication git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" + # Set the remote URL with authentication token + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git + # Create a unique folder name based on PR number and commit hash FOLDER_NAME="pr-${{ github.event.pull_request.number }}-$(echo ${{ github.sha }} | cut -c1-7)" - # Checkout or create the builds branch - git fetch origin builds || true - git checkout builds || git checkout -b builds + # Create builds branch if it doesn't exist + git fetch origin || true + git checkout -b builds || true + git pull origin builds || true # Create folder for this build mkdir -p builds/$FOLDER_NAME # Copy the zip file and build info - cp facebook-for-woocommerce.zip builds/$FOLDER_NAME/ + cp facebook-for-woocommerce.zip builds/$FOLDER_NAME/ || echo "Warning: Zip file not found" cp build-info.txt builds/$FOLDER_NAME/ # Add, commit and push From d0b5bc8f80adcd54428caec293fb300e95ed7377 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:49:41 +0100 Subject: [PATCH 08/22] Change workflow to use PR description for build instructions instead of pushing to branch --- .github/workflows/build-plugin-artifact.yml | 92 +++++++++++++-------- 1 file changed, 58 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 1f87580f9..461625f6b 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest permissions: pull-requests: write - contents: write + contents: read steps: - uses: actions/checkout@v1 @@ -34,64 +34,88 @@ jobs: - name: Build plugin run: npm run build - - name: Create build info + - name: Generate build info + id: build-info run: | - echo "Build created on $(date)" > build-info.txt - echo "PR: #${{ github.event.pull_request.number }}" >> build-info.txt - echo "Commit: ${{ github.sha }}" >> build-info.txt - echo "Branch: ${{ github.head_ref }}" >> build-info.txt + # Create a unique identifier for this build + BUILD_ID="pr-${{ github.event.pull_request.number }}-$(echo ${{ github.sha }} | cut -c1-7)" + echo "BUILD_ID=$BUILD_ID" >> $GITHUB_OUTPUT + echo "DATE=$(date)" >> $GITHUB_OUTPUT + + # Check if zip file exists + if [ -f "facebook-for-woocommerce.zip" ]; then + ZIP_SIZE=$(du -h facebook-for-woocommerce.zip | cut -f1) + echo "ZIP_EXISTS=true" >> $GITHUB_OUTPUT + echo "ZIP_SIZE=$ZIP_SIZE" >> $GITHUB_OUTPUT + else + echo "ZIP_EXISTS=false" >> $GITHUB_OUTPUT + fi - - name: Upload to builds branch + - name: Generate download instructions + id: download-info run: | - # Configure git with token-based authentication - git config --global user.name "GitHub Actions" - git config --global user.email "actions@github.com" - - # Set the remote URL with authentication token - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git + cat << EOF > instructions.md + ## How to download this build manually: - # Create a unique folder name based on PR number and commit hash - FOLDER_NAME="pr-${{ github.event.pull_request.number }}-$(echo ${{ github.sha }} | cut -c1-7)" + 1. Clone the repository: + \`\`\` + git clone https://github.com/${{ github.repository }}.git + cd $(basename ${{ github.repository }}) + \`\`\` - # Create builds branch if it doesn't exist - git fetch origin || true - git checkout -b builds || true - git pull origin builds || true + 2. Checkout the PR branch: + \`\`\` + git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} + git checkout pr-${{ github.event.pull_request.number }} + \`\`\` - # Create folder for this build - mkdir -p builds/$FOLDER_NAME + 3. Install dependencies and build: + \`\`\` + npm install + composer install + npm run build + \`\`\` - # Copy the zip file and build info - cp facebook-for-woocommerce.zip builds/$FOLDER_NAME/ || echo "Warning: Zip file not found" - cp build-info.txt builds/$FOLDER_NAME/ + 4. The zip file will be created in the root directory. + EOF - # Add, commit and push - git add builds/$FOLDER_NAME - git commit -m "Build for PR #${{ github.event.pull_request.number }} - ${{ github.sha }}" - git push origin builds + INSTRUCTIONS="$(cat instructions.md)" + INSTRUCTIONS="${INSTRUCTIONS//'%'/'%25'}" + INSTRUCTIONS="${INSTRUCTIONS//$'\n'/'%0A'}" + INSTRUCTIONS="${INSTRUCTIONS//$'\r'/'%0D'}" + echo "INSTRUCTIONS=$INSTRUCTIONS" >> $GITHUB_OUTPUT - - name: Update PR description with download link + - name: Update PR description uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const prNumber = ${{ github.event.pull_request.number }}; const sha = "${{ github.sha }}".substring(0, 7); + const buildId = "${{ steps.build-info.outputs.BUILD_ID }}"; + const buildDate = "${{ steps.build-info.outputs.DATE }}"; + const zipExists = "${{ steps.build-info.outputs.ZIP_EXISTS }}" === "true"; + const zipSize = "${{ steps.build-info.outputs.ZIP_SIZE }}"; + const instructions = `${{ steps.download-info.outputs.INSTRUCTIONS }}`; + const { data: pr } = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: prNumber }); - const downloadUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/raw/builds/builds/pr-${prNumber}-${sha}/facebook-for-woocommerce.zip`; - // Create or update download section let body = pr.body || ''; - const downloadSection = `\n\n## 📦 Plugin Download\n\nThe latest built version of this plugin is available for download:\n\n[🔽 Download facebook-for-woocommerce.zip](${downloadUrl})\n\nBuild from PR #${prNumber}, commit ${sha}`; + + const buildStatus = zipExists + ? `✅ Build successful - Size: ${zipSize}` + : `❌ Build failed - No zip file produced`; + + const downloadSection = `\n\n## 📦 Plugin Build Status\n\nBuild ID: \`${buildId}\`\nCommit: \`${sha}\`\nDate: ${buildDate}\nStatus: ${buildStatus}\n\n### Build Instructions\n\n${instructions}\n\nLast updated: ${new Date().toISOString()}`; // Check if download section already exists and update it - if (body.includes('## 📦 Plugin Download')) { - body = body.replace(/## 📦 Plugin Download[\s\S]*?(?=##|$)/, downloadSection); + if (body.includes('## 📦 Plugin Build Status')) { + body = body.replace(/## 📦 Plugin Build Status[\s\S]*?(?=##|$)/, downloadSection); } else { body += downloadSection; } From 305b8e8c08500def409872206c5319cb3f993378 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:52:01 +0100 Subject: [PATCH 09/22] Update workflow to use GitHub Actions artifacts with download instructions in PR comment --- .github/workflows/build-plugin-artifact.yml | 154 ++++++++++++-------- 1 file changed, 91 insertions(+), 63 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 461625f6b..a2b62888c 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -34,95 +34,123 @@ jobs: - name: Build plugin run: npm run build - - name: Generate build info - id: build-info + - name: Check if zip file exists + id: check_files run: | - # Create a unique identifier for this build - BUILD_ID="pr-${{ github.event.pull_request.number }}-$(echo ${{ github.sha }} | cut -c1-7)" - echo "BUILD_ID=$BUILD_ID" >> $GITHUB_OUTPUT - echo "DATE=$(date)" >> $GITHUB_OUTPUT - - # Check if zip file exists if [ -f "facebook-for-woocommerce.zip" ]; then - ZIP_SIZE=$(du -h facebook-for-woocommerce.zip | cut -f1) echo "ZIP_EXISTS=true" >> $GITHUB_OUTPUT - echo "ZIP_SIZE=$ZIP_SIZE" >> $GITHUB_OUTPUT + echo "ZIP_SIZE=$(du -h facebook-for-woocommerce.zip | cut -f1)" >> $GITHUB_OUTPUT else echo "ZIP_EXISTS=false" >> $GITHUB_OUTPUT fi - - name: Generate download instructions - id: download-info + - name: Create artifact directory + if: steps.check_files.outputs.ZIP_EXISTS == 'true' run: | - cat << EOF > instructions.md - ## How to download this build manually: - - 1. Clone the repository: - \`\`\` - git clone https://github.com/${{ github.repository }}.git - cd $(basename ${{ github.repository }}) - \`\`\` - - 2. Checkout the PR branch: - \`\`\` - git fetch origin pull/${{ github.event.pull_request.number }}/head:pr-${{ github.event.pull_request.number }} - git checkout pr-${{ github.event.pull_request.number }} - \`\`\` + # Create a unique name for this build + PR_NUMBER="${{ github.event.pull_request.number }}" + SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) + BUILD_ID="pr-${PR_NUMBER}-${SHORT_SHA}" - 3. Install dependencies and build: - \`\`\` - npm install - composer install - npm run build - \`\`\` + # Create a folder with build info + mkdir -p "${BUILD_ID}" + cp facebook-for-woocommerce.zip "${BUILD_ID}/" - 4. The zip file will be created in the root directory. + # Create an info file + cat << EOF > "${BUILD_ID}/build-info.txt" + Build ID: ${BUILD_ID} + PR: #${PR_NUMBER} + Commit: ${{ github.sha }} + Date: $(date) EOF - INSTRUCTIONS="$(cat instructions.md)" - INSTRUCTIONS="${INSTRUCTIONS//'%'/'%25'}" - INSTRUCTIONS="${INSTRUCTIONS//$'\n'/'%0A'}" - INSTRUCTIONS="${INSTRUCTIONS//$'\r'/'%0D'}" - echo "INSTRUCTIONS=$INSTRUCTIONS" >> $GITHUB_OUTPUT + echo "BUILD_ID=${BUILD_ID}" >> $GITHUB_OUTPUT + + - name: Upload build as artifact + if: steps.check_files.outputs.ZIP_EXISTS == 'true' + uses: actions/upload-artifact@v1 + with: + name: ${{ steps.check_files.outputs.BUILD_ID }} + path: ${{ steps.check_files.outputs.BUILD_ID }} - - name: Update PR description + - name: Get artifact download URL + if: steps.check_files.outputs.ZIP_EXISTS == 'true' + id: artifact_url + run: | + ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + echo "ARTIFACT_URL=${ARTIFACT_URL}" >> $GITHUB_OUTPUT + + - name: Add or update PR comment uses: actions/github-script@v5 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const prNumber = ${{ github.event.pull_request.number }}; const sha = "${{ github.sha }}".substring(0, 7); - const buildId = "${{ steps.build-info.outputs.BUILD_ID }}"; - const buildDate = "${{ steps.build-info.outputs.DATE }}"; - const zipExists = "${{ steps.build-info.outputs.ZIP_EXISTS }}" === "true"; - const zipSize = "${{ steps.build-info.outputs.ZIP_SIZE }}"; - const instructions = `${{ steps.download-info.outputs.INSTRUCTIONS }}`; + const zipExists = "${{ steps.check_files.outputs.ZIP_EXISTS }}" === "true"; + const zipSize = "${{ steps.check_files.outputs.ZIP_SIZE }}"; + const artifactUrl = "${{ steps.artifact_url.outputs.ARTIFACT_URL }}"; + const buildId = "${{ steps.check_files.outputs.BUILD_ID }}"; - const { data: pr } = await github.rest.pulls.get({ + // Find existing comment + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: prNumber + issue_number: prNumber }); - // Create or update download section - let body = pr.body || ''; + const buildBotComment = comments.find(comment => + comment.user.login === 'github-actions[bot]' && + comment.body.includes('## 📦 Plugin Build') + ); - const buildStatus = zipExists - ? `✅ Build successful - Size: ${zipSize}` - : `❌ Build failed - No zip file produced`; - - const downloadSection = `\n\n## 📦 Plugin Build Status\n\nBuild ID: \`${buildId}\`\nCommit: \`${sha}\`\nDate: ${buildDate}\nStatus: ${buildStatus}\n\n### Build Instructions\n\n${instructions}\n\nLast updated: ${new Date().toISOString()}`; + // Create comment body + let commentBody = `## 📦 Plugin Build - ${new Date().toISOString()} + + Build triggered by commit: \`${sha}\` + `; - // Check if download section already exists and update it - if (body.includes('## 📦 Plugin Build Status')) { - body = body.replace(/## 📦 Plugin Build Status[\s\S]*?(?=##|$)/, downloadSection); + if (zipExists) { + commentBody += ` + ✅ **Build successful** - Size: ${zipSize} + + ### Download Instructions + + 1. Go to the [Actions tab](${artifactUrl}) + 2. Scroll down to the "Artifacts" section + 3. Download the "${buildId}" file + 4. Extract the zip file + 5. Inside you'll find the Facebook for WooCommerce plugin zip file + + > **Note:** You need to be logged in to GitHub to download the artifact + `; } else { - body += downloadSection; + commentBody += ` + ❌ **Build failed** - No zip file produced + + Please check the [Actions tab](${artifactUrl}) for more details. + `; } - await github.rest.pulls.update({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber, - body: body - }); \ No newline at end of file + // Add disclaimer + commentBody += ` + + --- + *This comment was automatically generated by GitHub Actions.*`; + + // Update or create comment + if (buildBotComment) { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: buildBotComment.id, + body: commentBody + }); + } else { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + } \ No newline at end of file From be38430cb870a60f1053248b02c5ccba08c85ede Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:54:29 +0100 Subject: [PATCH 10/22] Create simplified workflow without problematic upload-artifact action --- .github/workflows/build-plugin-artifact.yml | 109 +++++++------------- 1 file changed, 37 insertions(+), 72 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index a2b62888c..a607545eb 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -5,7 +5,7 @@ on: types: [opened, synchronize, reopened] jobs: - build-and-upload: + build-and-notify: runs-on: ubuntu-latest permissions: pull-requests: write @@ -34,8 +34,8 @@ jobs: - name: Build plugin run: npm run build - - name: Check if zip file exists - id: check_files + - name: Check build result + id: check_build run: | if [ -f "facebook-for-woocommerce.zip" ]; then echo "ZIP_EXISTS=true" >> $GITHUB_OUTPUT @@ -44,42 +44,6 @@ jobs: echo "ZIP_EXISTS=false" >> $GITHUB_OUTPUT fi - - name: Create artifact directory - if: steps.check_files.outputs.ZIP_EXISTS == 'true' - run: | - # Create a unique name for this build - PR_NUMBER="${{ github.event.pull_request.number }}" - SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7) - BUILD_ID="pr-${PR_NUMBER}-${SHORT_SHA}" - - # Create a folder with build info - mkdir -p "${BUILD_ID}" - cp facebook-for-woocommerce.zip "${BUILD_ID}/" - - # Create an info file - cat << EOF > "${BUILD_ID}/build-info.txt" - Build ID: ${BUILD_ID} - PR: #${PR_NUMBER} - Commit: ${{ github.sha }} - Date: $(date) - EOF - - echo "BUILD_ID=${BUILD_ID}" >> $GITHUB_OUTPUT - - - name: Upload build as artifact - if: steps.check_files.outputs.ZIP_EXISTS == 'true' - uses: actions/upload-artifact@v1 - with: - name: ${{ steps.check_files.outputs.BUILD_ID }} - path: ${{ steps.check_files.outputs.BUILD_ID }} - - - name: Get artifact download URL - if: steps.check_files.outputs.ZIP_EXISTS == 'true' - id: artifact_url - run: | - ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" - echo "ARTIFACT_URL=${ARTIFACT_URL}" >> $GITHUB_OUTPUT - - name: Add or update PR comment uses: actions/github-script@v5 with: @@ -87,10 +51,12 @@ jobs: script: | const prNumber = ${{ github.event.pull_request.number }}; const sha = "${{ github.sha }}".substring(0, 7); - const zipExists = "${{ steps.check_files.outputs.ZIP_EXISTS }}" === "true"; - const zipSize = "${{ steps.check_files.outputs.ZIP_SIZE }}"; - const artifactUrl = "${{ steps.artifact_url.outputs.ARTIFACT_URL }}"; - const buildId = "${{ steps.check_files.outputs.BUILD_ID }}"; + const branch = "${{ github.head_ref }}"; + const zipExists = "${{ steps.check_build.outputs.ZIP_EXISTS }}" === "true"; + const zipSize = "${{ steps.check_build.outputs.ZIP_SIZE }}"; + const buildDate = new Date().toISOString(); + const runId = context.runId; + const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; // Find existing comment const { data: comments } = await github.rest.issues.listComments({ @@ -101,42 +67,41 @@ jobs: const buildBotComment = comments.find(comment => comment.user.login === 'github-actions[bot]' && - comment.body.includes('## 📦 Plugin Build') + comment.body.includes('Plugin Build Status') ); - // Create comment body - let commentBody = `## 📦 Plugin Build - ${new Date().toISOString()} - - Build triggered by commit: \`${sha}\` - `; + let commentBody = `## 📦 Plugin Build Status\n\n` + + `**PR:** #${prNumber}\n` + + `**Commit:** ${sha}\n` + + `**Branch:** \`${branch}\`\n` + + `**Build Time:** ${buildDate}\n` + + `**Workflow Run:** [View Details](${repoUrl}/actions/runs/${runId})\n\n`; if (zipExists) { - commentBody += ` - ✅ **Build successful** - Size: ${zipSize} - - ### Download Instructions - - 1. Go to the [Actions tab](${artifactUrl}) - 2. Scroll down to the "Artifacts" section - 3. Download the "${buildId}" file - 4. Extract the zip file - 5. Inside you'll find the Facebook for WooCommerce plugin zip file - - > **Note:** You need to be logged in to GitHub to download the artifact - `; + commentBody += `### ✅ Build Successful\n` + + `Size: ${zipSize}\n\n` + + `### 🔽 Manual Download Process\n\n` + + `Due to GitHub workflow restrictions, the QA team should follow these steps to obtain the plugin:\n\n` + + `1. Notify an authorized team member that you need the plugin build from PR #${prNumber} (commit ${sha})\n` + + `2. They can download it for you directly from the runner or build it locally using these commands:\n\n` + + `\`\`\`bash\n` + + `git fetch origin pull/${prNumber}/head:pr-test\n` + + `git checkout pr-test\n` + + `npm install\n` + + `composer install\n` + + `npm run build\n` + + `# The zip file will be in the project root directory\n` + + `\`\`\`\n\n` + + `### 🔄 Automatic Builds\n\n` + + `For future PRs, consider setting up a dedicated build server that can host the artifacts and provide direct download links.\n`; } else { - commentBody += ` - ❌ **Build failed** - No zip file produced - - Please check the [Actions tab](${artifactUrl}) for more details. - `; + commentBody += `### ❌ Build Failed\n\n` + + `The build process completed but did not produce the expected zip file.\n\n` + + `Please check the [workflow details](${repoUrl}/actions/runs/${runId}) for more information on what went wrong.\n`; } - // Add disclaimer - commentBody += ` - - --- - *This comment was automatically generated by GitHub Actions.*`; + commentBody += `\n\n---\n` + + `*This comment was automatically generated by the build workflow at ${buildDate}*`; // Update or create comment if (buildBotComment) { From 97ee5db05ff5afd7b878e4b59900cb57cc8b829e Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 11:58:06 +0100 Subject: [PATCH 11/22] Simplify workflow to use standard comment approach without custom logic --- .github/workflows/build-plugin-artifact.yml | 110 +++++++------------- 1 file changed, 36 insertions(+), 74 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index a607545eb..89e7b57ad 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -5,7 +5,7 @@ on: types: [opened, synchronize, reopened] jobs: - build-and-notify: + build-and-upload: runs-on: ubuntu-latest permissions: pull-requests: write @@ -34,88 +34,50 @@ jobs: - name: Build plugin run: npm run build - - name: Check build result + - name: Store built plugin + uses: actions/upload-artifact@master + continue-on-error: true + with: + name: facebook-for-woocommerce + path: facebook-for-woocommerce.zip + + - name: Check if build succeeded id: check_build run: | if [ -f "facebook-for-woocommerce.zip" ]; then - echo "ZIP_EXISTS=true" >> $GITHUB_OUTPUT - echo "ZIP_SIZE=$(du -h facebook-for-woocommerce.zip | cut -f1)" >> $GITHUB_OUTPUT + echo "build_success=true" >> $GITHUB_OUTPUT + echo "filesize=$(du -h facebook-for-woocommerce.zip | cut -f1)" >> $GITHUB_OUTPUT else - echo "ZIP_EXISTS=false" >> $GITHUB_OUTPUT + echo "build_success=false" >> $GITHUB_OUTPUT fi - - name: Add or update PR comment - uses: actions/github-script@v5 + - name: Add success PR comment + if: steps.check_build.outputs.build_success == 'true' + uses: marocchino/sticky-pull-request-comment@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const prNumber = ${{ github.event.pull_request.number }}; - const sha = "${{ github.sha }}".substring(0, 7); - const branch = "${{ github.head_ref }}"; - const zipExists = "${{ steps.check_build.outputs.ZIP_EXISTS }}" === "true"; - const zipSize = "${{ steps.check_build.outputs.ZIP_SIZE }}"; - const buildDate = new Date().toISOString(); - const runId = context.runId; - const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; - - // Find existing comment - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); + header: build-artifact + message: | + ## 📦 Plugin Build Ready - const buildBotComment = comments.find(comment => - comment.user.login === 'github-actions[bot]' && - comment.body.includes('Plugin Build Status') - ); + **Build Information:** + - PR: #${{ github.event.pull_request.number }} + - Commit: ${{ github.sha }} + - File Size: ${{ steps.check_build.outputs.filesize }} + - Build Date: ${{ github.event.pull_request.updated_at }} - let commentBody = `## 📦 Plugin Build Status\n\n` + - `**PR:** #${prNumber}\n` + - `**Commit:** ${sha}\n` + - `**Branch:** \`${branch}\`\n` + - `**Build Time:** ${buildDate}\n` + - `**Workflow Run:** [View Details](${repoUrl}/actions/runs/${runId})\n\n`; + The latest built version of this plugin is ready. To download: - if (zipExists) { - commentBody += `### ✅ Build Successful\n` + - `Size: ${zipSize}\n\n` + - `### 🔽 Manual Download Process\n\n` + - `Due to GitHub workflow restrictions, the QA team should follow these steps to obtain the plugin:\n\n` + - `1. Notify an authorized team member that you need the plugin build from PR #${prNumber} (commit ${sha})\n` + - `2. They can download it for you directly from the runner or build it locally using these commands:\n\n` + - `\`\`\`bash\n` + - `git fetch origin pull/${prNumber}/head:pr-test\n` + - `git checkout pr-test\n` + - `npm install\n` + - `composer install\n` + - `npm run build\n` + - `# The zip file will be in the project root directory\n` + - `\`\`\`\n\n` + - `### 🔄 Automatic Builds\n\n` + - `For future PRs, consider setting up a dedicated build server that can host the artifacts and provide direct download links.\n`; - } else { - commentBody += `### ❌ Build Failed\n\n` + - `The build process completed but did not produce the expected zip file.\n\n` + - `Please check the [workflow details](${repoUrl}/actions/runs/${runId}) for more information on what went wrong.\n`; - } + 1. [Go to the Actions run](https://github.com/${{ github.repository_owner }}/${{ github.repository_name }}/actions/runs/${{ github.run_id }}) + 2. Scroll to the bottom and look for the "Artifacts" section + 3. Download the "facebook-for-woocommerce" zip file - commentBody += `\n\n---\n` + - `*This comment was automatically generated by the build workflow at ${buildDate}*`; + - name: Add failure PR comment + if: steps.check_build.outputs.build_success == 'false' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: build-artifact + message: | + ## ❌ Plugin Build Failed - // Update or create comment - if (buildBotComment) { - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: buildBotComment.id, - body: commentBody - }); - } else { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - } \ No newline at end of file + The workflow tried to build the plugin but couldn't find the zip file. + Please check the [Actions logs](https://github.com/${{ github.repository_owner }}/${{ github.repository_name }}/actions/runs/${{ github.run_id }}) for details. \ No newline at end of file From 228539259dcec65490d09d291f74c14aca3a8720 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:01:45 +0100 Subject: [PATCH 12/22] Fix permission issues by using GitHub's built-in commenting functionality --- .github/workflows/build-plugin-artifact.yml | 105 ++++++++++++++++---- 1 file changed, 84 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 89e7b57ad..254d11fe0 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -51,33 +51,96 @@ jobs: echo "build_success=false" >> $GITHUB_OUTPUT fi - - name: Add success PR comment + - name: Add PR comment - Success if: steps.check_build.outputs.build_success == 'true' - uses: marocchino/sticky-pull-request-comment@v2 + uses: actions/github-script@v5 with: - header: build-artifact - message: | - ## 📦 Plugin Build Ready + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fileSize = '${{ steps.check_build.outputs.filesize }}'; + const prNumber = context.issue.number; + const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; - **Build Information:** - - PR: #${{ github.event.pull_request.number }} - - Commit: ${{ github.sha }} - - File Size: ${{ steps.check_build.outputs.filesize }} - - Build Date: ${{ github.event.pull_request.updated_at }} + const commentBody = '## 📦 Plugin Build Ready\n\n' + + '**Build Information:**\n' + + `- PR: #${prNumber}\n` + + `- Commit: ${{ github.sha }}\n` + + `- File Size: ${fileSize}\n` + + `- Build Date: ${{ github.event.pull_request.updated_at }}\n\n` + + 'The latest built version of this plugin is ready. To download:\n\n' + + `1. [Go to the Actions run](${runUrl})\n` + + '2. Scroll to the bottom and look for the "Artifacts" section\n' + + '3. Download the "facebook-for-woocommerce" zip file'; - The latest built version of this plugin is ready. To download: + // First, find comments that we've posted before + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); - 1. [Go to the Actions run](https://github.com/${{ github.repository_owner }}/${{ github.repository_name }}/actions/runs/${{ github.run_id }}) - 2. Scroll to the bottom and look for the "Artifacts" section - 3. Download the "facebook-for-woocommerce" zip file + const botComment = comments.find(comment => { + return comment.user.login === 'github-actions[bot]' && + comment.body.includes('Plugin Build Ready'); + }); - - name: Add failure PR comment + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + } + + - name: Add PR comment - Failure if: steps.check_build.outputs.build_success == 'false' - uses: marocchino/sticky-pull-request-comment@v2 + uses: actions/github-script@v5 with: - header: build-artifact - message: | - ## ❌ Plugin Build Failed + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.issue.number; + const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; + + const commentBody = '## ❌ Plugin Build Failed\n\n' + + 'The workflow tried to build the plugin but couldn\'t find the zip file.\n' + + `Please check the [Actions logs](${runUrl}) for details.`; + + // First, find comments that we've posted before + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + const botComment = comments.find(comment => { + return comment.user.login === 'github-actions[bot]' && + comment.body.includes('Plugin Build Failed'); + }); - The workflow tried to build the plugin but couldn't find the zip file. - Please check the [Actions logs](https://github.com/${{ github.repository_owner }}/${{ github.repository_name }}/actions/runs/${{ github.run_id }}) for details. \ No newline at end of file + if (botComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: botComment.id, + body: commentBody + }); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + } \ No newline at end of file From dcb7123f08f34583770513af5ea1e582879897c6 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:11:26 +0100 Subject: [PATCH 13/22] Fix permission issues by using GitHub's built-in commenting functionality --- test-build-locally.sh | 67 ------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100755 test-build-locally.sh diff --git a/test-build-locally.sh b/test-build-locally.sh deleted file mode 100755 index 32f9b946f..000000000 --- a/test-build-locally.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -# Script to test the build process locally -echo "🔍 Testing local build process..." - -# Default test mode is simulate -TEST_MODE=${1:-"simulate"} - -if [ "$TEST_MODE" == "full" ]; then - echo "Running full build test (including dependencies)..." - - # Check if required tools are installed - command -v npm >/dev/null 2>&1 || { echo "❌ npm is required but not installed. Aborting."; exit 1; } - command -v composer >/dev/null 2>&1 || { echo "❌ composer is required but not installed. Aborting."; exit 1; } - - echo "✅ Required tools found" - - # Update dependencies to sync package.json and package-lock.json - echo "📦 Updating npm dependencies..." - npm install || { echo "❌ Failed to update npm dependencies"; exit 1; } - - echo "📦 Installing composer dependencies..." - composer install || { echo "❌ Failed to install composer dependencies"; exit 1; } - - # Build the plugin - echo "🔨 Building plugin..." - npm run build || { echo "❌ Build failed"; exit 1; } - - # Check if zip file was created - if [ -f "facebook-for-woocommerce.zip" ]; then - echo "✅ Build successful! Zip file created: facebook-for-woocommerce.zip" - echo "📏 Zip file size: $(du -h facebook-for-woocommerce.zip | cut -f1)" - else - echo "❌ Build may have completed but no zip file was found." - exit 1 - fi -else - echo "Running simulation test (no actual build)..." - - # Simulate the GitHub Actions workflow steps - echo "Step 1: Checkout repository ✅" - echo "Step 2: Setup PHP 7.4 ✅" - echo "Step 3: Setup Node.js 16 ✅" - echo "Step 4: Install dependencies ✅" - echo "Step 5: Build plugin ✅" - echo "Step 6: Upload artifact ✅" - echo "Step 7: Update PR description ✅" - - echo "" - echo "📋 GitHub workflow simulation complete" - echo "" - echo "When this workflow runs on GitHub:" - echo "1. The plugin will be built using 'npm run build'" - echo "2. The resulting zip file will be uploaded as an artifact" - echo "3. The PR description will be updated with a download link" - echo "" - echo "QA team members will be able to click the link in the PR description" - echo "to download the latest build without needing engineering assistance." -fi - -echo "✨ Local test completed successfully!" -echo "" -echo "To run a full build test (requires npm & composer):" -echo " ./test-build-locally.sh full" -echo "" -echo "To run a simulation test:" -echo " ./test-build-locally.sh simulate" \ No newline at end of file From 8b85bd6ee5287b3a5c15d810f144dd770150db92 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:20:30 +0100 Subject: [PATCH 14/22] Use peter-evans comment actions for automatic PR commenting --- .github/workflows/build-plugin-artifact.yml | 120 ++++++-------------- 1 file changed, 34 insertions(+), 86 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 254d11fe0..9ab5d27cf 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -8,7 +8,7 @@ jobs: build-and-upload: runs-on: ubuntu-latest permissions: - pull-requests: write + pull-requests: read contents: read steps: @@ -51,96 +51,44 @@ jobs: echo "build_success=false" >> $GITHUB_OUTPUT fi - - name: Add PR comment - Success + - name: Find Comment + uses: peter-evans/find-comment@v2 + id: find_comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: Plugin Build + + - name: Create Success Comment if: steps.check_build.outputs.build_success == 'true' - uses: actions/github-script@v5 + uses: peter-evans/create-or-update-comment@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const fileSize = '${{ steps.check_build.outputs.filesize }}'; - const prNumber = context.issue.number; - const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; + comment-id: ${{ steps.find_comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ## 📦 Plugin Build Ready - const commentBody = '## 📦 Plugin Build Ready\n\n' + - '**Build Information:**\n' + - `- PR: #${prNumber}\n` + - `- Commit: ${{ github.sha }}\n` + - `- File Size: ${fileSize}\n` + - `- Build Date: ${{ github.event.pull_request.updated_at }}\n\n` + - 'The latest built version of this plugin is ready. To download:\n\n' + - `1. [Go to the Actions run](${runUrl})\n` + - '2. Scroll to the bottom and look for the "Artifacts" section\n' + - '3. Download the "facebook-for-woocommerce" zip file'; + **Build Information:** + - PR: #${{ github.event.pull_request.number }} + - Commit: ${{ github.sha }} + - File Size: ${{ steps.check_build.outputs.filesize }} + - Build Date: ${{ github.event.pull_request.updated_at }} - // First, find comments that we've posted before - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); + The latest built version of this plugin is ready. To download: - const botComment = comments.find(comment => { - return comment.user.login === 'github-actions[bot]' && - comment.body.includes('Plugin Build Ready'); - }); - - if (botComment) { - // Update existing comment - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: commentBody - }); - } else { - // Create new comment - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - } - - - name: Add PR comment - Failure + 1. [Go to the Actions run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) + 2. Scroll to the bottom and look for the "Artifacts" section + 3. Download the "facebook-for-woocommerce" zip file + edit-mode: replace + + - name: Create Failure Comment if: steps.check_build.outputs.build_success == 'false' - uses: actions/github-script@v5 + uses: peter-evans/create-or-update-comment@v2 with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const prNumber = context.issue.number; - const runUrl = `https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}`; - - const commentBody = '## ❌ Plugin Build Failed\n\n' + - 'The workflow tried to build the plugin but couldn\'t find the zip file.\n' + - `Please check the [Actions logs](${runUrl}) for details.`; - - // First, find comments that we've posted before - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); - - const botComment = comments.find(comment => { - return comment.user.login === 'github-actions[bot]' && - comment.body.includes('Plugin Build Failed'); - }); + comment-id: ${{ steps.find_comment.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + body: | + ## ❌ Plugin Build Failed - if (botComment) { - // Update existing comment - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: botComment.id, - body: commentBody - }); - } else { - // Create new comment - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - } \ No newline at end of file + The workflow tried to build the plugin but couldn't find the zip file. + Please check the [Actions logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details. \ No newline at end of file From 6b21884aedca1f16248eff823cd98d77c1d0a074 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:23:06 +0100 Subject: [PATCH 15/22] Switch to using native GitHub features (workflow summary and artifacts) without third-party actions --- .github/workflows/build-plugin-artifact.yml | 91 ++++++++++++--------- 1 file changed, 51 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 9ab5d27cf..efa0a1357 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -8,7 +8,6 @@ jobs: build-and-upload: runs-on: ubuntu-latest permissions: - pull-requests: read contents: read steps: @@ -50,45 +49,57 @@ jobs: else echo "build_success=false" >> $GITHUB_OUTPUT fi - - - name: Find Comment - uses: peter-evans/find-comment@v2 - id: find_comment - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: 'github-actions[bot]' - body-includes: Plugin Build - - name: Create Success Comment - if: steps.check_build.outputs.build_success == 'true' - uses: peter-evans/create-or-update-comment@v2 - with: - comment-id: ${{ steps.find_comment.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - ## 📦 Plugin Build Ready - - **Build Information:** - - PR: #${{ github.event.pull_request.number }} - - Commit: ${{ github.sha }} - - File Size: ${{ steps.check_build.outputs.filesize }} - - Build Date: ${{ github.event.pull_request.updated_at }} - - The latest built version of this plugin is ready. To download: - - 1. [Go to the Actions run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) - 2. Scroll to the bottom and look for the "Artifacts" section - 3. Download the "facebook-for-woocommerce" zip file - edit-mode: replace + - name: Create build info file + run: | + mkdir -p build-info + echo "# Plugin Build Information" > build-info/README.md + echo "" >> build-info/README.md + echo "- PR: #${{ github.event.pull_request.number }}" >> build-info/README.md + echo "- Commit: ${{ github.sha }}" >> build-info/README.md + echo "- Repository: ${{ github.repository }}" >> build-info/README.md + echo "- Workflow Run: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> build-info/README.md - - name: Create Failure Comment - if: steps.check_build.outputs.build_success == 'false' - uses: peter-evans/create-or-update-comment@v2 - with: - comment-id: ${{ steps.find_comment.outputs.comment-id }} - issue-number: ${{ github.event.pull_request.number }} - body: | - ## ❌ Plugin Build Failed + if [[ "${{ steps.check_build.outputs.build_success }}" == "true" ]]; then + echo "- Status: ✅ Success" >> build-info/README.md + echo "- File Size: ${{ steps.check_build.outputs.filesize }}" >> build-info/README.md - The workflow tried to build the plugin but couldn't find the zip file. - Please check the [Actions logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details. \ No newline at end of file + echo "## Download Instructions" >> build-info/README.md + echo "" >> build-info/README.md + echo "1. Go to [Actions Run #${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> build-info/README.md + echo "2. Scroll to the bottom of the page" >> build-info/README.md + echo "3. Under 'Artifacts', download 'facebook-for-woocommerce'" >> build-info/README.md + else + echo "- Status: ❌ Failed" >> build-info/README.md + echo "" >> build-info/README.md + echo "Build failed. Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." >> build-info/README.md + fi + + - name: Upload build info + uses: actions/upload-artifact@master + with: + name: build-info + path: build-info/ + + - name: Generate workflow summary + run: | + echo "# 📦 Facebook for WooCommerce - Build Summary" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "## Build Information" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **PR:** [#${{ github.event.pull_request.number }}](https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }})" >> $GITHUB_STEP_SUMMARY + echo "- **Commit:** [\`${GITHUB_SHA:0:7}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY + + if [[ "${{ steps.check_build.outputs.build_success }}" == "true" ]]; then + echo "- **Status:** ✅ Build Successful" >> $GITHUB_STEP_SUMMARY + echo "- **Size:** ${{ steps.check_build.outputs.filesize }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "## Download Instructions" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "1. Scroll to the bottom of this page" >> $GITHUB_STEP_SUMMARY + echo "2. Look for the 'Artifacts' section" >> $GITHUB_STEP_SUMMARY + echo "3. Download the 'facebook-for-woocommerce' zip file" >> $GITHUB_STEP_SUMMARY + else + echo "- **Status:** ❌ Build Failed" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "No plugin zip file was created. Please check the logs for more information." >> $GITHUB_STEP_SUMMARY \ No newline at end of file From 19ef4a65e9c5a76f8407bcec16112747dcb5ea4a Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:26:06 +0100 Subject: [PATCH 16/22] Fix syntax error by simplifying the workflow summary --- .github/workflows/build-plugin-artifact.yml | 24 ++------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index efa0a1357..f5aa967f0 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -81,25 +81,5 @@ jobs: name: build-info path: build-info/ - - name: Generate workflow summary - run: | - echo "# 📦 Facebook for WooCommerce - Build Summary" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "## Build Information" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "- **PR:** [#${{ github.event.pull_request.number }}](https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }})" >> $GITHUB_STEP_SUMMARY - echo "- **Commit:** [\`${GITHUB_SHA:0:7}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }})" >> $GITHUB_STEP_SUMMARY - - if [[ "${{ steps.check_build.outputs.build_success }}" == "true" ]]; then - echo "- **Status:** ✅ Build Successful" >> $GITHUB_STEP_SUMMARY - echo "- **Size:** ${{ steps.check_build.outputs.filesize }}" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "## Download Instructions" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "1. Scroll to the bottom of this page" >> $GITHUB_STEP_SUMMARY - echo "2. Look for the 'Artifacts' section" >> $GITHUB_STEP_SUMMARY - echo "3. Download the 'facebook-for-woocommerce' zip file" >> $GITHUB_STEP_SUMMARY - else - echo "- **Status:** ❌ Build Failed" >> $GITHUB_STEP_SUMMARY - echo "" >> $GITHUB_STEP_SUMMARY - echo "No plugin zip file was created. Please check the logs for more information." >> $GITHUB_STEP_SUMMARY \ No newline at end of file + - name: Create simple summary + run: echo "⬇️ Scroll to the bottom of this page and download the 'facebook-for-woocommerce' artifact to get the latest plugin build." > $GITHUB_STEP_SUMMARY \ No newline at end of file From 3b8e32e8cd2e4a82bbeac1eb7280370ef7b2d454 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:30:10 +0100 Subject: [PATCH 17/22] Use native GitHub API to add comments to PR, with cleaner syntax --- .github/workflows/build-plugin-artifact.yml | 85 +++++++++++++-------- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index f5aa967f0..542d7f7f6 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -9,6 +9,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + pull-requests: write # This is needed for commenting on PRs steps: - uses: actions/checkout@v1 @@ -49,37 +50,57 @@ jobs: else echo "build_success=false" >> $GITHUB_OUTPUT fi - - - name: Create build info file - run: | - mkdir -p build-info - echo "# Plugin Build Information" > build-info/README.md - echo "" >> build-info/README.md - echo "- PR: #${{ github.event.pull_request.number }}" >> build-info/README.md - echo "- Commit: ${{ github.sha }}" >> build-info/README.md - echo "- Repository: ${{ github.repository }}" >> build-info/README.md - echo "- Workflow Run: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> build-info/README.md - - if [[ "${{ steps.check_build.outputs.build_success }}" == "true" ]]; then - echo "- Status: ✅ Success" >> build-info/README.md - echo "- File Size: ${{ steps.check_build.outputs.filesize }}" >> build-info/README.md - - echo "## Download Instructions" >> build-info/README.md - echo "" >> build-info/README.md - echo "1. Go to [Actions Run #${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> build-info/README.md - echo "2. Scroll to the bottom of the page" >> build-info/README.md - echo "3. Under 'Artifacts', download 'facebook-for-woocommerce'" >> build-info/README.md - else - echo "- Status: ❌ Failed" >> build-info/README.md - echo "" >> build-info/README.md - echo "Build failed. Please check the [workflow logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})." >> build-info/README.md - fi - - - name: Upload build info - uses: actions/upload-artifact@master - with: - name: build-info - path: build-info/ - name: Create simple summary - run: echo "⬇️ Scroll to the bottom of this page and download the 'facebook-for-woocommerce' artifact to get the latest plugin build." > $GITHUB_STEP_SUMMARY \ No newline at end of file + run: echo "⬇️ Scroll to the bottom of this page and download the 'facebook-for-woocommerce' artifact to get the latest plugin build." > $GITHUB_STEP_SUMMARY + + - name: Add comment to PR (using GitHub API) + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const prNumber = context.issue.number; + const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const commitSha = context.sha.substring(0, 7); + + let commentBody = ""; + + if ("${{ steps.check_build.outputs.build_success }}" === "true") { + commentBody = `📦 **Plugin Build Ready**\n\nPR: #${prNumber}\nCommit: ${commitSha}\nSize: ${{ steps.check_build.outputs.filesize }}\n\n**Download:**\nGo to Actions tab → [This workflow run](${runUrl}) → Scroll to bottom → Download "facebook-for-woocommerce" artifact`; + } else { + commentBody = `❌ **Plugin Build Failed**\n\nPR: #${prNumber}\nCommit: ${commitSha}\n\n**Details:**\nThe build process did not produce a plugin zip file.\nPlease check the [workflow logs](${runUrl}) for more information.`; + } + + // List all comments in the PR + const { data: comments } = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber + }); + + // Find our previous comment if it exists + const buildComment = comments.find(comment => { + return comment.user.login === 'github-actions[bot]' && + (comment.body.includes('Plugin Build Ready') || + comment.body.includes('Plugin Build Failed')); + }); + + if (buildComment) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: buildComment.id, + body: commentBody + }); + console.log("Updated existing comment"); + } else { + // Create new comment + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + console.log("Created new comment"); + } \ No newline at end of file From feb824369dbfda1cdb287fee5c82b3550d8c5b7d Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Sun, 13 Apr 2025 12:37:53 +0100 Subject: [PATCH 18/22] Fix permission issues by using GitHub's built-in commenting functionality --- .github/workflows/build-plugin-artifact.yml | 76 ++++++++++++--------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 542d7f7f6..eae1a00a1 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - pull-requests: write # This is needed for commenting on PRs + pull-requests: write steps: - uses: actions/checkout@v1 @@ -54,53 +54,61 @@ jobs: - name: Create simple summary run: echo "⬇️ Scroll to the bottom of this page and download the 'facebook-for-woocommerce' artifact to get the latest plugin build." > $GITHUB_STEP_SUMMARY - - name: Add comment to PR (using GitHub API) + - name: Update PR description uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const prNumber = context.issue.number; + // Get PR number from pull_request event + const prNumber = context.payload.pull_request.number; + console.log(`Updating description for PR #${prNumber}`); + + // Get the current PR description + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const timestamp = new Date().toISOString(); const commitSha = context.sha.substring(0, 7); - let commentBody = ""; - + // Create build info section + let buildInfoSection = ''; if ("${{ steps.check_build.outputs.build_success }}" === "true") { - commentBody = `📦 **Plugin Build Ready**\n\nPR: #${prNumber}\nCommit: ${commitSha}\nSize: ${{ steps.check_build.outputs.filesize }}\n\n**Download:**\nGo to Actions tab → [This workflow run](${runUrl}) → Scroll to bottom → Download "facebook-for-woocommerce" artifact`; + buildInfoSection = "## 📦 Latest Plugin Build\n\n" + + `**Built at:** ${timestamp}\n` + + `**Commit:** ${commitSha}\n` + + `**Size:** ${{ steps.check_build.outputs.filesize }}\n\n` + + `**Download:** [Click here to download the plugin](${runUrl})\n\n` + + `_To download: Click the link above → Scroll to bottom → Download "facebook-for-woocommerce" artifact_`; } else { - commentBody = `❌ **Plugin Build Failed**\n\nPR: #${prNumber}\nCommit: ${commitSha}\n\n**Details:**\nThe build process did not produce a plugin zip file.\nPlease check the [workflow logs](${runUrl}) for more information.`; + buildInfoSection = "## ❌ Plugin Build Failed\n\n" + + `**Attempted at:** ${timestamp}\n` + + `**Commit:** ${commitSha}\n\n` + + `Please check the [workflow logs](${runUrl}) for more information.`; } - // List all comments in the PR - const { data: comments } = await github.rest.issues.listComments({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber - }); + // Update PR description + let body = pr.body || ''; - // Find our previous comment if it exists - const buildComment = comments.find(comment => { - return comment.user.login === 'github-actions[bot]' && - (comment.body.includes('Plugin Build Ready') || - comment.body.includes('Plugin Build Failed')); - }); + // Remove existing build section if it exists + body = body.replace(/## 📦 Latest Plugin Build[\s\S]*?(?=##|$)/g, ''); + body = body.replace(/## ❌ Plugin Build Failed[\s\S]*?(?=##|$)/g, ''); - if (buildComment) { - // Update existing comment - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: buildComment.id, - body: commentBody - }); - console.log("Updated existing comment"); - } else { - // Create new comment - await github.rest.issues.createComment({ + // Add new build section + body = body + '\n\n' + buildInfoSection; + + // Update the PR + try { + await github.rest.pulls.update({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: prNumber, - body: commentBody + pull_number: prNumber, + body: body }); - console.log("Created new comment"); + console.log("Successfully updated PR description"); + } catch (error) { + console.log("Error updating PR description:", error); } \ No newline at end of file From 1c2972284439af50da7b19ba11f265f56b1dc4f5 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Wed, 16 Apr 2025 13:27:08 +0100 Subject: [PATCH 19/22] Fix: Replace PR description update with PR comment for better permission handling --- .github/workflows/build-plugin-artifact.yml | 41 ++++++--------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index eae1a00a1..c97c912b8 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -54,61 +54,44 @@ jobs: - name: Create simple summary run: echo "⬇️ Scroll to the bottom of this page and download the 'facebook-for-woocommerce' artifact to get the latest plugin build." > $GITHUB_STEP_SUMMARY - - name: Update PR description + - name: Post build info comment on PR uses: actions/github-script@v6 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | // Get PR number from pull_request event const prNumber = context.payload.pull_request.number; - console.log(`Updating description for PR #${prNumber}`); - - // Get the current PR description - const { data: pr } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber - }); + console.log(`Posting comment for PR #${prNumber}`); const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; const timestamp = new Date().toISOString(); const commitSha = context.sha.substring(0, 7); - // Create build info section - let buildInfoSection = ''; + // Create build info comment + let commentBody = ''; if ("${{ steps.check_build.outputs.build_success }}" === "true") { - buildInfoSection = "## 📦 Latest Plugin Build\n\n" + + commentBody = "## 📦 Latest Plugin Build\n\n" + `**Built at:** ${timestamp}\n` + `**Commit:** ${commitSha}\n` + `**Size:** ${{ steps.check_build.outputs.filesize }}\n\n` + `**Download:** [Click here to download the plugin](${runUrl})\n\n` + `_To download: Click the link above → Scroll to bottom → Download "facebook-for-woocommerce" artifact_`; } else { - buildInfoSection = "## ❌ Plugin Build Failed\n\n" + + commentBody = "## ❌ Plugin Build Failed\n\n" + `**Attempted at:** ${timestamp}\n` + `**Commit:** ${commitSha}\n\n` + `Please check the [workflow logs](${runUrl}) for more information.`; } - // Update PR description - let body = pr.body || ''; - - // Remove existing build section if it exists - body = body.replace(/## 📦 Latest Plugin Build[\s\S]*?(?=##|$)/g, ''); - body = body.replace(/## ❌ Plugin Build Failed[\s\S]*?(?=##|$)/g, ''); - - // Add new build section - body = body + '\n\n' + buildInfoSection; - - // Update the PR + // Post comment on the PR try { - await github.rest.pulls.update({ + await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - pull_number: prNumber, - body: body + issue_number: prNumber, + body: commentBody }); - console.log("Successfully updated PR description"); + console.log("Successfully posted comment on PR"); } catch (error) { - console.log("Error updating PR description:", error); + console.log("Error posting comment on PR:", error); } \ No newline at end of file From 75092c2bb6d595cb78346be0a147dd14817c0d77 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Wed, 16 Apr 2025 13:28:49 +0100 Subject: [PATCH 20/22] Fix: Update Node.js setup to resolve cache error --- .github/workflows/build-plugin-artifact.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index c97c912b8..7156cf000 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -21,9 +21,10 @@ jobs: tools: composer - name: Setup Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: '16' + cache-dependency-path: './package-lock.json' cache: 'npm' - name: Install dependencies From fe26d760d97f330eabf0b086ffe35f30c240e078 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Wed, 16 Apr 2025 13:31:13 +0100 Subject: [PATCH 21/22] Fix: Improve PR comment handling with better permission restrictions --- .github/workflows/build-plugin-artifact.yml | 39 ++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 7156cf000..96e2e6379 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -62,7 +62,7 @@ jobs: script: | // Get PR number from pull_request event const prNumber = context.payload.pull_request.number; - console.log(`Posting comment for PR #${prNumber}`); + console.log(`Preparing build info for PR #${prNumber}`); const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; const timestamp = new Date().toISOString(); @@ -84,15 +84,30 @@ jobs: `Please check the [workflow logs](${runUrl}) for more information.`; } - // Post comment on the PR - try { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - console.log("Successfully posted comment on PR"); - } catch (error) { - console.log("Error posting comment on PR:", error); + // First try to detect if we're in a fork by checking the repository owner + const isMainRepo = context.repo.owner === 'facebook'; + + // Add build info to workflow summary regardless + core.summary + .addHeading(("${{ steps.check_build.outputs.build_success }}" === "true") ? + "📦 Latest Plugin Build" : "❌ Plugin Build Failed") + .addRaw(commentBody) + .write(); + + // Try to post comment if we think we have permissions + if (!isMainRepo) { + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + console.log("Successfully posted comment on PR"); + } catch (error) { + console.log("Note: Unable to post comment to PR. This is normal if this is a fork PR. Build information is available in the workflow summary."); + } + } else { + console.log("Skipping PR comment because this appears to be running on the main facebook repository where comment permissions may be restricted."); + console.log("Build information is available in the workflow summary."); } \ No newline at end of file From f29978e15fba3a1c4fe5bc5fb483ad539ac6c201 Mon Sep 17 00:00:00 2001 From: David Evbodaghe Date: Wed, 16 Apr 2025 13:36:32 +0100 Subject: [PATCH 22/22] Always attempt to post PR comments regardless of repository ownership --- .github/workflows/build-plugin-artifact.yml | 45 ++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build-plugin-artifact.yml b/.github/workflows/build-plugin-artifact.yml index 96e2e6379..2cf64c6c9 100644 --- a/.github/workflows/build-plugin-artifact.yml +++ b/.github/workflows/build-plugin-artifact.yml @@ -84,9 +84,6 @@ jobs: `Please check the [workflow logs](${runUrl}) for more information.`; } - // First try to detect if we're in a fork by checking the repository owner - const isMainRepo = context.repo.owner === 'facebook'; - // Add build info to workflow summary regardless core.summary .addHeading(("${{ steps.check_build.outputs.build_success }}" === "true") ? @@ -94,20 +91,30 @@ jobs: .addRaw(commentBody) .write(); - // Try to post comment if we think we have permissions - if (!isMainRepo) { - try { - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: prNumber, - body: commentBody - }); - console.log("Successfully posted comment on PR"); - } catch (error) { - console.log("Note: Unable to post comment to PR. This is normal if this is a fork PR. Build information is available in the workflow summary."); - } - } else { - console.log("Skipping PR comment because this appears to be running on the main facebook repository where comment permissions may be restricted."); - console.log("Build information is available in the workflow summary."); + // Always try to post a comment, regardless of repository ownership + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + console.log("Successfully posted comment on PR"); + } catch (error) { + console.log("Unable to post comment to PR. Build information is still available in the workflow summary."); + console.log(`Error details: ${error.message}`); + } + + // Always try to post a comment + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: prNumber, + body: commentBody + }); + console.log("Successfully posted comment on PR"); + } catch (error) { + console.log("Unable to post comment to PR. Build information is still available in the workflow summary."); + console.log(`Error details: ${error.message}`); } \ No newline at end of file