Skip to content

Commit

Permalink
Merge pull request #36 from tarosky/feature/find-short-tags
Browse files Browse the repository at this point in the history
closes #34 ショートオープンタグをJSで見つける
  • Loading branch information
fumikito committed Feb 7, 2024
2 parents 4735cff + 8adb987 commit 55ecc3e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
npm test
phplint:
uses: tarosky/workflows/.github/workflows/phplint.yml@feature/php-syntax-check
uses: tarosky/workflows/.github/workflows/phplint.yml@main

php-shor-open-tag:
uses: tarosky/workflows/.github/workflows/php-short-open-tag.yml@feature/find-short-tags

readme:
name: Generate readme.txt
Expand Down Expand Up @@ -64,7 +67,7 @@ jobs:
status-check:
name: Status Check
runs-on: ubuntu-latest
needs: [ readme, lint, versioning, phplint ]
needs: [ readme, lint, versioning, phplint, php-shor-open-tag ]
steps:
- name: Display Status
run: echo "OK"
81 changes: 81 additions & 0 deletions .github/workflows/php-short-open-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: PHP Short Open Tag Check

on:
workflow_call:
inputs:
path:
description: 'Path to search short open tag.'
default: "."
required: false
type: string
version:
description: 'PHP version to run'
default: "8.0"
required: false
type: string
workflow_dispatch:
inputs:
path:
description: 'Path to search short open tag.'
default: "."
required: false
type: string
version:
description: 'PHP version to run'
default: "8.0"
required: false
type: string

jobs:
short-open-tag:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main

- name: Setup PHP with composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.version }}
tools: composer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Search Short Open tags
uses: actions/github-script@v7
id: short-open-tags
with:
result-encoding: string
script: |
const fs = require( 'fs');
const files = [];
const readFile = (dir) => {
fs.readdirSync( dir ).forEach( (file) => {
const path = dir + '/' + file;
if ( fs.statSync( path ).isDirectory() ) {
readFile( path );
} else if( /\.php$/.test( file ) ) {
files.push( path );
}
});
};
readFile( '${{ inputs.path }}' );
const shorts = [];
files.forEach( (file) => {
const content = fs.readFileSync( file, 'utf8' );
if ( /<\?( |\n|\t)/m.test( content ) ) {
shorts.push( file );
}
});
if ( shorts.length ) {
shorts.unshift( 'Short open tag found:' );
return shorts.join( "\t" );
} else {
return "OK";
}
- name: Show Results
if: steps.short-open-tags.outputs.result != 'OK'
shell: bash
run: |
echo "${{ steps.short-open-tags.outputs.result }}" >&2
exit 1
2 changes: 1 addition & 1 deletion .github/workflows/phplint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
sed -i '/^No syntax errors/d' output.txt
cat output.txt
php -r 'echo filesize( "output.txt" ) . "Byte"; if ( 1 >= filesize( "output.txt" ) ) { echo "No error detected."; unlink( "output.txt" ); }'
php -r 'echo filesize( "output.txt" ) . "Byte:\t"; if ( 1 >= filesize( "output.txt" ) ) { echo "No error detected."; unlink( "output.txt" ); }'
- name: Check error file exists.
id: check_files
Expand Down

0 comments on commit 55ecc3e

Please sign in to comment.