Skip to content

Commit 2afdc9d

Browse files
nficanoclaude
andcommitted
ci: add GitHub Actions test workflow
Runs unit tests on push to main and PRs, with caching, concurrency control, minimal permissions, and pinned action versions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 322c9de commit 2afdc9d

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# CI for php-sdk.
2+
#
3+
# Action pinning policy:
4+
# - First-party actions (actions/*) are pinned to a major tag (e.g. @v4).
5+
# - Third-party actions are pinned to a full commit SHA, with the released
6+
# version recorded in a trailing comment for human review.
7+
name: test
8+
9+
on:
10+
push:
11+
branches: [main]
12+
paths-ignore:
13+
- '**.md'
14+
- 'docs/**'
15+
- 'LICENSE'
16+
- '.gitignore'
17+
- '.editorconfig'
18+
pull_request:
19+
branches: [main]
20+
paths-ignore:
21+
- '**.md'
22+
- 'docs/**'
23+
- 'LICENSE'
24+
- '.gitignore'
25+
- '.editorconfig'
26+
workflow_dispatch:
27+
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.ref }}
30+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
31+
32+
permissions:
33+
contents: read
34+
35+
jobs:
36+
test:
37+
name: PHP ${{ matrix.php }}
38+
runs-on: ubuntu-latest
39+
strategy:
40+
fail-fast: false
41+
matrix:
42+
php: ['8.4']
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
with:
47+
fetch-depth: 1
48+
49+
- name: Setup PHP ${{ matrix.php }}
50+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
51+
with:
52+
php-version: ${{ matrix.php }}
53+
extensions: pdo, pdo_sqlite, mbstring, json
54+
coverage: none
55+
tools: composer:v2
56+
57+
- name: Get composer cache directory
58+
id: composer-cache
59+
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
60+
61+
- name: Cache composer dependencies
62+
uses: actions/cache@v4
63+
with:
64+
path: ${{ steps.composer-cache.outputs.dir }}
65+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock', '**/composer.json') }}
66+
restore-keys: |
67+
${{ runner.os }}-php-${{ matrix.php }}-composer-
68+
69+
- name: Install dependencies
70+
run: composer install --no-progress --no-interaction --prefer-dist
71+
72+
- name: Lint (php-cs-fixer dry-run)
73+
if: hashFiles('.php-cs-fixer.dist.php', '.php-cs-fixer.php') != ''
74+
run: vendor/bin/php-cs-fixer fix --dry-run --diff
75+
76+
- name: Run PHPUnit
77+
run: vendor/bin/phpunit
78+
79+
- name: Upload test artifacts on failure
80+
if: failure()
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: test-artifacts-php-${{ matrix.php }}
84+
path: |
85+
.phpunit.cache/
86+
build/
87+
coverage.xml
88+
if-no-files-found: ignore
89+
retention-days: 7

0 commit comments

Comments
 (0)