Skip to content

Commit

Permalink
Automatic php-cs-fixer with commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeweerd committed Dec 4, 2023
1 parent 2f93912 commit 49f59ca
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/phpcsfixer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
on: [pull_request, push]
name: PHP_CS_FIXER
jobs:
phan:
name: Run phpcs on modified or added files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Default checkout
- name: Show variables
run: |
git log
git status
git branch
echo "BASE_REF=$GITHUB_BASE_REF HEAD_REF=$GITHUB_HEAD_REF GITHUB_REF=$GITHUB_REF GITHUB_REF_NAME=$GITHUB_REF_NAME"
env
- name: Fetch up to merge-base on push
uses: BioData/fetch-through-merge-base@v0
timeout-minutes: 3
if: github.event_name == 'push'
with:
base_ref: develop
head_ref: ${{ github.sha }}
- name: Fetch up to merge-base on pull
uses: BioData/fetch-through-merge-base@v0
timeout-minutes: 3
if: github.event_name == 'pull_request'
with:
base_ref: ${{ github.base_ref }}
head_ref: ${{ github.sha }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
tools: cs2pr,phpcs,phpcbf,php-cs-fixer
- name: Run phpcs analysis
env:
ACTIONS_STEP_DEBUG: true
run: |
# Get base branch if PR
echo "BASE_REF=$GITHUB_BASE_REF HEAD_REF=$GITHUB_HEAD_REF GITHUB_REF=$GITHUB_REF GITHUB_REF_NAME=$GITHUB_REF_NAME"
DIFF_TARGET=$GITHUB_BASE_REF
echo "DIFF_TARGET='${DIFF_TARGET}'"
HEAD_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "HEAD_BRANCH='${HEAD_BRANCH}'"
[ "$HEAD_BRANCH" == "HEAD" ] && HEAD_BRANCH=$GITHUB_REF_NAME
echo "HEAD_BRANCH='${HEAD_BRANCH}'"
[ "$DIFF_TARGET" == "" ] && DIFF_TARGET=$(git show-branch -a --merge-base)
echo "DIFF_TARGET='${DIFF_TARGET}'"
TMPFILE=$(mktemp)
git diff --diff-filter=MA --name-only --merge-base "${DIFF_TARGET}" -- '***.php' > "${TMPFILE}"
RULESET_OPT="--standard=dev/setup/codesniffer/ruleset.xml"
ls -l ${TMPFILE} && cat ${TMPFILE}
[ ! -s ${TMPFILE} ] && echo "No change php files" && exit 0
echo run php-cs-fixer
[ -s ${TMPFILE} ] && while read f; do php-cs-fixer fix "$f" ; done < ${TMPFILE}
echo run phpcbf
[ -s ${TMPFILE} ] && phpcbf --file-list=${TMPFILE} -s -p -d memory_limit=-1 --extensions=php --tab-width=4 ${RULESET_OPT}
echo run phpcs
[ -s ${TMPFILE} ] && phpcs --file-list=${TMPFILE} -s -p --report=checkstyle --report-file=_phpcs.xml -d memory_limit=-1 --extensions=php --tab-width=4 ${RULESET_OPT}
- name: Add results to PR
if: ${{ always() }}
run: |
ls -l
[ ! -r _phpcs.xml ] || [ ! -s _phpcs.xml ] || cs2pr _phpcs.xml
- name: Provide phpcs log as artifact
uses: actions/upload-artifact@v3
# if: ${{ always() }}
if: false
with:
name: phpcs-srcrt
path: |
${{ github.workspace }}/_phpcs.xml
retention-days: 2
- name: Commit changes
run: |
git diff --exit-code && exit 0
git config user.name github-actions
git config user.email [email protected]
git add "*.php"
git commit -m "qual: PHP CS FIXER Github Action"
git push
3 changes: 2 additions & 1 deletion dev/tools/test/namespacemig/bbb.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

//use \Aaa as Aaa;

use Dolibarr\Aaa as Aaa;
use \Dolibarr\Aaa as Aaa;

use function Dolibarr\faaa as faaa; // Need php 5.6+

//use const Dolibarr\AAA;
Expand Down
2 changes: 1 addition & 1 deletion dev/translation/strip_language_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
if ((!empty($aSecondary[$key]) && $aSecondary[$key] != $aPrimary[$key]
&& !empty($aEnglish[$key]) && $aSecondary[$key] != $aEnglish[$key])
|| in_array($key, $arrayofkeytoalwayskeep) || preg_match('/^FormatDate/', $key) || preg_match('/^FormatHour/', $key)
) {
) {
//print "Key $key differs (aSecondary=".$aSecondary[$key].", aPrimary=".$aPrimary[$key].", aEnglish=".$aEnglish[$key].") so we add it into new secondary language (line: $cnt).\n";
fwrite($oh, $key."=".(empty($aSecondary[$key]) ? $aPrimary[$key] : $aSecondary[$key])."\n");
}
Expand Down

0 comments on commit 49f59ca

Please sign in to comment.