|
| 1 | +name: publish |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: 'Version tag to publish (for example v1.1.0)' |
| 11 | + required: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +jobs: |
| 17 | + publish: |
| 18 | + name: package and publish to Packagist |
| 19 | + runs-on: ubuntu-latest |
| 20 | + environment: packagist |
| 21 | + env: |
| 22 | + PACKAGE_NAME: arcp/arcp |
| 23 | + REPOSITORY_URL: https://github.com/agentruntimecontrolprotocol/php-sdk |
| 24 | + PACKAGIST_USERNAME: ${{ secrets.PACKAGIST_USERNAME }} |
| 25 | + PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v6 |
| 29 | + with: |
| 30 | + ref: ${{ inputs.tag || github.ref }} |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Setup PHP |
| 34 | + uses: shivammathur/setup-php@7c071dfe9dc99bdf297fa79cb49ea005b9fcadbc # 2.37.1 |
| 35 | + with: |
| 36 | + php-version: '8.4' |
| 37 | + extensions: pdo, pdo_sqlite, mbstring, json |
| 38 | + tools: composer:v2 |
| 39 | + |
| 40 | + - name: Validate composer metadata |
| 41 | + run: composer validate --strict |
| 42 | + |
| 43 | + - name: Install production dependencies |
| 44 | + run: composer install --no-dev --no-progress --no-interaction --prefer-dist |
| 45 | + |
| 46 | + - name: Build Composer archive |
| 47 | + run: | |
| 48 | + set -euo pipefail |
| 49 | + mkdir -p build |
| 50 | + version="${GITHUB_REF_NAME}" |
| 51 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 52 | + version="${{ inputs.tag }}" |
| 53 | + fi |
| 54 | + composer archive --format=zip --file="build/${PACKAGE_NAME//\//-}-${version}" |
| 55 | +
|
| 56 | + - name: Upload package artifact |
| 57 | + uses: actions/upload-artifact@v7 |
| 58 | + with: |
| 59 | + name: composer-package |
| 60 | + path: build/*.zip |
| 61 | + if-no-files-found: error |
| 62 | + |
| 63 | + - name: Publish to Packagist |
| 64 | + run: | |
| 65 | + set -euo pipefail |
| 66 | +
|
| 67 | + if [ -z "${PACKAGIST_USERNAME}" ] || [ -z "${PACKAGIST_TOKEN}" ]; then |
| 68 | + echo "PACKAGIST_USERNAME and PACKAGIST_TOKEN repository secrets are required." >&2 |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | +
|
| 72 | + status="$(curl -sS -o /tmp/packagist-package.json -w '%{http_code}' \ |
| 73 | + "https://repo.packagist.org/p2/${PACKAGE_NAME}.json")" |
| 74 | +
|
| 75 | + if [ "${status}" = "200" ]; then |
| 76 | + endpoint="https://packagist.org/api/update-package" |
| 77 | + elif [ "${status}" = "404" ]; then |
| 78 | + endpoint="https://packagist.org/api/create-package" |
| 79 | + else |
| 80 | + echo "Unexpected Packagist metadata status ${status}" >&2 |
| 81 | + cat /tmp/packagist-package.json >&2 || true |
| 82 | + exit 1 |
| 83 | + fi |
| 84 | +
|
| 85 | + curl --fail-with-body -sS \ |
| 86 | + -X POST \ |
| 87 | + -H 'Content-Type: application/json' \ |
| 88 | + -H "Authorization: Bearer ${PACKAGIST_USERNAME}:${PACKAGIST_TOKEN}" \ |
| 89 | + "${endpoint}" \ |
| 90 | + -d "{\"repository\":\"${REPOSITORY_URL}\"}" |
0 commit comments