Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(ci): mirror the PHP SDK only from an up-to-date main

Yudhi Armyndharis0c3e56495f3f
diff --git a/.github/workflows/split-php-sdk.yml b/.github/workflows/split-php-sdk.yml
index b6a8b1511..bbe79c488 100644
--- a/.github/workflows/split-php-sdk.yml
+++ b/.github/workflows/split-php-sdk.yml
@@ -32,6 +32,7 @@ concurrency:
jobs:
test:
name: PHP SDK tests
+ if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
timeout-minutes: 15
defaults:
@@ -47,6 +48,7 @@ jobs:
split:
name: Mirror sdk/php -> rmyndharis/openwa-php
+ if: github.ref == 'refs/heads/main'
# Never mirror an untested (red) SDK to Packagist dev-main.
needs: [test]
runs-on: ubuntu-latest
@@ -68,6 +70,13 @@ jobs:
fi
git config user.name "rmyndharis"
git config user.email "[email protected]"
+ # An unrelated main commit schedules no replacement run under the SDK path filter.
+ # Compare SDK content, retaining the tested HEAD for the split and the push.
+ git fetch --no-tags origin refs/heads/main
+ if [ "$(git rev-parse HEAD:sdk/php)" != "$(git rev-parse FETCH_HEAD:sdk/php)" ]; then
+ echo "::notice::Source main has different PHP content; leaving the mirror to its tested run"
+ exit 0
+ fi
SPLIT_SHA="$(git subtree split --prefix=sdk/php HEAD)"
echo "Split SHA: $SPLIT_SHA"
# Hooks off: nothing in this job runs project code, so none are expected, and none may run with the
diff --git a/src/common/split-php-sdk-workflow.spec.ts b/src/common/split-php-sdk-workflow.spec.ts
new file mode 100644
index 000000000..a4336eb11
--- /dev/null
+++ b/src/common/split-php-sdk-workflow.spec.ts
@@ -0,0 +1,33 @@
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { load } from 'js-yaml';
+
+type Job = { if?: string; steps?: { name?: string; run?: string }[] };
+type Workflow = { jobs: Record<string, Job> };
+
+/**
+ * The job force-pushes the SDK tree to the mirror's main, which is what Packagist reads as dev-main.
+ * A manual run on another ref, or a re-run of an older push after a newer SDK change was mirrored,
+ * must not replace it.
+ */
+describe('split-php-sdk.yml', () => {
+ const workflow = load(
+ readFileSync(join(__dirname, '..', '..', '.github', 'workflows', 'split-php-sdk.yml'), 'utf8'),
+ ) as Workflow;
+
+ it.each(['test', 'split'])('runs the %s job only on main', job => {
+ expect(workflow.jobs[job].if).toBe("github.ref == 'refs/heads/main'");
+ });
+
+ it('pushes only after the checked-out SDK tree is compared with the one on main', () => {
+ const run = workflow.jobs.split.steps?.find(step => step.name?.startsWith('Split and force-push'))?.run ?? '';
+ const lines = run.split('\n').map(line => line.trim());
+ const fetch = lines.findIndex(line => line.startsWith('git fetch') && line.endsWith('refs/heads/main'));
+ const compare = lines.findIndex(line => line.includes('HEAD:sdk/php') && line.includes('FETCH_HEAD:sdk/php'));
+ const push = lines.findIndex(line => line.includes('push --force'));
+
+ expect(fetch).toBeGreaterThan(-1);
+ expect(compare).toBeGreaterThan(fetch);
+ expect(push).toBeGreaterThan(compare);
+ });
+});