Skip to content

Commit 82d46d7

Browse files
committed
Tweak CI jobs to rewrite branch githubusercontent.com URLs into trunk URLs
1 parent 6511153 commit 82d46d7

File tree

10 files changed

+117
-37
lines changed

10 files changed

+117
-37
lines changed

.github/workflows/postprocess.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
1211
steps:
1312
- uses: actions/checkout@v2
1413
- name: Set up Python 3.8
@@ -17,8 +16,8 @@ jobs:
1716
python-version: 3.8
1817
- name: Install Prettier
1918
run: npm install -g prettier
20-
- name: Run make_index.py
21-
run: python make_index.py
19+
- name: Run reindex_postprocess.py
20+
run: python reindex_postprocess.py
2221
- name: Run Prettier
2322
run: prettier --write blueprints/**/*.json
2423
- name: Check for uncommitted changes

.github/workflows/ships-blueprint-json.yml

+15
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ jobs:
1313
- name: Checkout code
1414
uses: actions/checkout@v2
1515

16+
- name: Install jsonlint
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y npm
20+
npm install -g jsonlint
21+
1622
- name: Find updated directories
1723
id: find_directories
1824
run: |
@@ -27,3 +33,12 @@ jobs:
2733
exit 1
2834
fi
2935
done < updated_directories.txt
36+
37+
- name: Validate blueprint.json files
38+
run: |
39+
while IFS= read -r directory; do
40+
if [ -f "blueprints/$directory/blueprint.json" ]; then
41+
echo "Validating blueprint.json file in $directory"
42+
jsonlint -q "blueprints/$directory/blueprint.json"
43+
fi
44+
done < updated_directories.txt

GALLERY.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Here's the list of all the community Blueprints submitted to this repository. Se
44

55
| Title | Preview | Source |
66
| ----- | ------- | ------ |
7-
| 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) |
8-
| 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) |
7+
| 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) |
98
| 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) |
9+
| 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) |
1010
| 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) |
11-
| 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) |
11+
| 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) |
1212

blueprints/admin-notice/blueprint.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"title": "Display Admin Notice ",
55
"description": "Blueprint to add a tiny mu-plugin and display an admin notice",
66
"author": "bph",
7-
"categories": ["Admin", "notices"]
7+
"categories": [
8+
"Admin",
9+
"notices"
10+
]
811
},
912
"landingPage": "/wp-admin/plugins.php",
1013
"steps": [
@@ -19,4 +22,4 @@
1922
"data": "<?php add_action('admin_notices', function() { echo '<div class=\"notice notice-info is-dismissible\"><p>Hello from Playground.</p></div>'; });"
2023
}
2124
]
22-
}
25+
}

blueprints/custom-post/blueprint.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"title": "Custom Post Type: Books",
55
"description": "Blueprint that added a custom post type to playground",
66
"author": "bph",
7-
"categories": ["Content", "CPT"]
7+
"categories": [
8+
"Content",
9+
"CPT"
10+
]
811
},
912
"landingPage": "/wp-admin/",
1013
"steps": [
@@ -28,4 +31,4 @@
2831
"pluginPath": "books/books.php"
2932
}
3033
]
31-
}
34+
}

blueprints/grid-variations/blueprint.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"title": "Grid Variations Experiments enabled",
55
"author": "bph",
66
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
7-
"categories": ["Gutenberg", "Experiments"]
7+
"categories": [
8+
"Gutenberg",
9+
"Experiments"
10+
]
811
},
912
"landingPage": "/wp-admin/site-editor.php",
1013
"steps": [
@@ -28,4 +31,4 @@
2831
"code": "<?php require '/wordpress/wp-load.php'; update_option( 'gutenberg-experiments', array( 'gutenberg-grid-interactivity' => true ) );"
2932
}
3033
]
31-
}
34+
}

blueprints/latest-gutenberg/blueprint.json

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"title": "Latest Gutenberg plugin",
44
"author": "zieladam",
55
"description": "A preview of the latest version of the Gutenberg plugin.",
6-
"categories": ["plugins"]
6+
"categories": [
7+
"plugins"
8+
]
79
},
8-
"plugins": ["gutenberg"]
9-
}
10+
"plugins": [
11+
"gutenberg"
12+
]
13+
}

blueprints/posts-via-wp-cli/blueprint.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"title": "Use wp-cli command to add posts",
55
"description": "Blueprint example to add posts via a wp-cli command.",
66
"author": "bph",
7-
"categories": ["Content", "wpcli"]
7+
"categories": [
8+
"Content",
9+
"wpcli"
10+
]
811
},
912
"landingPage": "/wp-admin/edit.php",
1013
"steps": [
@@ -18,4 +21,4 @@
1821
"command": "wp post generate --count=12 --post_type=post --post_date=1999-01-04"
1922
}
2023
]
21-
}
24+
}

