Skip to content
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3dfc553
Add workflow to build plugin artifact and update PR description
Apr 13, 2025
f1f370d
Fix: Update upload-artifact action to v2 and fix deprecated set-outpu…
Apr 13, 2025
8577ee2
Add local testing script for build workflow
Apr 13, 2025
399aa69
Update GitHub Actions to more stable versions, use upload-artifact@v1
Apr 13, 2025
74d0f76
Downgrade checkout action to v1
Apr 13, 2025
27c7291
Completely redesign workflow to avoid using upload-artifact action
Apr 13, 2025
595de5f
Fix git authentication in workflow
Apr 13, 2025
d0b5bc8
Change workflow to use PR description for build instructions instead …
Apr 13, 2025
305b8e8
Update workflow to use GitHub Actions artifacts with download instruc…
Apr 13, 2025
be38430
Create simplified workflow without problematic upload-artifact action
Apr 13, 2025
97ee5db
Simplify workflow to use standard comment approach without custom logic
Apr 13, 2025
2285392
Fix permission issues by using GitHub's built-in commenting functiona…
Apr 13, 2025
dcb7123
Fix permission issues by using GitHub's built-in commenting functiona…
Apr 13, 2025
8b85bd6
Use peter-evans comment actions for automatic PR commenting
Apr 13, 2025
6b21884
Switch to using native GitHub features (workflow summary and artifact…
Apr 13, 2025
19ef4a6
Fix syntax error by simplifying the workflow summary
Apr 13, 2025
3b8e32e
Use native GitHub API to add comments to PR, with cleaner syntax
Apr 13, 2025
feb8243
Fix permission issues by using GitHub's built-in commenting functiona…
Apr 13, 2025
1c29722
Fix: Replace PR description update with PR comment for better permiss…
Apr 16, 2025
75092c2
Fix: Update Node.js setup to resolve cache error
Apr 16, 2025
fe26d76
Fix: Improve PR comment handling with better permission restrictions
Apr 16, 2025
f29978e
Always attempt to post PR comments regardless of repository ownership
Apr 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/build-plugin-artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Build Plugin Artifact

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build-and-upload:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write

steps:
- uses: actions/checkout@v1

- 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-dependency-path: './package-lock.json'
cache: 'npm'

- name: Install dependencies
run: |
npm ci || npm install
composer install

- name: Build plugin
run: npm run build

- 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 "build_success=true" >> $GITHUB_OUTPUT
echo "filesize=$(du -h facebook-for-woocommerce.zip | cut -f1)" >> $GITHUB_OUTPUT
else
echo "build_success=false" >> $GITHUB_OUTPUT
fi

- 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: 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(`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();
const commitSha = context.sha.substring(0, 7);

// Create build info comment
let commentBody = '';
if ("${{ steps.check_build.outputs.build_success }}" === "true") {
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 {
commentBody = "## ❌ Plugin Build Failed\n\n" +
`**Attempted at:** ${timestamp}\n` +
`**Commit:** ${commitSha}\n\n` +
`Please check the [workflow logs](${runUrl}) for more information.`;
}

// 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();

// 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}`);
}