From 8a09b63afce87fa81c343dcd63ec290ca3a9c21e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 11:00:24 +0000 Subject: [PATCH 1/3] Initial plan From b0d5d373fd774bb8d2315ef767a3c69b67e1e905 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 11:06:03 +0000 Subject: [PATCH 2/3] Add PHP SDK publish workflow for Packagist Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com> --- .github/workflows/php.yml | 25 ++++++ php/PUBLISHING.md | 164 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 php/PUBLISHING.md diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9dafd06..0f9ec8b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -57,3 +57,28 @@ jobs: file: php/coverage.xml flags: php fail_ci_if_error: false + + publish: + name: Publish to Packagist + runs-on: ubuntu-latest + needs: test + if: startsWith(github.ref, 'refs/tags/v') + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Extract version from tag + id: get_version + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION" + + - name: Trigger Packagist update + run: | + curl -X POST \ + -H "Content-Type: application/json" \ + "https://packagist.org/api/update-package?username=${{ secrets.PACKAGIST_USERNAME }}&apiToken=${{ secrets.PACKAGIST_API_TOKEN }}" \ + -d '{"repository":{"url":"https://github.com/json-structure/sdk"}}' diff --git a/php/PUBLISHING.md b/php/PUBLISHING.md new file mode 100644 index 0000000..cbe9cb9 --- /dev/null +++ b/php/PUBLISHING.md @@ -0,0 +1,164 @@ +# Publishing to Packagist + +This document describes how to publish the PHP SDK to Packagist. + +## Prerequisites + +### 1. Packagist Account + +Create an account at https://packagist.org/ + +Packagist is the main Composer repository for PHP packages. You'll need an account to register and manage packages. + +### 2. Register Package on Packagist + +1. Log in to https://packagist.org/ +2. Go to "Submit" or "Submit Package" +3. Enter the GitHub repository URL: `https://github.com/json-structure/sdk` +4. Submit the package + +### 3. Generate Packagist API Token + +1. Go to your Packagist profile settings +2. Navigate to "API Token" section +3. Generate a new API token with "Update" permission +4. Copy the token - you'll need it for GitHub secrets + +### 4. GitHub Secrets + +Configure these secrets in your repository settings (Settings → Secrets and variables → Actions): + +- `PACKAGIST_USERNAME`: Your Packagist username +- `PACKAGIST_API_TOKEN`: Your Packagist API token (from step 3) + +## Automated Release Process + +The CI workflow automatically notifies Packagist when you push a version tag. + +### Creating a Release + +1. Ensure all tests pass on the main branch +2. Create and push a version tag: + +```bash +git tag v0.1.0 +git push origin v0.1.0 +``` + +### What Happens Automatically + +The CI workflow will: + +1. ✅ Run all tests across multiple PHP versions (8.1, 8.2, 8.3) +2. ✅ Validate composer.json +3. ✅ Extract version from the git tag +4. ✅ Trigger Packagist update via API + +### Tag Format + +Tags must follow the pattern `v[0-9]+.[0-9]+.[0-9]+`: + +- `v0.1.0` - Initial release +- `v0.1.1` - Patch release +- `v1.0.0` - Major release + +## How Packagist Works + +Packagist reads version information directly from your GitHub repository tags. You don't need to manually update the version in `composer.json` - Packagist automatically: + +1. Detects git tags matching semantic versioning (e.g., `v1.0.0`, `1.0.0`) +2. Creates corresponding package versions +3. Makes them available via `composer require json-structure/sdk` + +### Version Detection + +When you push a tag like `v1.2.3`, Packagist will: +- Create version `1.2.3` for users to install +- Read package metadata from `composer.json` on that tagged commit +- Make it installable via: `composer require json-structure/sdk:^1.2.3` + +## Manual Trigger + +If you need to manually trigger a Packagist update: + +### Using the API + +```bash +curl -X POST \ + -H "Content-Type: application/json" \ + "https://packagist.org/api/update-package?username=YOUR_USERNAME&apiToken=YOUR_API_TOKEN" \ + -d '{"repository":{"url":"https://github.com/json-structure/sdk"}}' +``` + +### Using the Web Interface + +1. Log in to Packagist +2. Go to your package page +3. Click "Update" button to force a sync + +## Verification + +After publishing: + +1. Check https://packagist.org/packages/json-structure/sdk +2. Verify the new version appears in the versions list +3. Test installation: + +```bash +composer require json-structure/sdk +``` + +Or for a specific version: + +```bash +composer require json-structure/sdk:^0.1.0 +``` + +## Troubleshooting + +### Package Not Updating + +- Verify the GitHub webhook is configured (Packagist should set this automatically) +- Manually trigger an update using the Packagist web interface +- Check that the API credentials in GitHub secrets are correct + +### Version Not Appearing + +- Ensure your tag follows semantic versioning (e.g., `v1.0.0` or `1.0.0`) +- Check that `composer.json` is valid: `composer validate --strict` +- Wait a few minutes - Packagist may take time to index + +### First-Time Setup + +For the first publication: + +1. Register the package on Packagist manually +2. Packagist will set up a GitHub webhook automatically +3. Subsequent updates will be automatic (or use the CI workflow) + +## GitHub Webhook (Recommended) + +For fully automatic updates without CI: + +1. Packagist sets up a GitHub webhook when you register your package +2. Every push to GitHub (including tags) triggers Packagist to re-index +3. No manual intervention or API calls needed + +To verify the webhook: +1. Go to your GitHub repo → Settings → Webhooks +2. Look for a webhook pointing to `packagist.org` +3. Check recent deliveries to ensure it's working + +## Version Management + +The version is managed through git tags. The `composer.json` file does not need a version field when publishing via Packagist, as versions are determined by your git tags. + +However, if you want to include a version field in `composer.json` for local development, you can add: + +```json +{ + "version": "0.1.0" +} +``` + +Note: This version field is ignored by Packagist in favor of git tags. From 0148468291abac6589913becf310c4b32275916f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 8 Dec 2025 11:07:56 +0000 Subject: [PATCH 3/3] Improve Packagist API error handling in publish workflow Co-authored-by: clemensv <542030+clemensv@users.noreply.github.com> --- .github/workflows/php.yml | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 0f9ec8b..a783c2f 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -78,7 +78,20 @@ jobs: - name: Trigger Packagist update run: | - curl -X POST \ + response=$(curl -X POST \ + --fail-with-body \ -H "Content-Type: application/json" \ + -w "\nHTTP_CODE:%{http_code}" \ "https://packagist.org/api/update-package?username=${{ secrets.PACKAGIST_USERNAME }}&apiToken=${{ secrets.PACKAGIST_API_TOKEN }}" \ - -d '{"repository":{"url":"https://github.com/json-structure/sdk"}}' + -d '{"repository":{"url":"https://github.com/json-structure/sdk"}}') + + echo "$response" + + http_code=$(echo "$response" | \ + grep -o "HTTP_CODE:[0-9]*" | cut -d: -f2) + if [ "$http_code" != "200" ] && [ "$http_code" != "202" ]; then + echo "Error: Packagist API returned HTTP $http_code" + exit 1 + fi + + echo "Successfully triggered Packagist update (HTTP $http_code)"