Skip to content

Commit

Permalink
Tweak CI jobs to rewrite branch githubusercontent.com URLs into trunk…
Browse files Browse the repository at this point in the history
… URLs
  • Loading branch information
adamziel committed Apr 15, 2024
1 parent 6511153 commit 82d46d7
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 37 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/postprocess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
Expand All @@ -17,8 +16,8 @@ jobs:
python-version: 3.8
- name: Install Prettier
run: npm install -g prettier
- name: Run make_index.py
run: python make_index.py
- name: Run reindex_postprocess.py
run: python reindex_postprocess.py
- name: Run Prettier
run: prettier --write blueprints/**/*.json
- name: Check for uncommitted changes
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/ships-blueprint-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Install jsonlint
run: |
sudo apt-get update
sudo apt-get install -y npm
npm install -g jsonlint
- name: Find updated directories
id: find_directories
run: |
Expand All @@ -27,3 +33,12 @@ jobs:
exit 1
fi
done < updated_directories.txt
- name: Validate blueprint.json files
run: |
while IFS= read -r directory; do
if [ -f "blueprints/$directory/blueprint.json" ]; then
echo "Validating blueprint.json file in $directory"
jsonlint -q "blueprints/$directory/blueprint.json"
fi
done < updated_directories.txt
6 changes: 3 additions & 3 deletions GALLERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Here's the list of all the community Blueprints submitted to this repository. Se

| Title | Preview | Source |
| ----- | ------- | ------ |
| Grid Variations Experiments enabled | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/grid-variations/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/grid-variations/blueprint.json) |
| Display Admin Notice | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/admin-notice/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/admin-notice/blueprint.json) |
| Custom Post Type: Books | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/custom-post/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/custom-post/blueprint.json) |
| Latest Gutenberg plugin | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/latest-gutenberg/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/latest-gutenberg/blueprint.json) |
| Display Admin Notice | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/admin-notice/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/admin-notice/blueprint.json) |
| Use wp-cli command to add posts | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/posts-via-wp-cli/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/posts-via-wp-cli/blueprint.json) |
| Custom Post Type: Books | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/custom-post/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/custom-post/blueprint.json) |
| Grid Variations Experiments enabled | [Preview](https://playground.wordpress.net/?blueprint-url=https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprints/grid-variations/blueprint.json) | [Source](https://github.com/adamziel/blueprints/blob/trunk/blueprints/grid-variations/blueprint.json) |

7 changes: 5 additions & 2 deletions blueprints/admin-notice/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"title": "Display Admin Notice ",
"description": "Blueprint to add a tiny mu-plugin and display an admin notice",
"author": "bph",
"categories": ["Admin", "notices"]
"categories": [
"Admin",
"notices"
]
},
"landingPage": "/wp-admin/plugins.php",
"steps": [
Expand All @@ -19,4 +22,4 @@
"data": "<?php add_action('admin_notices', function() { echo '<div class=\"notice notice-info is-dismissible\"><p>Hello from Playground.</p></div>'; });"
}
]
}
}
7 changes: 5 additions & 2 deletions blueprints/custom-post/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"title": "Custom Post Type: Books",
"description": "Blueprint that added a custom post type to playground",
"author": "bph",
"categories": ["Content", "CPT"]
"categories": [
"Content",
"CPT"
]
},
"landingPage": "/wp-admin/",
"steps": [
Expand All @@ -28,4 +31,4 @@
"pluginPath": "books/books.php"
}
]
}
}
7 changes: 5 additions & 2 deletions blueprints/grid-variations/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"title": "Grid Variations Experiments enabled",
"author": "bph",
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
"categories": ["Gutenberg", "Experiments"]
"categories": [
"Gutenberg",
"Experiments"
]
},
"landingPage": "/wp-admin/site-editor.php",
"steps": [
Expand All @@ -28,4 +31,4 @@
"code": "<?php require '/wordpress/wp-load.php'; update_option( 'gutenberg-experiments', array( 'gutenberg-grid-interactivity' => true ) );"
}
]
}
}
10 changes: 7 additions & 3 deletions blueprints/latest-gutenberg/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"title": "Latest Gutenberg plugin",
"author": "zieladam",
"description": "A preview of the latest version of the Gutenberg plugin.",
"categories": ["plugins"]
"categories": [
"plugins"
]
},
"plugins": ["gutenberg"]
}
"plugins": [
"gutenberg"
]
}
7 changes: 5 additions & 2 deletions blueprints/posts-via-wp-cli/blueprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"title": "Use wp-cli command to add posts",
"description": "Blueprint example to add posts via a wp-cli command.",
"author": "bph",
"categories": ["Content", "wpcli"]
"categories": [
"Content",
"wpcli"
]
},
"landingPage": "/wp-admin/edit.php",
"steps": [
Expand All @@ -18,4 +21,4 @@
"command": "wp post generate --count=12 --post_type=post --post_date=1999-01-04"
}
]
}
}
36 changes: 18 additions & 18 deletions index.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"blueprints/grid-variations/blueprint.json": {
"title": "Grid Variations Experiments enabled",
"blueprints/custom-post/blueprint.json": {
"title": "Custom Post Type: Books",
"description": "Blueprint that added a custom post type to playground",
"author": "bph",
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
"categories": [
"Gutenberg",
"Experiments"
"Content",
"CPT"
]
},
"blueprints/latest-gutenberg/blueprint.json": {
"title": "Latest Gutenberg plugin",
"author": "zieladam",
"description": "A preview of the latest version of the Gutenberg plugin.",
"categories": [
"plugins"
]
},
"blueprints/admin-notice/blueprint.json": {
Expand All @@ -17,14 +25,6 @@
"notices"
]
},
"blueprints/latest-gutenberg/blueprint.json": {
"title": "Latest Gutenberg plugin",
"author": "zieladam",
"description": "A preview of the latest version of the Gutenberg plugin.",
"categories": [
"plugins"
]
},
"blueprints/posts-via-wp-cli/blueprint.json": {
"title": "Use wp-cli command to add posts",
"description": "Blueprint example to add posts via a wp-cli command.",
Expand All @@ -34,13 +34,13 @@
"wpcli"
]
},
"blueprints/custom-post/blueprint.json": {
"title": "Custom Post Type: Books",
"description": "Blueprint that added a custom post type to playground",
"blueprints/grid-variations/blueprint.json": {
"title": "Grid Variations Experiments enabled",
"author": "bph",
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
"categories": [
"Content",
"CPT"
"Gutenberg",
"Experiments"
]
}
}
54 changes: 52 additions & 2 deletions make_index.py → reindex_postprocess.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import re
import sys


