Merge branch 'trunk' into PCP-4791-vaulting-my-account-pay-pal-gateway-and-button-should-not-be-displayed-when-customer-already-has-vaulted-pay-pal-account

This commit is contained in:
Emili Castells Guasch 2025-08-12 15:08:47 +02:00
commit efb5c4afd3
No known key found for this signature in database
2 changed files with 309 additions and 0 deletions

160
.github/scripts/playground-comment.js vendored Normal file
View file

@ -0,0 +1,160 @@
const generateWordpressPlaygroundBlueprint = (runId, prNumber, artifactName) => {
const defaultSchema = {
landingPage: '/wp-admin/admin.php?page=wc-settings&tab=advanced&section=blueprint&activate-multi=true',
preferredVersions: {
php: '8.0',
wp: 'latest',
},
phpExtensionBundles: ['kitchen-sink'],
// Enable networking for API calls and external connections
features: {
networking: true
},
steps: [
// Step 1: Install and activate WooCommerce
{
step: 'installPlugin',
pluginData: {
resource: 'wordpress.org/plugins',
slug: 'woocommerce'
},
options: {
activate: true
}
},
// Step 2: Install PayPal Payments plugin from PR artifact
{
step: 'installPlugin',
pluginZipFile: {
resource: 'url',
url: `https://playground.wordpress.net/plugin-proxy.php?org=woocommerce&repo=woocommerce-paypal-payments&workflow=PR%20Playground%20Demo&artifact=${artifactName}&pr=${prNumber}`,
},
options: {
activate: true,
},
},
// Step 3: Skip WooCommerce onboarding wizard
{
step: 'setSiteOptions',
options: {
woocommerce_onboarding_profile: {
skipped: true,
},
},
},
// Step 4: Enable Coming Soon mode
{
step: 'setSiteOptions',
options: {
woocommerce_coming_soon: 'yes',
},
},
// Step 5: Set up admin user login
{
step: 'login',
username: 'admin',
password: 'password',
},
],
// Initialize empty plugins array (can be extended later)
plugins: [],
};
return defaultSchema;
};
async function run({ github, context, core }) {
try {
const commentInfo = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
};
// Validate required environment variables
if (!process.env.PLUGIN_VERSION || !process.env.ARTIFACT_NAME) {
core.setFailed('Missing required environment variables: PLUGIN_VERSION or ARTIFACT_NAME');
return;
}
// Check for existing playground comment to update instead of creating duplicate
const comments = await github.rest.issues.listComments(commentInfo);
const existingComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('Test using WordPress Playground')
);
const defaultSchema = generateWordpressPlaygroundBlueprint(
context.runId,
context.issue.number,
process.env.ARTIFACT_NAME
);
const url = `https://playground.wordpress.net/#${JSON.stringify(defaultSchema)}`;
const body = `## Test using WordPress Playground
The changes in this pull request can be previewed and tested using a [WordPress Playground](https://developer.wordpress.org/playground/) instance.
[WordPress Playground](https://developer.wordpress.org/playground/) is an experimental project that creates a full WordPress instance entirely within the browser.
**🔗 [Test this pull request with WordPress Playground](${url})**
### What's included:
- WordPress (latest)
- WooCommerce (latest)
- PayPal Payments plugin v${process.env.PLUGIN_VERSION} (built from this PR)
### Login credentials:
- **Username:** \`admin\`
- **Password:** \`password\`
### Plugin Details:
- **Version:** ${process.env.PLUGIN_VERSION}
- **Commit:** ${context.payload.pull_request.head.sha}
- **Artifact:** ${process.env.ARTIFACT_NAME}
> 💡 The demo environment resets each time you refresh. Perfect for testing!
>
> 🔄 This link updates automatically with each new commit to the PR.
>
> This URL is valid for 30 days from when this comment was last updated.
---
<sub>🤖 Auto-generated for commit ${context.payload.pull_request.head.sha} Last updated: ${new Date().toISOString()}</sub>`;
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: body
});
core.info(`Successfully updated existing playground comment #${existingComment.id} on PR #${context.issue.number}`);
} else {
// Create new comment
await github.rest.issues.createComment({
...commentInfo,
body: body
});
core.info(`Successfully created new playground comment on PR #${context.issue.number}`);
}
} catch (error) {
core.setFailed(`Failed to create/update playground comment: ${error.message}`);
core.error(`Error details: ${error.stack}`);
}
}
module.exports = { run };

