mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
212 lines
7.5 KiB
YAML
212 lines
7.5 KiB
YAML
name: PR Playground Demo
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, reopened]
|
|
paths:
|
|
- 'src/**'
|
|
- 'assets/**'
|
|
- 'package.json'
|
|
- 'composer.json'
|
|
workflow_run:
|
|
workflows: ["PR Playground Demo"]
|
|
types:
|
|
- completed
|
|
push:
|
|
branches:
|
|
- 'PCP-5039-*'
|
|
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:
|
|
create_archive:
|
|
runs-on: ubuntu-latest
|
|
# Only run for the main repository, not forks, and allow push events on PCP-5039 branches
|
|
if: >
|
|
github.repository == 'woocommerce/woocommerce-paypal-payments' &&
|
|
(github.event_name == 'pull_request' ||
|
|
(github.event_name == 'push' && startsWith(github.ref_name, 'PCP-5039-')))
|
|
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 || '0' }}-${VERSUFFIX}"
|
|
ARTIFACT_NAME="woocommerce-paypal-payments-${PR_VERSION}"
|
|
echo "plugin_version=$PR_VERSION" >> $GITHUB_OUTPUT
|
|
echo "artifact_name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
|
|
|
|
- name: Build plugin archive
|
|
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: ${{ steps.version.outputs.plugin_version }}
|
|
PLUGIN_FOLDER_NAME: woocommerce-paypal-payments
|
|
ARCHIVE_NAME: ${{ steps.version.outputs.artifact_name }}
|
|
COMPILE_ASSETS_ARGS: "-vv --env=root"
|
|
|
|
- name: Save PR details
|
|
run: |
|
|
mkdir -p ./pr
|
|
echo "${{ github.event.pull_request.number || '0' }}" > ./pr/NR
|
|
echo "${{ steps.version.outputs.plugin_version }}" > ./pr/VERSION
|
|
echo "${{ steps.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
|
|
permissions:
|
|
issues: write
|
|
pull-requests: write
|
|
# Only run on workflow_run events from successful builds, and only for the main repo
|
|
if: >
|
|
github.repository == 'woocommerce/woocommerce-paypal-payments' &&
|
|
github.event_name == 'workflow_run' &&
|
|
github.event.workflow_run.event == 'pull_request' &&
|
|
github.event.workflow_run.conclusion == 'success'
|
|
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: ${{ github.event.workflow_run.id }},
|
|
});
|
|
|
|
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 issue_number = Number(fs.readFileSync('./NR'));
|
|
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;
|
|
|
|
// Create a mock context for the script
|
|
const mockContext = {
|
|
...context,
|
|
issue: { number: issue_number },
|
|
runId: ${{ github.event.workflow_run.id }},
|
|
payload: {
|
|
pull_request: {
|
|
head: {
|
|
sha: '${{ github.event.workflow_run.head_sha }}'
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
await script.run({ github, context: mockContext, core });
|
|
|
|
# =============================================================================
|
|
# TEMPORARY TESTING JOB - REMOVE AFTER TESTING COMPLETE
|
|
# =============================================================================
|
|
|
|
temporary_comment_testing:
|
|
name: "[TEMP] Test Comment on PR #3574"
|
|
runs-on: ubuntu-latest
|
|
needs: create_archive
|
|
permissions:
|
|
issues: write
|
|
pull-requests: write
|
|
# TEMPORARY: Only for testing workflow development on PCP-5039 branches
|
|
if: >
|
|
github.repository == 'woocommerce/woocommerce-paypal-payments' &&
|
|
github.event_name == 'push' &&
|
|
startsWith(github.ref_name, 'PCP-5039-') &&
|
|
needs.create_archive.result == 'success'
|
|
|
|
steps:
|
|
- name: "[TEMP] Checkout for testing"
|
|
uses: actions/checkout@v4
|
|
|
|
- name: "[TEMP] Test comment on PR #3574"
|
|
uses: actions/github-script@v7
|
|
env:
|
|
PLUGIN_VERSION: ${{ needs.create_archive.outputs.plugin_version }}
|
|
ARTIFACT_NAME: ${{ needs.create_archive.outputs.artifact_name }}
|
|
with:
|
|
script: |
|
|
console.log("🧪 TEMPORARY TESTING: Testing comment on PR #3574");
|
|
|
|
const script = require('./.github/scripts/playground-comment.js');
|
|
|
|
// Direct context for PR #3574
|
|
const mockContext = {
|
|
...context,
|
|
issue: { number: 3574 },
|
|
runId: context.runId,
|
|
payload: {
|
|
pull_request: {
|
|
head: {
|
|
sha: '${{ github.sha }}'
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
console.log("🧪 TEMPORARY TESTING: Posting comment to PR #3574");
|
|
await script.run({ github, context: mockContext, core });
|
|
console.log("🧪 TEMPORARY TESTING: Comment posted successfully");
|
|
|
|
# =============================================================================
|
|
# END TEMPORARY TESTING SECTION
|
|
# =============================================================================
|