Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

415: Update docker setup and php version #13

Merged
merged 11 commits into from
Jan 17, 2025
53 changes: 32 additions & 21 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,53 @@
on: pull_request
name: PR Review
jobs:
test-composer-files:
name: Validate composer
test-composer-install:
name: Validate composer (${{ matrix.php }}) / (${{ matrix.dependency-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: [ '7.4', '8.0' ]
php: [ '8.1', '8.2', '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: json
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2
# https://github.com/shivammathur/setup-php#cache-composer-dependencies
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Validate composer files
run: |
composer validate composer.json --strict
- name: Ensure dependencies resolve
run: composer validate composer.json --strict

- name: Install dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction

php-check-coding-standards:
name: PHP - Check Coding Standards
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: ${{ matrix.php }}
extensions: json
coverage: none
tools: composer:v2
Expand All @@ -61,16 +66,22 @@ jobs:
composer install --no-interaction --no-progress
- name: PHPCS
run: |
composer check-coding-standards
composer coding-standards-check

unit_tests:
name: Unit tests
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
dependency-version: [ prefer-lowest, prefer-stable ]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: ${{ matrix.php }}
extensions: json
coverage: none
tools: composer:v2
Expand All @@ -95,7 +106,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -110,7 +121,7 @@ jobs:
- name: Yarn install
uses: actions/setup-node@v2
with:
node-version: '12'
node-version: '20'
- run: yarn install
- name: markdownlint
run: yarn markdownlint README.md
run: yarn markdownlint README.md
12 changes: 12 additions & 0 deletions .markdownlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// @see https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
// MD013/line-length - Line length
"MD013": {
// Exclude code blocks
"code_blocks": false
}
}

// Local Variables:
// mode: json
// End:
1 change: 0 additions & 1 deletion .php-version

This file was deleted.

60 changes: 32 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Composer package for the Azure AD Delta Sync flow.
If you are looking to use this in a Symfony or Drupal project you should use
either:

* Symfony: [itk-dev/adgangsstyring-bundle](https://github.com/itk-dev/adgangsstyring-bundle)
* Drupal: [itk-dev/adgangsstyring_drupal](https://github.com/itk-dev/adgangsstyring_drupal)
* Symfony: [itk-dev/azure-ad-delta-sync-symfony](https://github.com/itk-dev/azure-ad-delta-sync-symfony)
* Drupal: [itk-dev/azure-ad-delta-sync-drupal](https://github.com/itk-dev/azure-ad-delta-sync-drupal)

### Direct installation

Expand Down Expand Up @@ -99,10 +99,11 @@ that every single user should be deleted.

## Development Setup

A `docker-compose.yml` file with a PHP 7.4 image is included in this project.
A `docker-compose.yml` file with a PHP 8.2 image is included in this project.
To install the dependencies you can run

```shell
docker compose pull
docker compose up -d
docker compose exec phpfpm composer install
```
Expand All @@ -119,20 +120,38 @@ docker compose exec phpfpm ./vendor/bin/phpunit tests
The test suite uses [Mocks](https://phpunit.de/manual/6.5/en/test-doubles.html)
for generation of test doubles.

### Check Coding Standard
### Coding Standard

* PHP files (PHP_CodeSniffer)
#### PHP files (PHP_CodeSniffer)

```shell
docker compose exec phpfpm composer check-coding-standards
```
Check PHP coding standards

* Markdown files (markdownlint standard rules)
```shell
docker compose run --rm phpfpm composer install
docker compose run --rm phpfpm composer coding-standards-check
```

Apply coding standard changes

```shell
docker compose run --rm phpfpm composer coding-standards-apply
```

#### Markdown files

Check markdown coding standards

```shell
docker run -v ${PWD}:/app itkdev/yarn:latest install
docker run -v ${PWD}:/app itkdev/yarn:latest check-coding-standards
```
```shell
docker compose run --rm node yarn install
docker compose run --rm node yarn coding-standards-check
```

Apply markdown coding standards

```shell
docker compose run --rm node yarn install
docker compose run --rm node yarn coding-standards-apply
```

### GitHub Actions

Expand All @@ -152,21 +171,6 @@ individual workflow jobs that can be run, e.g.
act -P ubuntu-latest=shivammathur/node:focal pull_request --job phpcsfixer
```

### Apply Coding Standards

* PHP files (PHP_CodeSniffer)

```shell
docker compose exec phpfpm composer apply-coding-standards
```

* Markdown files (markdownlint standard rules)

```shell
docker run -v ${PWD}:/app itkdev/yarn:latest install
docker run -v ${PWD}:/app itkdev/yarn:latest apply-coding-standards
```

## Versioning

We use [SemVer](http://semver.org/) for versioning.
Expand Down
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}
},
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-json": "*",
"symfony/options-resolver": "^4.4 || ^5.0",
"symfony/options-resolver": "^5.4 || ^6.0",
"psr/http-client": "^1.0",
"nyholm/psr7": "^1.4"
},
Expand All @@ -36,10 +36,10 @@
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1"
},
"scripts": {
"check-coding-standards": [
"coding-standards-check": [
"vendor/bin/phpcs --standard=phpcs.xml.dist"
],
"apply-coding-standards": [
"coding-standards-apply": [
"vendor/bin/phpcbf --standard=phpcs.xml.dist"
],
"install-codestandards": [
Expand All @@ -48,5 +48,10 @@
"post-install-cmd": [
"@install-codestandards"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
10 changes: 8 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ version: "3"

services:
phpfpm:
image: itkdev/php7.4-fpm:latest
image: itkdev/php8.2-fpm:latest
sinejespersen marked this conversation as resolved.
Show resolved Hide resolved
environment:
- XDEBUG_MODE=${XDEBUG_MODE:-off}
- XDEBUG_SESSION=${XDEBUG_SESSION:-0}
- COMPOSER_VERSION=2
- DOCKER_HOST_DOMAIN=${COMPOSE_DOMAIN}
- PHP_IDE_CONFIG=serverName=localhost
volumes:
- .:/app:delegated
- .:/app:delegated

node:
image: node:20
volumes:
- .:/app:delegated
working_dir: /app
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"markdownlint-cli": "^0.27.1"
},
"scripts": {
"check-coding-standards/markdownlint": "markdownlint README.md CHANGELOG.md",
"check-coding-standards": "yarn check-coding-standards/markdownlint",
"apply-coding-standards/markdownlint": "markdownlint --fix README.md CHANGELOG.md",
"apply-coding-standards": "yarn apply-coding-standards/markdownlint"
"coding-standards-check/markdownlint": "markdownlint README.md CHANGELOG.md",
"coding-standards-check": "yarn coding-standards-check/markdownlint",
"coding-standards-apply/markdownlint": "markdownlint --fix README.md CHANGELOG.md",
"coding-standards-apply": "yarn coding-standards-apply/markdownlint"
jekuaitk marked this conversation as resolved.
Show resolved Hide resolved
}
}
11 changes: 3 additions & 8 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ class Controller
*/
private ClientInterface $client;

/**
* @var array
*/
private array $options;

public function __construct(ClientInterface $client, array $options)
public function __construct(ClientInterface $client, private array $options)
{
$this->client = $client;

Expand All @@ -54,7 +49,7 @@ public function __construct(ClientInterface $client, array $options)
*
* @throws TokenException|DataException|NetworkException
*/
public function run(HandlerInterface $handler)
public function run(HandlerInterface $handler): void
{
// Acquiring access token and token type
$url = self::MICROSOFT_LOGIN_DOMAIN . $this->options['tenant_id'] . self::MICROSOFT_TOKEN_SUBDIRECTORY;
Expand Down Expand Up @@ -149,7 +144,7 @@ private function getData(string $url, string $tokenType, string $accessToken): a
*
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setRequired(['tenant_id', 'client_id', 'client_secret', 'group_id']);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Handler/HandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Interface HandlerInterface
*
* Interface allowing users to implement how to handle
* create a user deletion list, how to remove users from and
* creation of a user deletion list, how to remove users from the list and
* how to handle the list upon finishing the Azure AD Delta Sync flow.
*
* @package ItkDev\AzureAdDeltaSync\Handler
Expand Down
2 changes: 1 addition & 1 deletion tests/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function testRun()
/**
* Testing the Controller run() function
*
* Ensure the function does not call removeUsersFromDeletionList twice when theres no users on second list
* Ensure the function does not call removeUsersFromDeletionList twice when there are no users on second list
*/
public function testRunNoUsersOnSecondList()
{
Expand Down
Loading