149
.github/workflows/pr-playground-demo.yml vendored Normal file
View file

@ -0,0 +1,149 @@
name: PR Playground Demo
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- "src/**"
- "assets/**"
- "package.json"
- "composer.json"
push:
paths:
- "src/**"
- "assets/**"
- "package.json"
- "composer.json"
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
# Disable permissions for all available scopes by default.
permissions: {}
jobs:
prepare_version:
runs-on: ubuntu-latest
# Only run for the main repository, not forks
if: github.repository == 'woocommerce/woocommerce-paypal-payments' && github.event_name == 'pull_request'
outputs:
artifact_name: ${{ steps.version.outputs.artifact_name }}
plugin_version: ${{ steps.version.outputs.plugin_version }}
steps:
- uses: actions/checkout@v4
- name: Set plugin version and artifact name
id: version
run: |
BASE_VERSION=$(sed -nE '/Version:/s/.* ([0-9.]+).*/\1/p' woocommerce-paypal-payments.php)
VERSUFFIX="${GITHUB_RUN_ID}-g$(git rev-parse --short HEAD)"
PR_VERSION="${BASE_VERSION}-pr${{ github.event.pull_request.number }}-${VERSUFFIX}"
ARTIFACT_NAME="woocommerce-paypal-payments-${PR_VERSION}"
echo "plugin_version=$PR_VERSION" >> $GITHUB_OUTPUT
echo "artifact_name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
build_plugin:
needs: prepare_version
uses: inpsyde/reusable-workflows/.github/workflows/build-plugin-archive.yml@a9af34f34e95cbe18703198c7e972e97ebcd7473
with:
PHP_VERSION: 7.4
NODE_VERSION: 22
PLUGIN_MAIN_FILE: ./woocommerce-paypal-payments.php
PLUGIN_VERSION: ${{ needs.prepare_version.outputs.plugin_version }}
PLUGIN_FOLDER_NAME: woocommerce-paypal-payments
ARCHIVE_NAME: ${{ needs.prepare_version.outputs.artifact_name }}
COMPILE_ASSETS_ARGS: "-vv --env=root"
create_archive:
runs-on: ubuntu-latest
needs: [prepare_version, build_plugin]
outputs:
artifact_name: ${{ needs.prepare_version.outputs.artifact_name }}
plugin_version: ${{ needs.prepare_version.outputs.plugin_version }}
steps:
- uses: actions/checkout@v4
- name: Save PR details
run: |
mkdir -p ./pr
echo "${{ github.event.pull_request.number }}" > ./pr/NR
echo "${{ needs.prepare_version.outputs.plugin_version }}" > ./pr/VERSION
echo "${{ needs.prepare_version.outputs.artifact_name }}" > ./pr/ARTIFACT
- name: Upload PR number
uses: actions/upload-artifact@v4
with:
name: pr-details
path: pr/
playground_demo:
name: Comment on PR with Playground details
runs-on: ubuntu-latest
needs: create_archive
permissions:
issues: write
pull-requests: write
# Only run for pull requests in the main repository
if: github.repository == 'woocommerce/woocommerce-paypal-payments' && github.event_name == 'pull_request'
steps:
- uses: actions/checkout@v4
- name: Download PR details artifact
uses: actions/github-script@v7
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
const matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name === 'pr-details'
})[0];
if (!matchArtifact) {
core.setFailed('No pr-details artifact found!');
return;
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.writeFileSync('${{github.workspace}}/pr-details.zip', Buffer.from(download.data));
- name: Unzip PR details
run: unzip pr-details.zip
- name: Create or update PR playground comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const pr_number = fs.readFileSync('./NR', 'utf8').trim();
const plugin_version = fs.readFileSync('./VERSION', 'utf8').trim();
const artifact_name = fs.readFileSync('./ARTIFACT', 'utf8').trim();
// Load the comment script
const script = require('./.github/scripts/playground-comment.js');
// Set environment variables for the script
process.env.PLUGIN_VERSION = plugin_version;
process.env.ARTIFACT_NAME = artifact_name;
const updatedContext = {
...context,
issue: {
number: parseInt(pr_number, 10)
}
};
await script.run({ github, context: updatedContext, core });