def build_json_index():
Expand All @@ -16,7 +17,6 @@ def build_json_index():
with open('index.json', 'w') as f:
json.dump(index, f, indent=2)

build_json_index()

def get_dot_template_files():
dot_template_files = []
Expand Down Expand Up @@ -63,4 +63,54 @@ def format_row(row):
with open(file.replace('.template', ''), 'w') as f:
f.write(re.sub(r'{BLUEPRINTS_TABLE}', ''.join(formatted_table), template))

build_markdown_table()

def rewrite_branch_urls_to_trunk():
with open('index.json', 'r') as f:
index = json.load(f)

for path, meta in index.items():
with open(path, 'r') as f:
blueprint = f.read()
json_blueprint = json.loads(blueprint)
map_url_resources(json_blueprint, branch_url_mapper)
with open(path, 'w') as f:
f.write(json.dumps(json_blueprint, indent="\t"))


def map_url_resources(blueprint_fragment, mapper):
"""
Recursively map URL resources in a blueprint using a mapper function.
A URL resource is a dictionary with a "resource": "url" entry, and a "url" key.
"""
if isinstance(blueprint_fragment, dict):
if 'resource' in blueprint_fragment and blueprint_fragment['resource'] == 'url' and 'url' in blueprint_fragment:
blueprint_fragment['url'] = mapper(blueprint_fragment['url'])
else:
for key, value in blueprint_fragment.items():
map_url_resources(value, mapper)
elif isinstance(blueprint_fragment, list):
for item in blueprint_fragment:
map_url_resources(item, mapper)

def branch_url_mapper(url):
"""
Rewrite a raw.githubusercontent.com URL to point to the trunk branch.
>>> branch_url_mapper('https://raw.githubusercontent.com/adamziel/blueprints/my-branch/blueprint.json')
'https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json'
>>> branch_url_mapper('https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json')
'https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json'
"""
if not url.startswith("https://raw.githubusercontent.com"):
return url
return re.sub(r'https://raw.githubusercontent.com/([^/]+)/([^/]+)/([^/]+)', r'https://raw.githubusercontent.com/\1/\2/trunk', url)

if '--test' in sys.argv:
print("Running doctests")
import doctest
doctest.testmod()
else:
print("Reindexing")
build_json_index()
build_markdown_table()
rewrite_branch_urls_to_trunk()

0 comments on commit 82d46d7

Please sign in to comment.