diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..298129d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,14 @@ +name: release + +"on": + release: + types: [published, edited] + workflow_dispatch: + +jobs: + actions-tagger: + runs-on: windows-latest + steps: + - uses: Actions-R-Us/actions-tagger@latest + with: + publish_latest_tag: true diff --git a/Dockerfile b/Dockerfile index 72f7829..5a1440e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,5 @@ FROM composer:latest -RUN composer global require laravel/pint --no-progress --dev -ENV PATH="/tmp/vendor/bin:${PATH}" - COPY "entrypoint.sh" "/entrypoint.sh" RUN chmod +x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 645c316..267a23a 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,32 @@ GitHub Action implementation of the [Laravel Pint](https://github.com/laravel/pi Use with [GitHub Actions](https://github.com/features/actions) -_.github/workflows/pint.yml_ +`_.github/workflows/pint.yml` -``` +```yml name: PHP Linting on: pull_request jobs: phplint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: aglipanci/laravel-pint-action@main + - uses: actions/checkout@v4 + - name: "laravel-pint" + uses: aglipanci/laravel-pint-action@latest + with: + preset: laravel + verboseMode: true + testMode: true + configPath: "vendor/my-company/coding-style/pint.json" + pintVersion: 1.8.0 + onlyDirty: true + onlyDiff: "main" + ``` +ℹ️ Starting from version 2 you can specify the Pint version to be used by specifying a `pintVersion` in your configuration file. + +If provided, a `pint.json` file in the root will be used for configuration during run of the Action. + +This action **DOESN'T** commit changes automatically. If you want to achieve such behaviour you have to use it in combination with another action like [git-auto-commit Action](https://github.com/stefanzweifel/git-auto-commit-action) or [Create Pull Request Action](https://github.com/marketplace/actions/create-pull-request). -If provided, a `pint.json` file in the root will be used for configuration during run of the Action. \ No newline at end of file +You can see Laravel Pint Action running on my [demo repository](https://github.com/aglipanci/laravel-pint-action-demo/pulls). diff --git a/action.yml b/action.yml index c5d7596..fa55780 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,26 @@ inputs: preset: description: "pint preset" required: false + + onlyDirty: + description: "only format changed files" + required: false + + onlyDiff: + description: "only format changed files that differ from the provided branch" + required: false + + parallel: + description: "run Pint in parallel mode (requires Pint >= 1.23)" + required: false + + pintVersion: + description: "laravel/pint composer version to install a specific version." + required: false + + useComposer: + description: "Use Laravel Pint version from project composer lock file. Lock file must be preset to use this flag." + required: false runs: using: 'docker' image: 'Dockerfile' @@ -25,6 +45,11 @@ runs: - ${{ inputs.verbose-mode }} - ${{ inputs.config-path }} - ${{ inputs.preset }} + - ${{ inputs.only-dirty }} + - ${{ inputs.onlyDiff }} + - ${{ inputs.parallel }} + - ${{ inputs.pint-version }} + - ${{ inputs.use-composer }} branding: icon: 'eye' - color: 'gray-dark' \ No newline at end of file + color: 'gray-dark' diff --git a/entrypoint.sh b/entrypoint.sh index 118947c..e506b6a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,24 +1,58 @@ #!/bin/bash set -e -command_string=("pint") +pint_install_command=("composer global require laravel/pint:PINT_VERSION --no-progress --dev") +if [[ "${INPUT_PINTVERSION}" ]] +then + pint_install_command="${pint_install_command/PINT_VERSION/${INPUT_PINTVERSION}}" +elif [[ "${INPUT_USECOMPOSER}" ]] +then + pint_install_command="${pint_install_command/PINT_VERSION/$(composer show --locked | grep 'laravel/pint' | awk '{print $2}')}" +else + pint_install_command="${pint_install_command/:PINT_VERSION/}" +fi + +echo "Running Command: ${pint_install_command[@]}" +${pint_install_command[@]} +PATH="/tmp/vendor/bin:${PATH}" + +pint_version=$(pint --version | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -1) +version_check=$(printf '%s\n1.23' "$pint_version" | sort -V | head -1) -if [[ "${INPUT_TESTMODE}" ]]; then - command_string+=" --test" +pint_command=("pint") +if [[ "${INPUT_TESTMODE}" == true ]]; then + pint_command+=" --test" fi -if [[ "${INPUT_VERBOSEMODE}" ]]; then - command_string+=" -v" +if [[ "${INPUT_VERBOSEMODE}" == true ]]; then + pint_command+=" -v" fi if [[ "${INPUT_CONFIGPATH}" ]]; then - command_string+=" --config ${INPUT_CONFIGPATH}" + pint_command+=" --config ${INPUT_CONFIGPATH}" fi if [[ "${INPUT_PRESET}" ]]; then - command_string+=" --preset ${INPUT_PRESET}" + pint_command+=" --preset ${INPUT_PRESET}" +fi + +if [[ "${INPUT_ONLYDIFF}" ]]; then + pint_command+=" --diff=${INPUT_ONLYDIFF}" +fi + +if [[ "${INPUT_ONLYDIRTY}" == true ]]; then + pint_command+=" --dirty" +fi + +if [[ "${INPUT_PARALLEL}" == true ]]; then + if [[ "$version_check" == "1.23" ]]; then + pint_command+=" --parallel" + echo "Parallel mode enabled (Pint version: $pint_version)" + else + echo "Warning: Parallel mode requested but Pint version $pint_version < 1.23. Skipping --parallel flag." + fi fi -echo "Running Command: " "${command_string[@]}" +echo "Running Command: " "${pint_command[@]}" -${command_string[@]} \ No newline at end of file +${pint_command[@]}