Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW scaffolding & var-replacement workflow #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/rename_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
while getopts a:n:u:d: flag
do
case "${flag}" in
a) author=${OPTARG};;
n) name=${OPTARG};;
u) urlname=${OPTARG};;
d) description=${OPTARG};;
esac
done

echo "Author: $author";
echo "Project Name: $name";
echo "Project URL name: $urlname";
echo "Description: $description";

echo "Renaming project..."

original_author="author_name"
original_name="project_name"
original_urlname="project_urlname"
original_description="project_description"
# for filename in $(find . -name "*.*")
for filename in $(git ls-files)
do
sed -i "s/$original_author/$author/g" $filename
sed -i "s/$original_name/$name/g" $filename
sed -i "s/$original_urlname/$urlname/g" $filename
sed -i "s/$original_description/$description/g" $filename
echo "Renamed $filename"
done

mv project_name $name

# This command runs only once on GHA!
rm -rf .github/template.yml
rm -rf .github/workflows/rename_project.yml
rm -rf copy/workflows/rename_project.yml
rm -rf .github/rename_project.sh

rm -rf README.md
mv README.tmpl.md README.md


1 change: 1 addition & 0 deletions .github/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
author: GatherPress
41 changes: 41 additions & 0 deletions .github/workflows/rename_project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Rename the project from template

on: [push]

permissions: write-all