index.json

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
{
2-
"blueprints/grid-variations/blueprint.json": {
3-
"title": "Grid Variations Experiments enabled",
2+
"blueprints/custom-post/blueprint.json": {
3+
"title": "Custom Post Type: Books",
4+
"description": "Blueprint that added a custom post type to playground",
45
"author": "bph",
5-
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
66
"categories": [
7-
"Gutenberg",
8-
"Experiments"
7+
"Content",
8+
"CPT"
9+
]
10+
},
11+
"blueprints/latest-gutenberg/blueprint.json": {
12+
"title": "Latest Gutenberg plugin",
13+
"author": "zieladam",
14+
"description": "A preview of the latest version of the Gutenberg plugin.",
15+
"categories": [
16+
"plugins"
917
]
1018
},
1119
"blueprints/admin-notice/blueprint.json": {
@@ -17,14 +25,6 @@
1725
"notices"
1826
]
1927
},
20-
"blueprints/latest-gutenberg/blueprint.json": {
21-
"title": "Latest Gutenberg plugin",
22-
"author": "zieladam",
23-
"description": "A preview of the latest version of the Gutenberg plugin.",
24-
"categories": [
25-
"plugins"
26-
]
27-
},
2828
"blueprints/posts-via-wp-cli/blueprint.json": {
2929
"title": "Use wp-cli command to add posts",
3030
"description": "Blueprint example to add posts via a wp-cli command.",
@@ -34,13 +34,13 @@
3434
"wpcli"
3535
]
3636
},
37-
"blueprints/custom-post/blueprint.json": {
38-
"title": "Custom Post Type: Books",
39-
"description": "Blueprint that added a custom post type to playground",
37+
"blueprints/grid-variations/blueprint.json": {
38+
"title": "Grid Variations Experiments enabled",
4039
"author": "bph",
40+
"description": "Blueprint example to toggle on enable a feature from the Experiments page in Gutenberg plugin",
4141
"categories": [
42-
"Content",
43-
"CPT"
42+
"Gutenberg",
43+
"Experiments"
4444
]
4545
}
4646
}

make_index.py reindex_postprocess.py

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import re
4+
import sys
45

56

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

19-
build_json_index()
2020

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

66-
build_markdown_table()
66+
67+
def rewrite_branch_urls_to_trunk():
68+
with open('index.json', 'r') as f:
69+
index = json.load(f)
70+
71+
for path, meta in index.items():
72+
with open(path, 'r') as f:
73+
blueprint = f.read()
74+
json_blueprint = json.loads(blueprint)
75+
map_url_resources(json_blueprint, branch_url_mapper)
76+
with open(path, 'w') as f:
77+
f.write(json.dumps(json_blueprint, indent="\t"))
78+
79+
80+
def map_url_resources(blueprint_fragment, mapper):
81+
"""
82+
Recursively map URL resources in a blueprint using a mapper function.
83+
A URL resource is a dictionary with a "resource": "url" entry, and a "url" key.
84+
"""
85+
if isinstance(blueprint_fragment, dict):
86+
if 'resource' in blueprint_fragment and blueprint_fragment['resource'] == 'url' and 'url' in blueprint_fragment:
87+
blueprint_fragment['url'] = mapper(blueprint_fragment['url'])
88+
else:
89+
for key, value in blueprint_fragment.items():
90+
map_url_resources(value, mapper)
91+
elif isinstance(blueprint_fragment, list):
92+
for item in blueprint_fragment:
93+
map_url_resources(item, mapper)
94+
95+
def branch_url_mapper(url):
96+
"""
97+
Rewrite a raw.githubusercontent.com URL to point to the trunk branch.
98+
99+
>>> branch_url_mapper('https://raw.githubusercontent.com/adamziel/blueprints/my-branch/blueprint.json')
100+
'https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json'
101+
>>> branch_url_mapper('https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json')
102+
'https://raw.githubusercontent.com/adamziel/blueprints/trunk/blueprint.json'
103+
"""
104+
if not url.startswith("https://raw.githubusercontent.com"):
105+
return url
106+
return re.sub(r'https://raw.githubusercontent.com/([^/]+)/([^/]+)/([^/]+)', r'https://raw.githubusercontent.com/\1/\2/trunk', url)
107+
108+
if '--test' in sys.argv:
109+
print("Running doctests")
110+
import doctest
111+
doctest.testmod()
112+
else:
113+
print("Reindexing")
114+
build_json_index()
115+
build_markdown_table()
116+
rewrite_branch_urls_to_trunk()

0 commit comments

Comments
 (0)