From ca054563734d4262f811955ea51575f382d20692 Mon Sep 17 00:00:00 2001 From: Igor Galeta Date: Fri, 14 Aug 2026 15:43:51 +0300 Subject: [PATCH 1/4] ci: add release workflow --- .github/workflows/release.yml | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..0cb4e48 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,90 @@ +name: Publish release to Packagist + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + verify-tag: + name: Verify release tag + runs-on: ubuntu-latest + steps: + - name: Check out the released revision + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + + - name: Verify release tag matches the package version + shell: bash + run: | + set -euo pipefail + package_version="$(php -r 'require "src/Client.php"; echo (new ReflectionClass(SerpApi\Client::class))->getConstant("VERSION");')" + if [[ "${GITHUB_REF_NAME}" != "v${package_version}" ]]; then + echo "Release tag ${GITHUB_REF_NAME} must equal v${package_version}." >&2 + exit 1 + fi + + test: + name: Test with PHP ${{ matrix.php-version }} + needs: verify-tag + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"] + + steps: + - name: Check out the released revision + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl, curl + ini-values: post_max_size=256M, max_execution_time=180 + coverage: none + tools: composer + + - name: Validate composer.json + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Lint + if: matrix.php-version == '8.5' + run: composer run-script lint + + - name: Test + run: composer run-script test + env: + API_KEY: ${{ secrets.API_KEY }} + + publish: + name: Publish to Packagist + needs: [verify-tag, test] + runs-on: ubuntu-latest + environment: + name: packagist + url: https://packagist.org/packages/serpapi/serpapi-php + env: + PACKAGIST_USERNAME: ${{ secrets.PACKAGIST_USERNAME }} + PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }} + + steps: + - name: Trigger a Packagist crawl + shell: bash + run: | + set -euo pipefail + if [[ -z "${PACKAGIST_USERNAME}" || -z "${PACKAGIST_TOKEN}" ]]; then + echo "Add PACKAGIST_USERNAME and PACKAGIST_TOKEN as GitHub Actions secrets on the packagist environment." >&2 + exit 1 + fi + + curl -sS --fail-with-body -X POST \ + -H 'Content-Type: application/json' \ + -H 'User-Agent: serpapi-php-release (mailto:contact@serpapi.com)' \ + -d "{\"repository\":{\"url\":\"https://github.com/${GITHUB_REPOSITORY}\"}}" \ + "https://packagist.org/api/update-package?username=${PACKAGIST_USERNAME}&apiToken=${PACKAGIST_TOKEN}" From 3b83cd97bcbde4adafb09c7f86a352ca36c89610 Mon Sep 17 00:00:00 2001 From: Igor Galeta Date: Fri, 14 Aug 2026 16:17:39 +0300 Subject: [PATCH 2/4] ci: pin PHP 8.5 for release tag verification --- .github/workflows/release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0cb4e48..ad644f4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,6 +15,12 @@ jobs: - name: Check out the released revision uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + - name: Setup PHP for tag verification + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: "8.5" + coverage: none + - name: Verify release tag matches the package version shell: bash run: | From 9d229e5804f7495bd44b386e09f790e0c7e33cff Mon Sep 17 00:00:00 2001 From: Igor Galeta Date: Tue, 18 Aug 2026 10:53:45 +0300 Subject: [PATCH 3/4] ci: trigger release on tag push and create the GitHub Release --- .github/workflows/release.yml | 47 +++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad644f4..f62d20b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,18 @@ -name: Publish release to Packagist +name: Release on: - release: - types: [published] + push: + tags: ['v**'] + workflow_dispatch: + inputs: + allow_example_test_failures: + description: 'Publish even if the live example tests fail (use only when a SerpApi engine is down)' + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false permissions: contents: read @@ -12,7 +22,13 @@ jobs: name: Verify release tag runs-on: ubuntu-latest steps: - - name: Check out the released revision + - name: Ensure ref is a tag + if: github.ref_type != 'tag' + run: | + echo "Release must run against a tag, got '${{ github.ref }}'" >&2 + exit 1 + + - name: Check out the tagged revision uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - name: Setup PHP for tag verification @@ -41,7 +57,7 @@ jobs: php-version: ["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"] steps: - - name: Check out the released revision + - name: Check out the tagged revision uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 - name: Setup PHP ${{ matrix.php-version }} @@ -64,22 +80,39 @@ jobs: run: composer run-script lint - name: Test - run: composer run-script test + run: composer run-script test -- --filter '/^(?!.*ExampleSearch)/' + env: + API_KEY: ${{ secrets.API_KEY }} + + - name: Run example tests + if: matrix.php-version == '8.5' + continue-on-error: ${{ inputs.allow_example_test_failures == true }} + run: composer run-script test -- --filter ExampleSearch env: API_KEY: ${{ secrets.API_KEY }} publish: - name: Publish to Packagist + name: Publish release needs: [verify-tag, test] runs-on: ubuntu-latest environment: name: packagist url: https://packagist.org/packages/serpapi/serpapi-php + permissions: + contents: write env: PACKAGIST_USERNAME: ${{ secrets.PACKAGIST_USERNAME }} PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }} steps: + - name: Create GitHub Release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_REPO: ${{ github.repository }} + run: | + gh release create "${GITHUB_REF_NAME}" --generate-notes \ + || echo "GitHub Release ${GITHUB_REF_NAME} already exists" + - name: Trigger a Packagist crawl shell: bash run: | From 6a1f19018e62d6c6a08aab54497594560ce85b20 Mon Sep 17 00:00:00 2001 From: Igor Galeta Date: Tue, 18 Aug 2026 11:07:05 +0300 Subject: [PATCH 4/4] ci: align workflows on checkout@v6 and setup-php@v2 --- .github/workflows/release.yml | 8 ++++---- .github/workflows/serpapi-php.yml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f62d20b..b386ac8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,10 +29,10 @@ jobs: exit 1 - name: Check out the tagged revision - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@v6 - name: Setup PHP for tag verification - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + uses: shivammathur/setup-php@v2 with: php-version: "8.5" coverage: none @@ -58,10 +58,10 @@ jobs: steps: - name: Check out the tagged revision - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + uses: actions/checkout@v6 - name: Setup PHP ${{ matrix.php-version }} - uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-version }} extensions: mbstring, intl, curl diff --git a/.github/workflows/serpapi-php.yml b/.github/workflows/serpapi-php.yml index 17faf9a..a6a989e 100644 --- a/.github/workflows/serpapi-php.yml +++ b/.github/workflows/serpapi-php.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -32,7 +32,7 @@ jobs: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup PHP uses: shivammathur/setup-php@v2