From d7dbb25bdf3937bd67d160d0cd0e3dec69137f38 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 30 Jun 2023 11:51:07 +0200 Subject: [PATCH] Test CI --- .github/workflows/files_changed.yaml | 75 +++++++++++++++++++ .../workflows/{phpcbf.yml => phpcsfixer.yml} | 14 ++++ 2 files changed, 89 insertions(+) create mode 100644 .github/workflows/files_changed.yaml rename .github/workflows/{phpcbf.yml => phpcsfixer.yml} (66%) diff --git a/.github/workflows/files_changed.yaml b/.github/workflows/files_changed.yaml new file mode 100644 index 00000000000..235e71b0174 --- /dev/null +++ b/.github/workflows/files_changed.yaml @@ -0,0 +1,75 @@ +# If any file in input folder_path was changed then return true else return false +# echo all changed files +# for PUSH event - compare current commit with previous commit +# for PULL_REQUEST event - compare source branch with target branch +name: If files in folder_path were changed + +on: + workflow_call: + outputs: + all_changed_files: + description: List of all changed files in folder_path input + value: ${{ jobs.if-file-changed.outputs.all_changed_files }} + boolean_output: + description: true - if files in folder_path were changed. else false. + value: ${{ jobs.if-file-changed.outputs.boolean_output }} + inputs: + folder_path: + required: true + type: string + + +jobs: + if-file-changed: + name: Check if files changed + runs-on: ubuntu-latest + outputs: + boolean_output: ${{ steps.get_output.outputs.boolean_output }} + all_changed_files: ${{ steps.get_output.outputs.all_changed_files }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 # fetch all history of all branches + + - name: Get files changed on push + # if push on dev or master or main then get diff between current and previous commit + if: github.event_name=='push' && contains(fromJson('["dev", "master","main"]'), github.ref_name) + id: files_changed_on_push + run: | + all_changed_files=$(git --no-pager diff --name-only HEAD^ HEAD) + echo "::set-output name=all_changed_files::$all_changed_files" + + - name: Git files changed when pr is created/updated + # compare source branch with target branch in Pull request + if: github.event_name=='pull_request' + id: files_changed_on_pr + run: | + git symbolic-ref refs/remotes/origin/HEAD origin/${{github.base_ref}} + all_changed_files=$(git --no-pager diff --name-only origin/${{github.head_ref}} origin/${{github.base_ref}}) + echo "::set-output name=all_changed_files::$all_changed_files" + + + - name: Get combined boolean output + # if request is PUSH or PR , get appropriate boolean_output + id: get_output + run: | + if [[ ${{ steps.files_changed_on_push.outcome }} == "success" ]]; then + all_changed_files=${{ steps.files_changed_on_push.outputs.all_changed_files }} + elif [[ ${{ steps.files_changed_on_pr.outcome }} == "success" ]]; then + all_changed_files=${{ steps.files_changed_on_pr.outputs.all_changed_files }} + fi + + echo all files changed are - + echo $all_changed_files + + echo "::set-output name=all_changed_files::$all_changed_files" + echo "::set-output name=boolean_output::false" + for file in $all_changed_files; do + echo file = $file + if [[ $file == ${{inputs.folder_path}} ]]; then + echo file matches folder_path pattern + echo "::set-output name=boolean_output::true" + break + fi + done \ No newline at end of file diff --git a/.github/workflows/phpcbf.yml b/.github/workflows/phpcsfixer.yml similarity index 66% rename from .github/workflows/phpcbf.yml rename to .github/workflows/phpcsfixer.yml index e5973f88ada..370500011f0 100644 --- a/.github/workflows/phpcbf.yml +++ b/.github/workflows/phpcsfixer.yml @@ -1,15 +1,29 @@ name: GitHub CI PHPCS and PHPCBF on: push +#on: +# push: +# paths: +# - '**.php' jobs: + filesChanged: + uses: ./.github/workflows/files_changed.yaml + with: + folder_path: .* + linter_name: name: Run & fix PHP Code Sniffer runs-on: ubuntu-latest + needs: filesChanged steps: - uses: actions/checkout@v3 with: fetch-depth: 10 + - name: echo all changed files + run: | + echo ${{ needs.filesChanged.outputs.all_changed_files }} + echo boolean_output=${{ needs.filesChanged.outputs.boolean_output }} - uses: eldy/phpcsfixer-action@master with: github_token: ${{ secrets.github_token }}