Skip to content

Commit

Permalink
Merge pull request #5 from tarosky/feature/deploy-script-renewal
Browse files Browse the repository at this point in the history
Feature/deploy script renewal
  • Loading branch information
fumikito authored Jan 29, 2025
2 parents 4127c9a + 99c69d6 commit d8449d1
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"Vue": false
},
"extends": [
"plugin:@wordpress/eslint-plugin/recommended"
"plugin:@wordpress/eslint-plugin/recommended-with-formatting"
],
"rules": {
"no-alert": "off",
Expand Down
122 changes: 67 additions & 55 deletions .github/workflows/wordpress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,66 @@ name: Deploy Plugin

on:
push:
branches:
- main
tags:
- '*'
pull_request:
branches:
- main

jobs:
test:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-18.04 ] # OS. ubuntu-18.04 is also available.
php: [ '5.6', '7.2', '7.4' ] # PHP versions to check.
wp: [ 'latest', '5.5' ] # WordPress version to check.
services:
mysql:
image: mysql:5.7
options: --health-cmd "mysqladmin ping --host 127.0.0.1 --port 3306" --health-interval 20s --health-timeout 10s --health-retries 10
ports:
- 3306/tcp
env:
MYSQL_ROOT_PASSWORD: root
name: WordPress ${{ matrix.wp }} in PHP ${{ matrix.php }} UnitTest
steps:
- uses: actions/checkout@master

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: ${{ matrix.php }}

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Start MySQL
run: sudo systemctl start mysql

- name: Install WordPress
run: bash bin/install-wp-tests.sh wordpress root root 127.0.0.1:3306 ${{ matrix.wp }}

- name: Check PHP Unit
run: composer test

- name: Check PHP styntax
run: composer lint
# test:
# runs-on: ${{ matrix.operating-system }}
# strategy:
# matrix:
# operating-system: [ ubuntu-18.04 ] # OS. ubuntu-18.04 is also available.
# php: [ '7.2', '7.4' ] # PHP versions to check.
# wp: [ 'latest', '5.9' ] # WordPress version to check.
# services:
# mysql:
# image: mysql:5.7
# options: --health-cmd "mysqladmin ping --host 127.0.0.1 --port 3306" --health-interval 20s --health-timeout 10s --health-retries 10
# ports:
# - 3306/tcp
# env:
# MYSQL_ROOT_PASSWORD: root
# name: WordPress ${{ matrix.wp }} in PHP ${{ matrix.php }} UnitTest
# steps:
# - uses: actions/checkout@master
#
# - name: Setup PHP
# uses: nanasess/setup-php@master
# with:
# php-version: ${{ matrix.php }}
#
# - name: Validate composer.json and composer.lock
# run: composer validate
#
# - name: Install dependencies
# run: composer install --prefer-dist --no-progress --no-suggest
#
# - name: Start MySQL
# run: sudo systemctl start mysql
#
# - name: Install WordPress
# run: bash bin/install-wp-tests.sh wordpress root root 127.0.0.1:3306 ${{ matrix.wp }}
#
# - name: Check PHP Unit
# run: composer test

lint:
name: Check PHP styntax
uses: tarosky/workflows/.github/workflows/phpcs.yml@main
with:
version: 7.4

assets:
name: Check Assets
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@main

- name: Install Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '12'

Expand All @@ -70,24 +71,36 @@ jobs:
- name: Check JS & CSS syntax
run: npm run lint

status-check:
name: Status Check
runs-on: ubuntu-latest
if: always()
needs: [ lint, assets ]
steps:
- uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}


release:
name: Deploy GitHub Release
needs: [ test, assets ]
needs: [ status-check ]
if: contains(github.ref, 'tags/')
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@main

- name: Confirm
run: echo ${{ needs.pre_release.outputs.upload_url }}
- name: Install Subversion
run: sudo apt-get install subversion

