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

Experimental: Automatically fetch WXR attachments into Pull Requests #52

Draft
wants to merge 33 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d423397
Experimental: CI workflow to grab assets from WXR files
adamziel Jun 6, 2024
29d9ae5
Adjust ci workflow
adamziel Jun 6, 2024
811dda5
Adjust ci
adamziel Jun 6, 2024
349e734
Adjust ci
adamziel Jun 6, 2024
3a9a68f
tweak ci
adamziel Jun 6, 2024
4be06ac
tweak ci
adamziel Jun 6, 2024
4be89b9
Tweak ci
adamziel Jun 6, 2024
2840a19
tweak ci
adamziel Jun 6, 2024
d8e338b
Reindex and reformat Blueprints
Jun 6, 2024
b3011ac
Reindex and reformat Blueprints
Jun 6, 2024
ef66977
Reindex and reformat Blueprints
Jun 6, 2024
80b1f58
Reindex and reformat Blueprints
Jun 6, 2024
a6f70f2
Reindex and reformat Blueprints
Jun 6, 2024
747d379
Reindex and reformat Blueprints
Jun 6, 2024
a477cb5
Reindex and reformat Blueprints
Jun 6, 2024
1757203
Reindex and reformat Blueprints
Jun 6, 2024
3b81935
Reindex and reformat Blueprints
Jun 6, 2024
c0fd0aa
Reindex and reformat Blueprints
Jun 6, 2024
369bd60
Reindex and reformat Blueprints
Jun 6, 2024
e515d77
Reindex and reformat Blueprints
Jun 6, 2024
e3cf4d4
Reindex and reformat Blueprints
Jun 6, 2024
ddab4a5
Reindex and reformat Blueprints
Jun 6, 2024
32bd479
Tweak CI
adamziel Jun 6, 2024
903af18
Remove formatting workflow to avoid infinite loops
adamziel Jun 6, 2024
86c56d7
remove too many .phar files
adamziel Jun 6, 2024
0e54a98
Tweak CI
adamziel Jun 6, 2024
ed8dcdf
Tweak ci
adamziel Jun 6, 2024
11dc21f
tweak ci
adamziel Jun 6, 2024
9c37606
Tweak CI
adamziel Jun 6, 2024
a0f31bc
Tweak ci
adamziel Jun 6, 2024
518e209
Tweak CI
adamziel Jun 6, 2024
b695a84
Reindex and reformat Blueprints
Jun 6, 2024
947af1d
add importWxr to blueprint
adamziel Jun 6, 2024
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
90 changes: 90 additions & 0 deletions .github/workflows/fetch-wxr-assets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Get WXR assets

on:
pull_request:
types:
- opened
- synchronize

jobs:
validate-and-normalize:
runs-on: ubuntu-latest
steps:
- name: Setup SSH Keys
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.GH_DEPLOY_KEY }}
- name: Checkout the PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Fetch base branch
run: |
git fetch origin trunk
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1' # or any other version you need

- name: Get WXR normalizer
run: |
wget https://github.com/adamziel/wxr-normalize/raw/trunk/preprocess-wxr.phar

# TODO: Go by file paths listed under importWxr in blueprint.json
- name: Validate file contents
id: validate_files
run: |
FILES=$(git diff --name-only origin/trunk | grep -E '\.(wxr|xml)$')
if [ -z "$FILES" ]; then
echo "No newly added WXR or XML files to check."
exit 1
fi
for FILE in $FILES; do
CONTENT=$(cat $FILE)
if [[ "$CONTENT" != *"<content:encoded>"* ]]; then
echo "File $FILE does not contain '<content:encoded>', skipping."
continue
fi
if [[ "$CONTENT" == *"githubusercontent.com"* ]]; then
echo "File $FILE contains 'githubusercontent.com', skipping."
continue
fi

echo "Normalizing $FILE"
ASSETS_DIR=$(dirname $FILE)/wxr-assets
mkdir -p $ASSETS_DIR
php preprocess-wxr.phar \
--wxr=$FILE \
--downloads-path=$ASSETS_DIR \
--new-assets-prefix=https://raw.githubusercontent.com/wordpress/blueprints/${{ github.head_ref }}/$ASSETS_DIR \
> /tmp/wxr.swap
if [ -s /tmp/wxr.swap ]; then
mv /tmp/wxr.swap $FILE
else
echo "/tmp/wxr.swap seems empty"
cat /tmp/wxr.swap
fi
done

- name: Check for uncommitted changes
id: changes
run: |
rm preprocess-wxr.phar*
if [ -z "$(git status --porcelain)" ]; then
echo "No changes"
echo 'CHANGES=0' >> $GITHUB_OUTPUT
else
echo "Changes detected"
echo 'CHANGES=1' >> $GITHUB_OUTPUT
fi
- name: Push rebuilt WordPress to GitHub
if: steps.changes.outputs.CHANGES == '1'
run: |
git config --global user.name "deployment_bot"
git config --global user.email "[email protected]"
git add -A
git commit -a -m "Reindex and reformat Blueprints"
git pull --rebase
if [ $? -eq 0 ]; then
git push [email protected]:${{ github.repository }}.git --follow-tags
fi;
27 changes: 0 additions & 27 deletions .github/workflows/has-valid-blueprint-json.yml

This file was deleted.

11 changes: 11 additions & 0 deletions blueprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [ "akismet", "gutenberg" ],
"themes": [ "twentynineteen" ],
"settings": {
"blogname": "My Custom Site",
"blogdescription": "Just another WordPress site"
},
"constants": {
"WP_DEBUG": true
}
}
33 changes: 33 additions & 0 deletions blueprints/stylish-press-clone/blueprint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://playground.wordpress.net/blueprint-schema.json",
"meta": {
"title": "Stylish Press",
"description": "A Woo store with custom theme, content, and products.",
"author": "adamziel",
"categories": ["Woocommerce", "Site"]
},
"landingPage": "/shop",
"preferredVersions": {
"php": "8.3",
"wp": "latest"
},
"features": {
"networking": true
},
"steps": [
{
"step": "importWxr",
"file": {
"resource": "url",
"url": "https://raw.githubusercontent.com/wordpress/blueprints/stylish-press/blueprints/stylish-press-clone/woo-products.wxr"
}
},
{
"step": "importWxr",
"file": {
"resource": "url",
"url": "https://raw.githubusercontent.com/wordpress/blueprints/stylish-press/blueprints/stylish-press-clone/site-content.wxr"
}
}
]
}
Loading
Loading