Build and deploy wpssg site to GitHub Pages #31
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy wpssg site to GitHub Pages | |
on: | |
# Runs on pushes targeting the default branch | |
push: | |
branches: [$default-branch] | |
# Allows you to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: read | |
pages: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: "pages" | |
cancel-in-progress: false | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Pages | |
id: pages | |
uses: actions/configure-pages@v5 | |
- name: Prerequisites | |
run: | | |
sudo apt install php-cli php-mysql php-dom mysql-server sqlite3 jq | |
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar | |
- name: Setup WordPress | |
run: | | |
sudo service mysql start | |
sudo mysql -h 127.0.0.1 --user=root --password=root <<< "CREATE USER 'wpssguser'@'127.0.0.1' IDENTIFIED WITH mysql_native_password BY 'wpssgpass'; CREATE DATABASE wpssgdb; GRANT ALL PRIVILEGES ON wpssgdb.* TO 'wpssguser'@'127.0.0.1';" | |
sudo mysql -h 127.0.0.1 --user=wpssguser --password=wpssgpass <<< "SHOW DATABASES" | |
php ./wp-cli.phar core download --locale=en_US #--skip-content --force | |
php ./wp-cli.phar config create --locale=en_US --dbuser=wpssguser --dbpass=wpssgpass --dbname=wpssgdb --dbhost=127.0.0.1 | |
#php ./wp-cli.phar db create | |
php ./wp-cli.phar core install --url=localhost:8080 --title=wpcli --admin_user=wpcli --admin_password=wpcli [email protected] | |
php ./wp-cli.phar option set permalink_structure '/%year%-%monthnum%-%day%-%postname%/' | |
php ./wp-cli.phar theme install --activate https://knd.te-st.ru/kandinsky.zip | |
- name: Setup postmark | |
run: | | |
git clone https://github.com/dirtsimple/postmark | |
#sed -e 's@"league/commonmark-ext-smartpunct": "^1.1",@@' -e 's@"league/commonmark-ext-strikethrough": "^1.0",@@' -e 's@"league/commonmark-ext-table": "^2.1",@@' -e 's@"webuni/commonmark-attributes-extension": "^1.0",@@' -e 's@\^2\.4@*@' -e 's@\^3\.4@*@' -e 's@\^7\.1@*@' -e 's@\^0\.3\.0@*@' -e 's@\^2@*@' -i ./postmark/composer.json | |
#sed -i 's@League\\CommonMark\\Ext\\Table\\TableExtension@dirtsimple\\Postmark\\ShortcodeParser@g' ./postmark/src/Formatter.php | |
#sed -i 's@League\\CommonMark\\Ext\\Strikethrough\\StrikethroughExtension@dirtsimple\\Postmark\\ShortcodeParser@g' ./postmark/src/Formatter.php | |
#sed -i 's@League\\CommonMark\\Ext\\SmartPunct\\SmartPunctExtension@dirtsimple\\Postmark\\ShortcodeParser@g' ./postmark/src/Formatter.php | |
#sed -i 's@Webuni\\CommonMark\\AttributesExtension\\AttributesExtension@dirtsimple\\Postmark\\ShortcodeParser@g' ./postmark/src/Formatter.php | |
#sed -i 's@WP_CLI\\Entity\\RecursiveDataStructureTraverser@WP_CLI\\Traverser\\RecursiveDataStructureTraverser@' ./postmark/src/Option.php | |
php ./wp-cli.phar package install ./postmark | |
#sed -i 's@WP_CLI\\Entity\\RecursiveDataStructureTraverser@WP_CLI\\Traverser\\RecursiveDataStructureTraverser@' ~/.wp-cli/packages/vendor/dirtsimple/imposer/src/Scheduler.php | |
#sed -i 's@WP_CLI\\Entity\\NonExistentKeyException@WP_CLI\\Exception\\NonExistentKeyException@' ~/.wp-cli/packages/vendor/dirtsimple/imposer/src/Scheduler.php | |
php ./wp-cli.phar post delete --force $(php ./wp-cli.phar post list --post_type='post' --format=ids) $(php ./wp-cli.phar post list --post_type='page' --format=ids) | |
php ./wp-cli.phar postmark tree ./_posts/ | |
php ./wp-cli.phar postmark sync index.md about.md | |
echo ListPage && php ./wp-cli.phar post list --post_type=page --field=url | |
echo ListPost && php ./wp-cli.phar post list --post_type=post --field=url | |
mkdir ./exportPOSTMARK/ | |
php ./wp-cli.phar postmark export --dir=./exportPOSTMARK/ $(php ./wp-cli.phar post list --post_type='post' --format=ids) | |
php ./wp-cli.phar export --filename_format=exportWXR.xml | |
php ./wp-cli.phar option list --format=json | jq '.' > exportOPTIONS.json | |
- name: Export to Sqlite | |
run: | | |
git clone https://github.com/mysql2sqlite/mysql2sqlite | |
sudo mysqldump -h 127.0.0.1 --user=wpssguser --password=wpssgpass --skip-extended-insert --no-tablespaces --xml --no-create-info --compact wpssgdb wp_options --result-file=wpssgopts.xml | |
sudo mysqldump -h 127.0.0.1 --user=wpssguser --password=wpssgpass --skip-extended-insert --no-tablespaces --no-data --compact wpssgdb --result-file=wpssgddl.sql | |
sudo mysqldump -h 127.0.0.1 --user=wpssguser --password=wpssgpass --skip-extended-insert --no-tablespaces --no-create-info --compact wpssgdb --result-file=wpssgdata.sql && sed -e "s/\\\'/''/g" -e "s/_binary //g" wpssgdata.sql > wpssgdatasqlite.sql | |
awk -f mysql2sqlite/mysql2sqlite wpssgddl.sql | sed s'/PRAGMA journal_mode = MEMORY/PRAGMA journal_mode = DELETE/' > wpssgddlsqlite.sql | |
sqlite3 wpssgsqlite.db < wpssgddlsqlite.sql | |
sqlite3 wpssgsqlite.db < wpssgdatasqlite.sql | |
- name: Setup wp2static | |
run: | | |
mkdir ./wp-content/plugins/wp2static # $(php wp-cli.phar plugin path)/wp2static | |
curl -L https://github.com/elementor/wp2static/archive/refs/tags/7.2.tar.gz | tar -xzf - -C ./wp-content/plugins/wp2static --strip-components=1 | |
cd ./wp-content/plugins/wp2static | |
curl -o composer.phar https://getcomposer.org/installer | |
php composer.phar update | |
php composer.phar install | |
cd ../../../ | |
php ./wp-cli.phar plugin activate wp2static | |
php ./wp-cli.phar wp2static options set deploymentURL "https://${{github.repository_owner}}.github.io${{steps.pages.outputs.base_path}}/" | |
- name: Run wp2static | |
run: | | |
php ./wp-cli.phar server --host=localhost --port=8080 & | |
sleep 5 | |
php ./wp-cli.phar wp2static detect | |
php ./wp-cli.phar wp2static crawl | |
php ./wp-cli.phar wp2static post_process | |
mv ./wp-content/uploads/wp2static-processed-site _site | |
# wget --recursive --html-extension http://localhost:8080 | |
# wget -P wpssgmirror -nd --mirror --convert-links --adjust-extension --page-requisites --no-parent --restrict-file-names=ascii,windows http://localhost:8080 | |
#wget --recursive --page-requisites --html-extension --convert-links --restrict-file-names=windows --random-wait otso.fr | |
- name: Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
path: | | |
exportPOSTMARK/ | |
exportWXR.xml | |
exportOPTIONS.json | |
wpssgopts.xml | |
wpssgddl.sql | |
wpssgdata.sql | |
wpssgddlsqlite.sql | |
wpssgdatasqlite.sql | |
wpssgsqlite.db | |
_site/ | |
- name: Upload artifact | |
# Automatically uploads an artifact from the './_site' directory by default | |
uses: actions/upload-pages-artifact@v3 | |
deploy: | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 |