- name: Setup PHP
uses: nanasess/setup-php@master
uses: shivammathur/setup-php@v2
with:
php-version: '5.6'
php-version: '7.4'
tools: composer

- name: Install NPM
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: '12'

Expand All @@ -103,7 +116,6 @@ jobs:
SVN_USERNAME: ${{ secrets.WP_ORG_USERNAME_TAROSKY }}
SVN_PASSWORD: ${{ secrets.WP_ORG_PASSWORD_TAROSKY }}


- name: Create Release
id: pre_release
uses: actions/[email protected]
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Taro CPT Front

Contributors: tarosky,Takahashi_Fumiki
Tags: CPT
Requires at least: 5.5.0
Requires PHP: 5.6
Tested up to: 5.8
Requires at least: 5.9
Requires PHP: 7.4
Tested up to: 6.7
Stable Tag: nightly
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
Expand Down Expand Up @@ -38,6 +38,11 @@ Create new ticket at Support forum. Or else, create [new issue](https://github.c

## Changelog

### 1.1.0

* Bump required PHP version.
* Fix small bugs.

### 1.0.0

* Initial release.
* Initial release.
21 changes: 10 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
"license": "GPL-3.0-or-later",
"scripts": {
"test": "phpunit",
"lint": [
"phpcs --config-set installed_paths $(pwd)/vendor/wp-coding-standards/wpcs",
"phpcs --standard=phpcs.ruleset.xml $(find ./ -name '*.php')"
],
"fix": [
"phpcs --config-set installed_paths $(pwd)/vendor/wp-coding-standards/wpcs",
"phpcbf --standard=phpcs.ruleset.xml $(find ./ -name '*.php')"
]
"lint": "phpcs --standard=phpcs.ruleset.xml $(find ./ -name '*.php')",
"fix": "phpcbf --standard=phpcs.ruleset.xml $(find ./ -name '*.php')"
},
"authors": [
{
Expand All @@ -21,12 +15,17 @@
}
],
"require": {
"php": "^5.6|^7.0"
"php": ">=7.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^6",
"phpunit/phpunit": ">=6",
"squizlabs/php_codesniffer": "^3.0",
"wp-coding-standards/wpcs": "^2.0",
"wp-coding-standards/wpcs": "^3.0",
"yoast/phpunit-polyfills": "^1.0"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
11 changes: 5 additions & 6 deletions includes/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @param string[] $states States.
* @param WP_Post $post Post object.
*/
add_filter( 'display_post_states', function( $states, $post ) {
add_filter( 'display_post_states', function ( $states, $post ) {
if ( ! ts_cptf_is_front( $post ) ) {
return $states;
}
Expand All @@ -22,7 +22,7 @@
/**
* Save pst dat.
*/
add_action( 'save_post', function( $post_id, $post ) {
add_action( 'save_post', function ( $post_id, $post ) {
if ( ! wp_verify_nonce( filter_input( INPUT_POST, '_tscptfnonce' ), 'tscptf_update' ) ) {
return;
}
Expand All @@ -31,19 +31,18 @@
} else {
delete_post_meta( $post_id, '_tscptf_is_front' );
}

}, 10, 2 );

/**
* Register meta box.
*
* @param string $post_type Post type.
*/
add_action( 'add_meta_boxes', function( $post_type ) {
add_action( 'add_meta_boxes', function ( $post_type ) {
if ( ! ts_cptf_available( $post_type ) ) {
return;
}
add_meta_box( 'tscpf-is-front', __( 'Front Page Setting', 'tscptf' ), function( WP_Post $post ) {
add_meta_box( 'tscpf-is-front', __( 'Front Page Setting', 'tscptf' ), function ( WP_Post $post ) {
$front = ts_cptf_get_front_page( $post->post_type );
if ( $front && $front->ID !== $post->ID ) {
// Other page is front.
Expand All @@ -57,7 +56,7 @@
} else {
wp_nonce_field( 'tscptf_update', '_tscptfnonce', false );
$is_front = $front ? 1 : 0;
foreach ( [ __( 'Not a Front Page', 'tscptf' ), __( 'Set as a Front Page', 'tscptf' ) ] as $index => $label ) {
foreach ( array( __( 'Not a Front Page', 'tscptf' ), __( 'Set as a Front Page', 'tscptf' ) ) as $index => $label ) {
printf(
'<p><label><input type="radio" value="%s" name="tscptf-is-front" %s /> %s</label></p>',
esc_attr( $index ),
Expand Down
18 changes: 9 additions & 9 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function ts_cptf_available( $post_type ) {
* @return string[]
*/
function ts_cptf_post_types() {
return (array) get_option( 'ts-cptf-post-types', [] );
return (array) get_option( 'ts-cptf-post-types', array() );
}

/**
Expand All @@ -46,19 +46,19 @@ function ts_cptf_is_front( $post = null ) {
* @return WP_Post|null
*/
function ts_cptf_get_front_page( $post_type ) {
$query = new WP_Query( [
$query = new WP_Query( array(
'post_type' => $post_type,
'post_status' => 'any',
'posts_per_page' => 1,
'no_fround_rows' => true,
'ignore_sticky' => true,
'meta_query' => [
[
'meta_query' => array(
array(
'key' => '_tscptf_is_front',
'value' => '1',
],
],
] );
),
),
) );
foreach ( $query->posts as $post ) {
return $post;
}
Expand All @@ -75,9 +75,9 @@ function ts_cptf_post_type_struct( $post_type ) {
global $wp_rewrite;
$post_type_obj = get_post_type_object( $post_type );
if ( ! $post_type_obj ) {
return [];
return array();
}
$struct = [ trim( $post_type_obj->rewrite['slug'], '/' ) ];
$struct = array( trim( $post_type_obj->rewrite['slug'], '/' ) );
if ( $post_type_obj->rewrite['with_front'] && ( '/' !== $wp_rewrite->front ) ) {
array_unshift( $struct, trim( $wp_rewrite->front, '/' ) );
}
Expand Down
18 changes: 9 additions & 9 deletions includes/rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* Filter permalink.
*/
add_filter( 'post_type_link', function( $link, $post ) {
add_filter( 'post_type_link', function ( $link, $post ) {
if ( ts_cptf_is_front( $post ) && get_option( 'rewrite_rules' ) ) {
// This is front page.
// Generate original pemalink.
Expand All @@ -24,7 +24,7 @@
*
* @aram string[] $vars Query vars.
*/
add_filter( 'query_vars', function( $vars ) {
add_filter( 'query_vars', function ( $vars ) {
$vars[] = 'root_of';
return $vars;
} );
Expand All @@ -35,8 +35,8 @@
* @param string[] $rules Rewrite rules.
* @return string[]
*/
add_filter( 'rewrite_rules_array', function( $rules ) {
$new_rules = [];
add_filter( 'rewrite_rules_array', function ( $rules ) {
$new_rules = array();
foreach ( ts_cptf_post_types() as $post_type ) {
$struct = ts_cptf_post_type_struct( $post_type );
if ( empty( $struct ) ) {
Expand All @@ -56,7 +56,7 @@
*
* @param WP_Query $wp_query Query object.
*/
add_action( 'pre_get_posts', function( $wp_query ) {
add_action( 'pre_get_posts', function ( $wp_query ) {
$is_front = $wp_query->get( 'root_of' );
if ( ! $is_front ) {
return;
Expand All @@ -65,11 +65,11 @@
$wp_query->set( 'posts_per_page', 1 );
$wp_query->set( 'no_found_rows', true );
$wp_query->set( 'ignore_sticky', true );
$wp_query->set( 'meta_query', [
[
$wp_query->set( 'meta_query', array(
array(
'key' => '_tscptf_is_front',
'value' => '1',
],
] );
),
) );
$wp_query->singular = true;
} );
Loading

0 comments on commit d8449d1

Please sign in to comment.