|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: [completed] |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + release: |
| 15 | + name: Tag & GitHub Release |
| 16 | + runs-on: ubuntu-latest |
| 17 | + if: > |
| 18 | + github.event.workflow_run.conclusion == 'success' && |
| 19 | + github.event.workflow_run.head_branch == 'master' && |
| 20 | + github.event.workflow_run.event == 'push' |
| 21 | +
|
| 22 | + steps: |
| 23 | + - name: Checkout CI head commit |
| 24 | + uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 27 | + fetch-depth: 0 |
| 28 | + |
| 29 | + - name: Extract version from composer.json |
| 30 | + id: version |
| 31 | + run: | |
| 32 | + set -euo pipefail |
| 33 | + VERSION=$(jq -r '.version' composer.json) |
| 34 | + if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 35 | + echo "::error::composer.json version '$VERSION' is not a plain semver (X.Y.Z). Pre-release tags are not supported by this workflow." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 39 | + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" |
| 40 | + echo "Detected version: $VERSION" |
| 41 | +
|
| 42 | + - name: Verify DefaultAgent.php version matches composer.json |
| 43 | + env: |
| 44 | + VERSION: ${{ steps.version.outputs.version }} |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | + AGENT_FILE="src/Models/Request/DefaultAgent.php" |
| 48 | + AGENT_VERSION=$(grep -oE "php/[0-9]+\.[0-9]+\.[0-9]+" "$AGENT_FILE" | head -n1 | sed 's|php/||') |
| 49 | + if [ -z "$AGENT_VERSION" ]; then |
| 50 | + echo "::error file=$AGENT_FILE::Could not locate 'php/X.Y.Z' SDK version literal in $AGENT_FILE." |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + if [ "$VERSION" != "$AGENT_VERSION" ]; then |
| 54 | + echo "::error file=$AGENT_FILE::Version drift detected. composer.json='$VERSION' but $AGENT_FILE='$AGENT_VERSION'. Update both files to the same value." |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | + echo "Version drift check passed: $VERSION" |
| 58 | +
|
| 59 | + - name: Check whether tag already exists |
| 60 | + id: tag-check |
| 61 | + env: |
| 62 | + TAG: ${{ steps.version.outputs.tag }} |
| 63 | + run: | |
| 64 | + set -euo pipefail |
| 65 | + git fetch --tags --quiet |
| 66 | + if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then |
| 67 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 68 | + echo "Tag ${TAG} already exists — nothing to release. Skipping." |
| 69 | + else |
| 70 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 71 | + echo "Tag ${TAG} does not exist — proceeding with release." |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Configure git identity |
| 75 | + if: steps.tag-check.outputs.exists == 'false' |
| 76 | + run: | |
| 77 | + git config user.name "github-actions[bot]" |
| 78 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 79 | +
|
| 80 | + - name: Create and push tag |
| 81 | + if: steps.tag-check.outputs.exists == 'false' |
| 82 | + env: |
| 83 | + TAG: ${{ steps.version.outputs.tag }} |
| 84 | + run: | |
| 85 | + set -euo pipefail |
| 86 | + git tag -a "$TAG" -m "Release $TAG" |
| 87 | + git push origin "$TAG" |
| 88 | +
|
| 89 | + - name: Create GitHub Release |
| 90 | + if: steps.tag-check.outputs.exists == 'false' |
| 91 | + env: |
| 92 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 93 | + TAG: ${{ steps.version.outputs.tag }} |
| 94 | + run: | |
| 95 | + gh release create "$TAG" \ |
| 96 | + --title "$TAG" \ |
| 97 | + --generate-notes |
0 commit comments