Test CI
This commit is contained in:
parent
1fcbda759b
commit
d7dbb25bdf
2 changed files with 89 additions and 0 deletions
75
.github/workflows/files_changed.yaml
vendored
Normal file
75
.github/workflows/files_changed.yaml
vendored
Normal file
|
|
@ -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
|
||||
|
|
@ -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 }}
|
||||
Loading…
Reference in a new issue