Skip to content

Commit 8d8dd15

Browse files
authored
chore: add devcontainer contributor workflow [DX-822] (#340)
* chore: add devcontainer contributor workflow * fix: restore PHP matrix devcontainer checks * fix: align PHP syntax checks with repo validation * fix: replace deprecated workflow runtimes * docs: explain devcontainer bootstrap script * docs: clarify devcontainer workflows
1 parent 6ab941f commit 8d8dd15

10 files changed

Lines changed: 208 additions & 134 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.devcontainer/Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
ARG PHP_VERSION=8.1
2+
FROM php:${PHP_VERSION}-cli
3+
4+
RUN groupadd --gid 1000 vscode \
5+
&& useradd --uid 1000 --gid 1000 --create-home --shell /bin/bash vscode \
6+
&& apt-get update \
7+
&& export DEBIAN_FRONTEND=noninteractive \
8+
&& apt-get install -y --no-install-recommends \
9+
curl \
10+
git \
11+
libicu-dev \
12+
libonig-dev \
13+
libxml2-dev \
14+
libzip-dev \
15+
unzip \
16+
zip \
17+
&& docker-php-ext-install -j"$(nproc)" bcmath dom intl mbstring soap xml zip \
18+
&& curl -fsSL https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
19+
&& git config --system --add safe.directory '*' \
20+
&& rm -rf /var/lib/apt/lists/*

.devcontainer/devcontainer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "contentful.php",
3+
"build": {
4+
"dockerfile": "Dockerfile",
5+
"context": "..",
6+
"args": {
7+
"PHP_VERSION": "${localEnv:PHP_VERSION:8.1}"
8+
}
9+
},
10+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
11+
"remoteUser": "vscode",
12+
"postCreateCommand": ".devcontainer/post-create.sh",
13+
"customizations": {
14+
"vscode": {
15+
"extensions": [
16+
"bmewburn.vscode-intelephense-client",
17+
"xdebug.php-debug"
18+
]
19+
}
20+
}
21+
}

.devcontainer/post-create.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
temp_composer="composer.devcontainer.json"
5+
temp_lock="composer.devcontainer.lock"
6+
7+
cleanup() {
8+
rm -f "$temp_composer" "$temp_lock"
9+
}
10+
11+
trap cleanup EXIT
12+
13+
# Install a devcontainer-only dependency set without the BC checker. This repo
14+
# does not commit a lockfile, and roave/backward-compatibility-check can force
15+
# incompatible resolutions during post-create; the dedicated BC CI job still
16+
# exercises that tooling separately.
17+
php <<'PHP'
18+
<?php
19+
20+
$composer = json_decode(file_get_contents('composer.json'), true, 512, JSON_THROW_ON_ERROR);
21+
unset($composer['require-dev']['roave/backward-compatibility-check']);
22+
23+
file_put_contents(
24+
'composer.devcontainer.json',
25+
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).PHP_EOL
26+
);
27+
PHP
28+
29+
COMPOSER="$temp_composer" composer install -n --prefer-dist

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
lint-syntax:
14+
name: Lint syntax (PHP 8.1)
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v5
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Install devcontainer CLI
22+
run: npm install -g @devcontainers/cli@0
23+
24+
- name: Run syntax checks in dev container
25+
env:
26+
PHP_VERSION: "8.1"
27+
run: |
28+
devcontainer up --workspace-folder .
29+
devcontainer exec --workspace-folder . bash -lc "git ls-files -z '*.php' | xargs -0 -n1 php -l"
30+
31+
static-analysis:
32+
name: Static analysis (PHP 8.1)
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v5
36+
with:
37+
fetch-depth: 0
38+
39+
- name: Install devcontainer CLI
40+
run: npm install -g @devcontainers/cli@0
41+
42+
- name: Run static analysis in dev container
43+
env:
44+
PHP_VERSION: "8.1"
45+
run: |
46+
devcontainer up --workspace-folder .
47+
devcontainer exec --workspace-folder . bash -lc "composer run lint-static-analysis"
48+
49+
backwards-compatibility:
50+
name: Backwards compatibility (PHP 8.1)
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v5
54+
with:
55+
fetch-depth: 0
56+
57+
- name: Install devcontainer CLI
58+
run: npm install -g @devcontainers/cli@0
59+
60+
- name: Check backwards compatibility in dev container
61+
env:
62+
PHP_VERSION: "8.1"
63+
run: |
64+
devcontainer up --workspace-folder .
65+
devcontainer exec --workspace-folder . bash -lc "composer install -n --prefer-dist && composer run test-for-bc-breaks || true"
66+
67+
test:
68+
name: Test (PHP ${{ matrix.php-version }})
69+
runs-on: ubuntu-latest
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
php-version: ["8.0", "8.1", "8.2", "8.3", "8.4"]
74+
steps:
75+
- uses: actions/checkout@v5
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Install devcontainer CLI
80+
run: npm install -g @devcontainers/cli@0
81+
82+
- name: Run test suite in dev container
83+
env:
84+
PHP_VERSION: ${{ matrix.php-version }}
85+
run: |
86+
devcontainer up --workspace-folder .
87+
devcontainer exec --workspace-folder . bash -lc "composer test-quick-fail"

.github/workflows/codeql.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

CONTRIBUTING.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Contributing
2+
3+
Thanks for helping improve `contentful.php`.
4+
5+
## Development with Dev Containers
6+
7+
This repository includes a `.devcontainer` configuration for a reproducible local setup. GitHub Actions uses the same devcontainer configuration for CI.
8+
9+
### Visual Studio Code
10+
11+
Open the repository in Visual Studio Code, install the Dev Containers extension if needed, then run `Dev Containers: Reopen in Container`. Wait for the container build and post-create setup to finish.
12+
13+
### Terminal or other editors
14+
15+
Install Docker and the Dev Container CLI (`npm install -g @devcontainers/cli`). From the repository root, run:
16+
17+
```bash
18+
devcontainer up --workspace-folder .
19+
devcontainer exec --workspace-folder . bash
20+
```
21+
22+
### Verify the environment
23+
24+
```bash
25+
composer test-quick-fail
26+
```
27+
28+
## Other Useful Commands
29+
30+
```bash
31+
composer run lint-static-analysis
32+
composer run test-for-bc-breaks
33+
```
34+
35+
## Pull Requests
36+
37+
1. Fork the repository and create a branch for your change.
38+
2. Run the relevant checks from the dev container.
39+
3. Open a pull request with a short summary of the change and any follow-up context.

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[![Packagist](https://img.shields.io/packagist/v/contentful/contentful.svg?style=for-the-badge)](https://packagist.org/packages/contentful/contentful)
1818
[![PHP version](https://img.shields.io/packagist/php-v/contentful/contentful.svg?style=for-the-badge)](https://packagist.org/packages/contentful/contentful)
1919
[![Packagist](https://img.shields.io/github/license/contentful/contentful.php.svg?style=for-the-badge)](https://packagist.org/packages/contentful/contentful)
20-
[![CircleCI](https://circleci.com/gh/contentful/contentful.php.svg?style=shield)](https://circleci.com/gh/contentful/contentful.php)
20+
[![CI](https://github.com/contentful/contentful.php/actions/workflows/ci.yml/badge.svg)](https://github.com/contentful/contentful.php/actions/workflows/ci.yml)
2121

2222

2323
> PHP library for the Contentful [Content Delivery API](https://www.contentful.com/developers/docs/references/content-delivery-api/) and [Content Preview API](https://www.contentful.com/developers/docs/references/content-preview-api/). It helps you to easily access your Content stored in Contentful with your PHP applications.
@@ -200,7 +200,15 @@ For details about how to upgrade from version 2.x to version 3, please check the
200200

201201
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?maxAge=31557600)](http://makeapullrequest.com)
202202

203-
**Important**: Right now, the API has `php-vcr` as a development dependency, which does not officially support PHP8 yet. If you want to develop on PHP8, you will need to install the dependencies with `composer install --ignore-platform-reqs` to overwrite this requirement.
203+
For a reproducible local setup, open this repository in its included dev container. The container installs the project dependencies automatically when it is created.
204+
205+
After the container is ready, run:
206+
207+
```bash
208+
composer test-quick-fail
209+
```
210+
211+
See [CONTRIBUTING.md](CONTRIBUTING.md) for the full contributor workflow.
204212

205213
## License
206214

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"test": "vendor/bin/phpunit",
4141
"test-quick-fail": "php vendor/bin/phpunit --stop-on-error --stop-on-failure -v",
4242
"test-for-bc-breaks": "php -d memory_limit=-1 vendor/bin/roave-backward-compatibility-check",
43-
"lint-static-analysis": "php vendor/bin/phpstan analyse src --level=5",
43+
"lint-static-analysis": "php -d memory_limit=-1 vendor/bin/phpstan analyse src --level=5",
4444
"release": "php vendor/contentful/core/scripts/release.php"
4545
},
4646
"config": {

src/Resource/DeletedAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of the contentful/contentful package.
55
*
6-
* @copyright 2015-2025 Contentful GmbH
6+
* @copyright 2015-2026 Contentful GmbH
77
* @license MIT
88
*/
99

0 commit comments

Comments
 (0)