-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (94 loc) · 3.28 KB
/
Copy pathphp.yml
File metadata and controls
100 lines (94 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: php
# why: composer.json lives at the repo root for Packagist; the PHP source
# stays in packages/php/. Tests/lint run from root via composer scripts.
# PHP version source is packages/php/VERSION; Packagist indexes new tags
# via the GitHub webhook, so the release job just creates the tag.
on:
push:
branches: [main]
paths:
- 'composer.json'
- 'packages/php/**'
- 'spec/**'
- '.github/workflows/php.yml'
pull_request:
branches: [main]
paths:
- 'composer.json'
- 'packages/php/**'
- 'spec/**'
- '.github/workflows/php.yml'
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
permissions:
contents: read
jobs:
test:
runs-on: blacksmith-2vcpu-ubuntu-2204
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.4']
steps:
- uses: actions/checkout@v4
- name: setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, json
coverage: none
tools: composer:v2
- name: composer install
run: composer install --no-interaction --no-progress --prefer-dist
- name: php-cs-fixer (dry-run)
run: composer cs-check
- name: phpstan
run: composer phpstan -- --no-progress
- name: phpunit
run: composer test -- --colors=never
release:
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: blacksmith-2vcpu-ubuntu-2204
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: gate on version
id: gate
run: |
set -euo pipefail
version="$(tr -d '[:space:]' < packages/php/VERSION)"
tag="php-v$version"
release=true
if git ls-remote --exit-code --tags origin "refs/tags/$tag" >/dev/null 2>&1; then
echo "tag $tag already exists; skipping release."
release=false
elif grep -qE "^## ${version} - unreleased" packages/php/CHANGELOG.md; then
echo "CHANGELOG marks ${version} as unreleased; skipping publish."
release=false
fi
echo "release=$release" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "tag=$tag" >> "$GITHUB_OUTPUT"
- if: steps.gate.outputs.release == 'true'
name: tag and GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# why: Packagist publishes via the GitHub webhook on tag push — no
# token in this workflow. One-time setup: register the package at
# packagist.org and add the GitHub webhook.
# Composer only parses semver-ish tags (vX.Y.Z), so we also push a
# plain `vX.Y.Z` next to the cross-language `php-vX.Y.Z` so
# Packagist indexes the release. The two tags point at the same
# commit; the GitHub Release is anchored to the language-prefixed
# one.
tag="${{ steps.gate.outputs.tag }}"
composer_tag="v${{ steps.gate.outputs.version }}"
git tag "$tag"
git tag "$composer_tag"
git push origin "$tag" "$composer_tag"
gh release create "$tag" \
--title "$tag" \
--generate-notes