Skip to content

Commit

Permalink
Merge pull request #7 from keboola/adamvyborny-upgrade-php
Browse files Browse the repository at this point in the history
Upgrade PHP and migrate to GH actions
  • Loading branch information
AdamVyborny authored Apr 26, 2022
2 parents c5163f1 + 2b30f33 commit d98458f
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 116 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: 'GitHub Actions'
'on':
- push
concurrency: 'ci-${{ github.ref }}'
env:
APP_IMAGE: keboola-php-csvtable
DOCKERHUB_USER: '${{ secrets.DOCKERHUB_USER }}'
DOCKERHUB_TOKEN: '${{ secrets.DOCKERHUB_TOKEN }}'
jobs:
tests:
runs-on: ubuntu-latest
steps:
-
name: 'Check out the repo'
uses: actions/checkout@v2
-
name: 'Docker login'
if: env.DOCKERHUB_TOKEN
run: 'docker login --username "$DOCKERHUB_USER" --password "$DOCKERHUB_TOKEN"'
-
name: 'Build image'
run: 'docker build -t $APP_IMAGE .'
-
name: 'Run tests'
run: 'docker run ${{env.APP_IMAGE}} composer ci'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vendor
.DS_Store
.kdev4
*.kdev4
.phpunit.result.cache
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM php:8

ARG DEBIAN_FRONTEND=noninteractive
ARG COMPOSER_FLAGS="--prefer-dist --no-interaction"

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_PROCESS_TIMEOUT 3600

WORKDIR /code/

COPY composer-install.sh /tmp/composer-install.sh

RUN apt-get update -q \
&& apt-get install unzip git wget -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/* \
&& /tmp/composer-install.sh \
&& rm /tmp/composer-install.sh \
&& mv composer.phar /usr/local/bin/composer

## Composer - deps always cached unless changed
# First copy only composer files
COPY composer.* /code/
# Download dependencies, but don't run scripts or init autoloaders as the app is missing
RUN composer install $COMPOSER_FLAGS --no-scripts --no-autoloader
# copy rest of the app
COPY . /code/
# run normal composer - all deps are cached already
RUN composer install $COMPOSER_FLAGS

CMD bash
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ Result:
id,column,names
"1","row","data"
```

## Development

Clone this repository and init the workspace with following command:

```
git clone https://github.com/keboola/php-csvtable.git
cd php-csvtable
docker-compose build
docker-compose run --rm dev composer install --no-scripts
```

Run the test suite using this command:

```
docker-compose run --rm dev composer tests
```
17 changes: 17 additions & 0 deletions composer-install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('SHA384', 'composer-setup.php');")"

if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php
exit 1
fi

php composer-setup.php --quiet
RESULT=$?
rm composer-setup.php
exit $RESULT
32 changes: 28 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,41 @@
}
],
"require": {
"php": "^7.1",
"php": "^8.1",
"keboola/php-temp": "^2.0",
"keboola/csv": "^2.2"
},
"require-dev": {
"phpunit/phpunit": ">=7.5",
"codeclimate/php-test-reporter": "dev-master"
"keboola/coding-standard": "^13.0",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": ">=7.5"
},
"scripts": {
"phpstan": "phpstan analyse ./src ./tests --level=max --no-progress -c phpstan.neon",
"phpcs": "phpcs -n --ignore=vendor --extensions=php .",
"phpcbf": "phpcbf -n --ignore=vendor --extensions=php .",
"phplint": "parallel-lint -j 10 --exclude vendor .",
"tests": "phpunit",
"build": [
"@phplint",
"@phpcs",
"@phpstan",
"@tests"
],
"ci": [
"@composer validate --strict",
"@build"
]
},
"autoload": {
"psr-0": {
"Keboola\\CsvTable": "src/"
}
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"

services:

dev:
build: .
tty: true
volumes:
- ./:/code
working_dir: /code
15 changes: 15 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<ruleset name="Project">
<rule ref="vendor/keboola/coding-standard/src/ruleset.xml"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
</ruleset>
52 changes: 52 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
parameters:
ignoreErrors:
-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:__construct\\(\\) has parameter \\$header with no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:addAttributes\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:getAttributes\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:getHeader\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:getPrimaryKey\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:getPrimaryKey\\(\\) should return array\\|string but returns array\\<string\\>\\|string\\|null\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:setAttributes\\(\\) has parameter \\$attributes with no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Method Keboola\\\\CsvTable\\\\Table\\:\\:setPrimaryKey\\(\\) has parameter \\$primaryKey with no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Property Keboola\\\\CsvTable\\\\Table\\:\\:\\$attributes type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

-
message: "#^Property Keboola\\\\CsvTable\\\\Table\\:\\:\\$header type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Keboola/CsvTable/Table.php

2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
includes:
- phpstan-baseline.neon
Loading

0 comments on commit d98458f

Please sign in to comment.