├── .github ├── FUNDING.yml └── workflows │ ├── build-docker.yaml │ └── update_version.yml ├── Dockerfile ├── README.md ├── action.yml ├── entrypoint.sh └── examples └── .github └── workflows └── test.yml /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [OskarStark] 4 | -------------------------------------------------------------------------------- /.github/workflows/build-docker.yaml: -------------------------------------------------------------------------------- 1 | name: "Build and push docker image" 2 | 3 | on: 4 | push: 5 | branches: 6 | - 'master' 7 | paths: 8 | - ".github/workflows/build-docker.yaml" 9 | - "**" 10 | 11 | env: 12 | IMAGE: "oskarstark/phpstan-ga" 13 | PLATFORMS: linux/arm/v7,linux/arm64/v8,linux/amd64 14 | 15 | jobs: 16 | build: 17 | name: 'Build and Push' 18 | runs-on: "ubuntu-latest" 19 | steps: 20 | - name: 'Checkout' 21 | uses: 'actions/checkout@v3' 22 | with: 23 | ref: '${{ github.head_ref }}' 24 | 25 | - name: 'Exposing Release Version' 26 | run: | 27 | echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV 28 | 29 | - name: Login to Dockerhub 30 | uses: docker/login-action@v2 31 | with: 32 | username: ${{ secrets.DOCKERHUB_USERNAME }} 33 | password: ${{ secrets.DOCKERHUB_TOKEN }} 34 | 35 | - name: Set up Docker Buildx 36 | id: buildx 37 | uses: docker/setup-buildx-action@v2.9.1 38 | 39 | - name: Build and push images 40 | uses: docker/build-push-action@v4 41 | with: 42 | push: true 43 | builder: ${{ steps.buildx.outputs.name }} 44 | tags: | 45 | ${{env.IMAGE}}:latest 46 | file: Dockerfile 47 | context: . 48 | cache-from: type=gha 49 | cache-to: type=gha,mode=max 50 | platforms: ${{ env.PLATFORMS }} 51 | -------------------------------------------------------------------------------- /.github/workflows/update_version.yml: -------------------------------------------------------------------------------- 1 | name: Update version 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '30 */4 * * *' 7 | 8 | jobs: 9 | update-version: 10 | name: Automatically get latest PHPStan version and commit 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - name: "Checkout code" 16 | uses: actions/checkout@v3 17 | with: 18 | ref: master 19 | fetch-depth: '0' 20 | 21 | - name: "Update Dockerfile and action.yml" 22 | id: fetch_version 23 | run: | 24 | latest=$(curl -s https://packagist.org/packages/phpstan/phpstan.json|jq '[.package.versions[]|select(.version|test("^\\d+\\.\\d+\\.\\d+$"))|.version]|max_by(.|[splits("[.]")]|map(tonumber))') 25 | latest=$(echo $latest | tr -d '"') 26 | echo "Latest PHPStan version is $latest" 27 | echo ::set-output name=latest::$latest 28 | sed -i -re "s/ENV VERSION=.*/ENV VERSION=$latest/" Dockerfile 29 | cat Dockerfile 30 | sed -i -re "s/phpstan-ga:([0-9.]+)?/phpstan-ga:$latest/" action.yml 31 | cat action.yml 32 | 33 | - name: "Commit changes" 34 | uses: stefanzweifel/git-auto-commit-action@v5 35 | id: commit 36 | with: 37 | commit_author: "Oskar Stark " 38 | commit_message: "Enhancement: Upgrade to PHPStan ${{ steps.fetch_version.outputs.latest }}" 39 | commit_user_email: "oskarstark@googlemail.com" 40 | commit_user_name: "Oskar Stark" 41 | 42 | - name: "Tag version ${{ steps.fetch_version.outputs.latest }}" 43 | uses: "anothrNick/github-tag-action@1.30.0" 44 | if: steps.commit.outputs.changes_detected == 'true' 45 | id: tag 46 | env: 47 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 48 | CUSTOM_TAG: ${{ steps.fetch_version.outputs.latest }} 49 | RELEASE_BRANCHES: master 50 | 51 | - name: "Create release ${{ steps.fetch_version.outputs.latest }}" 52 | uses: actions/create-release@v1 53 | if: steps.commit.outputs.changes_detected == 'true' 54 | env: 55 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 56 | with: 57 | tag_name: ${{ steps.tag.outputs.new_tag }} 58 | release_name: ${{ steps.tag.outputs.new_tag }} 59 | commitish: master 60 | body: "Upgrade PHPStan to ${{ steps.tag.outputs.new_tag }}" 61 | 62 | publish_docker_images: 63 | needs: [update-version] 64 | runs-on: ubuntu-20.04 65 | 66 | if: github.ref == 'refs/heads/master' || github.event_name == 'release' 67 | steps: 68 | - name: Checkout 69 | uses: actions/checkout@v3 70 | - name: Docker meta 71 | id: meta 72 | uses: crazy-max/ghaction-docker-meta@v2 73 | with: 74 | images: oskarstark/phpstan-ga 75 | tags: | 76 | type=raw,value=latest,enable=${{ endsWith(github.ref, 'master') }} 77 | type=ref,event=tag 78 | flavor: | 79 | latest=false 80 | - name: Login to DockerHub 81 | if: github.event_name != 'pull_request' 82 | uses: docker/login-action@v1 83 | with: 84 | username: ${{ secrets.DOCKERHUB_USERNAME }} 85 | password: ${{ secrets.DOCKERHUB_TOKEN }} 86 | - name: Build and push 87 | uses: docker/build-push-action@v2 88 | with: 89 | context: . 90 | push: ${{ github.event_name != 'pull_request' }} 91 | tags: ${{ steps.meta.outputs.tags }} 92 | labels: ${{ steps.meta.outputs.labels }} 93 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.3-alpine 2 | 3 | LABEL "com.github.actions.name"="OSKAR-phpstan" 4 | LABEL "com.github.actions.description"="phpstan" 5 | LABEL "com.github.actions.icon"="check" 6 | LABEL "com.github.actions.color"="blue" 7 | 8 | LABEL "repository"="http://github.com/oskarstark/phpstan-ga" 9 | LABEL "homepage"="http://github.com/actions" 10 | LABEL "maintainer"="Oskar Stark " 11 | 12 | COPY --from=composer:2.6.5 /usr/bin/composer /usr/local/bin/composer 13 | 14 | RUN mkdir /composer 15 | ENV COMPOSER_HOME=/composer 16 | 17 | RUN echo "memory_limit=-1" > $PHP_INI_DIR/conf.d/memory-limit.ini 18 | 19 | ENV VERSION=2.1.17 20 | 21 | RUN composer global require phpstan/phpstan $VERSION \ 22 | && composer global config --no-plugins allow-plugins.phpstan/extension-installer true \ 23 | && composer global require phpstan/extension-installer \ 24 | && composer global require phpstan/phpstan-doctrine \ 25 | && composer global require phpstan/phpstan-phpunit \ 26 | && composer global require phpstan/phpstan-nette \ 27 | && composer global require phpstan/phpstan-symfony \ 28 | && composer global require phpstan/phpstan-mockery \ 29 | && composer global require phpstan/phpstan-webmozart-assert \ 30 | && composer global show "*phpstan*" 31 | 32 | ADD entrypoint.sh /entrypoint.sh 33 | ENTRYPOINT ["/entrypoint.sh"] 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GithubAction for PHPStan 2 | 3 | ## Usage 4 | 5 | You can use it as a Github Action like this: 6 | 7 | ```yaml 8 | # .github/workflows/test.yml 9 | 10 | on: 11 | push: 12 | branches: 13 | - master 14 | pull_request: 15 | 16 | name: Test 17 | 18 | jobs: 19 | phpstan: 20 | name: PHPStan 21 | 22 | runs-on: ubuntu-latest 23 | 24 | steps: 25 | - name: "Checkout" 26 | uses: actions/checkout@v3 27 | 28 | - name: PHPStan 29 | uses: docker://oskarstark/phpstan-ga 30 | with: 31 | args: analyse src/ 32 | ``` 33 | 34 | _to use a specific level:_ 35 | ```diff 36 | uses: docker://oskarstark/phpstan-ga 37 | with: 38 | - args: analyse src/ 39 | + args: analyse src/ --level=5 40 | ``` 41 | 42 | _to install dev dependencies:_ 43 | ```diff 44 | uses: docker://oskarstark/phpstan-ga 45 | + env: 46 | + REQUIRE_DEV: true 47 | with: 48 | args: analyse src/ 49 | ``` 50 | 51 | _to allow dev dependencies:_ 52 | ```diff 53 | uses: docker://oskarstark/phpstan-ga 54 | + env: 55 | + ALLOW_DEV: true 56 | with: 57 | args: analyse src/ 58 | ``` 59 | 60 | _to skip checking the platform requirements:_ 61 | ```diff 62 | uses: docker://oskarstark/phpstan-ga 63 | + env: 64 | + CHECK_PLATFORM_REQUIREMENTS: false 65 | with: 66 | args: analyse src/ 67 | ``` 68 | 69 | to use a `phpstan.neon.dist` configuration file, just drop the `phpstan.neon.dist` 70 | in your repository root and it will be taken into account. 71 | 72 | 73 | **You can copy/paste the .github folder (under examples/) to your project and thats all!** 74 | 75 | ## Docker 76 | 77 | A Docker-Image is built automatically and located here: 78 | https://hub.docker.com/r/oskarstark/phpstan-ga 79 | 80 | You can run it in any given directory like this: 81 | 82 | `docker run --rm -it -w=/app -v ${PWD}:/app oskarstark/phpstan-ga:latest analyse src/ --level=5` 83 | 84 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | # https://help.github.com/en/articles/metadata-syntax-for-github-actions 2 | 3 | author: 'OskarStark' 4 | 5 | branding: 6 | icon: 'check' 7 | color: 'blue' 8 | 9 | description: 'Use PHPStan via GithubAction.' 10 | 11 | name: 'OSKAR-phpstan' 12 | 13 | runs: 14 | using: 'docker' 15 | image: 'docker://oskarstark/phpstan-ga:2.1.17' 16 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | set -e 4 | 5 | /composer/vendor/bin/phpstan --version 6 | 7 | echo "::group::Installed PHPStan extensions" 8 | composer show "*phpstan*" 9 | echo "::endgroup::" 10 | 11 | IGNORE_PLATFORM_REQS="" 12 | if [ "$CHECK_PLATFORM_REQUIREMENTS" = "false" ]; then 13 | IGNORE_PLATFORM_REQS="--ignore-platform-reqs" 14 | fi 15 | 16 | NO_DEV="--no-dev" 17 | if [ "$REQUIRE_DEV" = "true" ]; then 18 | NO_DEV="" 19 | fi 20 | 21 | COMPOSER_COMMAND="composer install --no-progress $NO_DEV $IGNORE_PLATFORM_REQS" 22 | echo "::group::$COMPOSER_COMMAND" 23 | 24 | if [ "$ALLOW_DEV" = "true" ]; then 25 | composer config minimum-stability dev 26 | composer config prefer-stable true 27 | fi 28 | 29 | $COMPOSER_COMMAND 30 | echo "::endgroup::" 31 | /composer/vendor/bin/phpstan $* 32 | -------------------------------------------------------------------------------- /examples/.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | pull_request: 4 | 5 | name: Test 6 | 7 | jobs: 8 | phpstan: 9 | name: PHPStan 10 | 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: "Checkout" 15 | uses: actions/checkout@v3 16 | 17 | - name: PHPStan 18 | uses: docker://oskarstark/phpstan-ga 19 | with: 20 | args: analyze src/ --level=5 21 | --------------------------------------------------------------------------------