Skip to content

Commit

Permalink
NEW scaffolding & var-replacement workflow for the use as a template-…
Browse files Browse the repository at this point in the history
…repo (97,2% clone from crud-the-docs-playground)
  • Loading branch information
carstingaxion committed Aug 28, 2024
1 parent 9168e2e commit ac6ca34
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 25 deletions.
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
13 changes: 10 additions & 3 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 All @@ -60,7 +67,7 @@
"step": "importWxr",
"file": {
"resource": "url",
"url": "https://raw.githubusercontent.com/carstingaxion/gatherpress-demo-data/main/GatherPress-demo-data-2024.xml"
"url": "https://raw.githubusercontent.com/GatherPress/demo-data/main/GatherPress-demo-data-2024.xml"
}
}
]
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

0 comments on commit ac6ca34

Please sign in to comment.