Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wpspecialprojects authored Jul 22, 2024
0 parents commit 85a0b6b
Show file tree
Hide file tree
Showing 61 changed files with 23,992 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.{yml,yaml,json}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.txt]
end_of_line = crlf
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Bug report
description: Create a bug report to help us improve.
body:
- type: textarea
id: description
attributes:
label: Description
validations:
required: true

- type: textarea
id: steps
attributes:
label: Steps to reproduce
placeholder: |
1. Start at `site-domain.com/blog`.
2. Click on any blog post.
3. Click on the 'Like' button.
4. ...
Attach any media by drag and dropping or selecting upload.
- type: textarea
id: expected
attributes:
label: What you expected to happen
placeholder: |
e.g. The post should be liked.
- type: textarea
id: actual
attributes:
label: What actually happened
placeholder: |
e.g. Clicking the button does nothing visibly.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: true
18 changes: 18 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Feature request
description: Create a feature request for this project.
body:
- type: textarea
id: description
attributes:
label: Description
description: Add a concise description of the feature being requested.
placeholder: What will this feature accomplish?
validations:
required: true

- type: textarea
id: context
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
placeholder: Add links to previous work or other sites that do something similar.
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#### Changes proposed in this Pull Request

*

#### Testing instructions

<!--
Add as many details as possible to help others reproduce the issue and test the fix.
"Before / After" screenshots can also be very helpful when the change is visual.
-->

*

Mentions #
72 changes: 72 additions & 0 deletions .github/workflows/fill-in-scaffold.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { statSync } from 'fs';
import { readdir, readFile } from 'fs/promises';
import { writeFile } from 'fs/promises';
import { join as joinPath } from 'path';
import process from 'process';

const repository = JSON.parse( process.argv[2] );
const skip_dirs = [ '.github', '.git' ];

/**
* @param {string} dirPath
* @param {(filePath: string) => Promise<void>} callback
*/
const traverseDirectory = async ( dirPath, callback ) => {
if ( skip_dirs.includes( dirPath ) ) {
console.log( 'Skipping %s', dirPath );
return;
}
console.log( 'Traversing %s', dirPath );

const files = await readdir( dirPath ); // Read the contents of the directory
for ( const file of files ) {
const filePath = joinPath( dirPath, file );

if ( statSync( filePath ).isFile() ) {
await callback( filePath );
} else { // Recursively traverse directories
await traverseDirectory( filePath, callback );
}
}
};

/**
* Build a template using envs
* @param {string} filePath
*/
const buildTemplate = async ( filePath ) => {
console.log( 'Building %s', filePath );

const templateFile = await readFile( filePath, 'utf-8' );
let renderedTemplate = templateFile, replacements;

const title = repository.custom_properties['human-title'] ?? repository.name;
if ( 'README.md' === filePath ) {
replacements = {
'EXAMPLE_REPO_NAME': title,
'EXAMPLE_REPO_DESCRIPTION': repository.description ?? '',
};
} else {
replacements = {
'Team51 Plugin Scaffold': title,
'A scaffold for WP.com Special Projects plugins.': repository.description ?? '',
'team51-plugin-scaffold': repository.name,
'wpcomsp-scaffold': repository.name,
'WPCOMSpecialProjects\\Scaffold': 'WPCOMSpecialProjects\\' + title.replaceAll( ' ', '' ).replace( 'WPCOMSP', '' ),
'WPCOMSpecialProjects\\\\Scaffold': 'WPCOMSpecialProjects\\\\' + title.replaceAll( ' ', '' ).replace( 'WPCOMSP', '' ),
'wpcomsp_scaffold': repository.custom_properties['php-globals-short-prefix'],
'WPCOMSP_SCAFFOLD': repository.custom_properties['php-globals-short-prefix'].toUpperCase(),
};
}

for ( const [ key, value ] of Object.entries( replacements ) ) {
renderedTemplate = renderedTemplate.replaceAll( key, value );
}

if ( renderedTemplate !== templateFile ) {
console.log( 'Changes were made. Overwriting file.' );
await writeFile( filePath, renderedTemplate );
}
};

await traverseDirectory( '.', buildTemplate );
42 changes: 42 additions & 0 deletions .github/workflows/fill-in-scaffold.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Fill in the Scaffold Placeholders

on:
repository_dispatch:
types: [ fill_scaffold ]
workflow_dispatch:

jobs:
fill-scaffold:
if: github.repository != 'a8cteam51/team51-plugin-scaffold' # Don't run this on the scaffold itself.

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Setup proper Node.js version
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Set github actions[bot] as the committer.
run: git config --local user.name 'github-actions[bot]' && git config --local user.email 'github-actions[bot]@users.noreply.github.com'

- name: Rename the readme and plugin file.
run: |
git mv --force README.scaffold.md README.md
git mv team51-plugin-scaffold.php ${{ github.event.repository.name }}.php
- name: Commit the changed files.
run: git commit -am "chore -- rename files from scaffolding"

- name: Perform string replacements within the files.
run: node ./.github/workflows/fill-in-scaffold.mjs '${{ toJSON( github.event.repository ) }}'

- name: Commit the changed files.
run: git commit -am "chore -- fill in scaffolding placeholders"

- name: Push all the changed files.
run: git push
28 changes: 28 additions & 0 deletions .github/workflows/js-css-coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: JS+CSS Coding Standards

on:
push:
branches: [ trunk, develop ]
pull_request:
branches: [ trunk, develop ]

jobs:
lint-js_css-files:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup proper Node.js version
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- name: Install dependencies
run: npm ci

- name: Run JS linter
run: npm run lint:scripts

- name: Run CSS linter
run: npm run lint:styles
42 changes: 42 additions & 0 deletions .github/workflows/php-coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PHP Coding Standards

on:
push:
branches: [ trunk, develop ]

jobs:
build:
strategy:
matrix:
php: [ 8.2 ]

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer

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

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer run-script packages-install

- name: Run PHP_CodeSniffer
run: composer run-script lint:php
31 changes: 31 additions & 0 deletions .github/workflows/php-syntax-errors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: PHP Syntax Errors

on:
push:
branches: [ trunk, develop ]
pull_request:
branches: [ trunk, develop ]

jobs:
build:
strategy:
matrix:
php: [ 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3 ] # Include all PHP versions between the absolute minimum that shouldn't throw an error and the latest release version.

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Setup proper PHP version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Check all files for syntax errors
if: ${{ matrix.php >= 8.2 }} # At least the minimum PHP version required by the plugin.
run: find -L $GITHUB_WORKSPACE -path $GITHUB_WORKSPACE/vendor -prune -o -name '*.php' -print0 | xargs -0 -n 1 -P 4 php -l

- name: Check bootstrap files for syntax errors
if: ${{ matrix.php <= 8.1 }}
run: find $GITHUB_WORKSPACE -maxdepth 1 -name 'team51-plugin-scaffold.php' -print0 | xargs -0 -n 1 -P 4 php -l
Loading

0 comments on commit 85a0b6b

Please sign in to comment.