jobs:
rename-project:
if: ${{ !contains (github.repository, '/gatherpress-awesome') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# by default, it uses a depth of 1
# this fetches all history so that we can read each commit
fetch-depth: 0
ref: ${{ github.head_ref }}

- run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}' | tr '-' '_' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
shell: bash

- run: echo "REPOSITORY_URLNAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
shell: bash

- run: echo "REPOSITORY_OWNER=$(echo '${{ github.repository }}' | awk -F '/' '{print $1}')" >> $GITHUB_ENV
shell: bash

- name: Is this still a template
id: is_template
run: echo "::set-output name=is_template::$(ls .github/template.yml &> /dev/null && echo true || echo false)"

- name: Rename the project
if: steps.is_template.outputs.is_template == 'true'
run: |
echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}"
.github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} -u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_NAME }} is Awesome for GatherPress."

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "✅ Ready to get Awesome."
push_options: --force
11 changes: 9 additions & 2 deletions .wordpress-org/blueprints/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{
"step": "setSiteOptions",
"options": {
"blogname": "GatherPress Awesome",
"blogname": "GatherPress project_name",
"blogdescription": "Powering Communities with WordPress.",
"users_can_register": 1,
"permalink_structure": "/%year%/%monthnum%/%postname%/"
Expand All @@ -31,6 +31,13 @@
"step": "runPHP",
"code": "<?php require '/wordpress/wp-load.php'; $user_id = wp_create_user('editor', 'editorpass', '[email protected]'); (new WP_User($user_id))->set_role('editor');"
},
{
"step": "updateUserMeta",
"meta": {
"admin_color": "modern"
},
"userId": 1
},
{
"step": "login",
"username": "admin",
Expand All @@ -50,7 +57,7 @@
"step": "installPlugin",
"pluginZipFile": {
"resource": "url",
"url": "https://github-proxy.com/proxy/?repo=GatherPress/gatherpress-awesome"
"url": "https://github-proxy.com/proxy/?repo=author_name/project_urlname"
},
"options": {
"activate": true
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@ A starter plugin for GatherPress companion plugin development.

- [x] Test [GatherPress Awesome in Playground](https://playground.wordpress.net/builder/builder.html?blueprint-url=https://raw.githubusercontent.com/GatherPress/gatherpress-awesome/main/.wordpress-org/blueprints/blueprint.json), with GatherPress installed & demo-data already in place.

## Up to you
### Up to you

- [ ] [Create your own GatherPress Awesome demo-data](https://github.com/carstingaxion/crud-the-docs-playground), and add it to your [`blueprint.json`](/.wordpress-org/blueprints/blueprint.json).


## You should create a new repository from [this template](https://github.com/new?template_name=gatherpress-awesome&template_owner=GatherPress) for yourself, if you'd like to ...

- **collaboratively work** on a compagnion-plugin for GatherPress

- extend GatherPress' standard **scenarios using your plugin or theme**

- see how GatherPress works & test its extendebility.

### Ready in 10 seconds

Creating a new repository from [this template](https://github.com/new?template_name=gatherpress-awesome&template_owner=GatherPress) lets you start immediately, because all paths, folder names etc. will be replaced to match the URLs of your new created repo. *Enjoy!*

This happens within an automated first commit directly after the repo gets initialised. So, please calm for 10 seconds and finally refresh the page.


## Acknowledgments

- [python-project-template](https://github.com/rochacbruno/python-project-template) for their nice template->repo renaming workflow

22 changes: 22 additions & 0 deletions README.tmpl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# GatherPress project_name

A starter plugin for GatherPress companion plugin development.

## Already prepared for your GatherPress project_name plugin

- [x] Test [GatherPress project_name in Playground](https://playground.wordpress.net/builder/builder.html?blueprint-url=https://raw.githubusercontent.com/author_name/project_urlname/main/.wordpress-org/blueprints/blueprint.json), with GatherPress installed & project_name already in place.

### Up to you

- [ ] [Create your own GatherPress project_name demo-data](https://github.com/carstingaxion/crud-the-docs-playground), and add it to your [`blueprint.json`](/.wordpress-org/blueprints/blueprint.json).


## You should create a new repository from [the original template](https://github.com/new?template_name=gatherpress-awesome&template_owner=GatherPress) for yourself, too, if you'd like to ...

- **collaboratively work** on a compagnion-plugin for GatherPress

- extend GatherPress' standard **scenarios using your plugin or theme**

- see how GatherPress works & test its extendebility.


26 changes: 13 additions & 13 deletions gatherpress-awesome.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
/**
* Plugin Name: GatherPress Awesome
* Plugin Name: GatherPress project_name
* Plugin URI: https://gatherpress.org/
* Description: Powering Communities with WordPress.
* Author: The GatherPress Community
* Author URI: https://gatherpress.org/
* Version: 1.0.0
* Requires PHP: 7.4
* Text Domain: gatherpress-awesome
* Text Domain: project_urlname
* License: GPLv2 or later (license.txt)
*
* @package GatherPress_Awesome
* @package GatherPress_project_urlname
*/

// Exit if accessed directly.
Expand All @@ -21,34 +21,34 @@
define( 'GATHERPRESS_AWESOME_CORE_PATH', __DIR__ );

/**
* Adds the GatherPress_Awesome namespace to the autoloader.
* Adds the GatherPress_project_urlname namespace to the autoloader.
*
* This function hooks into the 'gatherpress_autoloader' filter and adds the
* GatherPress_Awesome namespace to the list of namespaces with its core path.
* GatherPress_project_urlname namespace to the list of namespaces with its core path.
*
* @param array $namespace An associative array of namespaces and their paths.
* @return array Modified array of namespaces and their paths.
*/
function gatherpress_awesome_autoloader( array $namespace ): array {
$namespace['GatherPress_Awesome'] = GATHERPRESS_AWESOME_CORE_PATH;
function gatherpress_project_urlname_autoloader( array $namespace ): array {
$namespace['GatherPress_project_urlname'] = GATHERPRESS_AWESOME_CORE_PATH;

return $namespace;
}
add_filter( 'gatherpress_autoloader', 'gatherpress_awesome_autoloader' );
add_filter( 'gatherpress_autoloader', 'gatherpress_project_urlname_autoloader' );

/**
* Initializes the GatherPress Awesome setup.
* Initializes the GatherPress project_name setup.
*
* This function hooks into the 'plugins_loaded' action to ensure that
* the GatherPress_Awesome\Setup instance is created once all plugins are loaded,
* the GatherPress_project_urlname\Setup instance is created once all plugins are loaded,
* only if the GatherPress plugin is active.
*
* @return void
*/
function gatherpress_awesome_setup(): void {
function gatherpress_project_urlname_setup(): void {
if ( defined( 'GATHERPRESS_VERSION' ) ) {
GatherPress_Awesome\Setup::get_instance();
GatherPress_project_urlname\Setup::get_instance();
}

}
add_action( 'plugins_loaded', 'gatherpress_awesome_setup' );
add_action( 'plugins_loaded', 'gatherpress_project_urlname_setup' );
16 changes: 8 additions & 8 deletions includes/classes/class-setup.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Manages plugin setup for GatherPress Awesome.
* Manages plugin setup for GatherPress project_name.
*
* @package GatherPress_Awesome
* @package GatherPress_project_urlname
*/

namespace GatherPress_Awesome;
namespace GatherPress_project_urlname;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore
Expand Down Expand Up @@ -53,13 +53,13 @@ protected function setup_hooks(): void {
* @return array Modified array of sub-pages including the GatherPress Alpha sub-page.
*/
public function setup_sub_page( array $sub_pages ): array {
$sub_pages['awesome'] = array(
'name' => __( 'Awesome', 'gatherpress-awesome' ),
$sub_pages['project_urlname'] = array(
'name' => __( 'project_name', 'gatherpress-project_urlname' ),
'priority' => 10,
'sections' => array(
'awesome_it_works' => array(
'name' => __( 'Awesome', 'gatherpress-awesome' ),
'description' => __( 'GatherPress Awesome works!', 'gatherpress-awesome' ),
'project_urlname_it_works' => array(
'name' => __( 'project_name', 'gatherpress-project_urlname' ),
'description' => __( 'GatherPress project_name works!', 'gatherpress-project_urlname' ),
),
),
);
Expand Down