ci: improve release process, clean up and re-org repo, add automated minification (#143)

* ci: update scripts

* release 2.7.1

* remove tracked stylesheets

* docs: revert stable tag to 2.7.0

* chore: move Plugin source into own dir

* docs: delete info texts

These can now be found in the [project wiki][wiki].

[wiki]: https://github.com/markcheret/footnotes/wiki

* docs: tweak contributing guide

* ci: reflect new directory structure

* chore: update gitignore

* chore: reflect new dir structure

* docs: update documentation

* build(linting): add Husky hooks, Markdown linting, lint all MD files

* fix pre-push command

* fix pre-push command

* build: add stylesheet, JS minification

* ci: add linting steps

* ci: comment out CSS linting step (that's going to be a whole *thing*)

* ci: minify all JS files

* ci: call correct JS file

* chore: lint

* ci: fix PHP linting commands

* chore: increment version constant string

* ci: concat AMP stylesheets

* ci: improve build scripts

* chore: add assets dir
This commit is contained in:
Ben Goldsworthy 2021-04-25 09:28:02 +01:00 committed by GitHub
parent e780d817c1
commit 6a1117be15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
183 changed files with 9761 additions and 2941 deletions

View file

@ -14,70 +14,38 @@ echo "Running $(dirname "$0")/build-stylesheets.sh"
if [[ $1 == "-c" ]]; then
echo "Concatenating files and placing in \`css/tmp/\`..."
echo "Concatenating files and placing in \`tmp/css/\`..."
mkdir -p ./css/tmp
cat ./css/dev-common.css > ./css/tmp/footnotes-nottbrpl0.css
cat ./css/dev-{common,layout-reference-container}.css > ./css/tmp/footnotes-nottbrpl1.css
cat ./css/dev-{common,layout-entry-content}.css > ./css/tmp/footnotes-nottbrpl2.css
cat ./css/dev-{common,layout-main-content}.css > ./css/tmp/footnotes-nottbrpl3.css
cat ./css/dev-{common,tooltips}.css > ./css/tmp/footnotes-jqttbrpl0.css
cat ./css/dev-{common,tooltips,layout-reference-container}.css > ./css/tmp/footnotes-jqttbrpl1.css
cat ./css/dev-{common,tooltips,layout-entry-content}.css > ./css/tmp/footnotes-jqttbrpl2.css
cat ./css/dev-{common,tooltips,layout-main-content}.css > ./css/tmp/footnotes-jqttbrpl3.css
cat ./css/dev-{common,tooltips,tooltips-alternative}.css > ./css/tmp/footnotes-alttbrpl0.css
cat ./css/dev-{common,tooltips,tooltips-alternative,layout-reference-container}.css > ./css/tmp/footnotes-alttbrpl1.css
cat ./css/dev-{common,tooltips,tooltips-alternative,layout-entry-content}.css > ./css/tmp/footnotes-alttbrpl2.css
cat ./css/dev-{common,tooltips,tooltips-alternative,layout-main-content}.css > ./css/tmp/footnotes-alttbrpl3.css
cat ./css/settings.css > ./css/tmp/settings.css
mkdir -p ./tmp/css
cat ./src/css/dev-common.css > ./tmp/css/footnotes-nottbrpl0.css
cat ./src/css/dev-{common,layout-reference-container}.css > ./tmp/css/footnotes-nottbrpl1.css
cat ./src/css/dev-{common,layout-entry-content}.css > ./tmp/css/footnotes-nottbrpl2.css
cat ./src/css/dev-{common,layout-main-content}.css > ./tmp/css/footnotes-nottbrpl3.css
cat ./src/css/dev-{common,tooltips}.css > ./tmp/css/footnotes-jqttbrpl0.css
cat ./src/css/dev-{common,tooltips,layout-reference-container}.css > ./tmp/css/footnotes-jqttbrpl1.css
cat ./src/css/dev-{common,tooltips,layout-entry-content}.css > ./tmp/css/footnotes-jqttbrpl2.css
cat ./src/css/dev-{common,tooltips,layout-main-content}.css > ./tmp/css/footnotes-jqttbrpl3.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative}.css > ./tmp/css/footnotes-alttbrpl0.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-reference-container}.css > ./tmp/css/footnotes-alttbrpl1.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-entry-content}.css > ./tmp/css/footnotes-alttbrpl2.css
cat ./src/css/dev-{common,tooltips,tooltips-alternative,layout-main-content}.css > ./tmp/css/footnotes-alttbrpl3.css
cat ./src/css/dev-{common,tooltips,amp-tooltips}.css > ./tmp/css/footnotes-amptbrpl0.css
cat ./src/css/dev-{common,tooltips,amp-tooltips,layout-reference-container}.css > ./tmp/css/footnotes-amptbrpl1.css
cat ./src/css/dev-{common,tooltips,amp-tooltips,layout-entry-content}.css > ./tmp/css/footnotes-amptbrpl2.css
cat ./src/css/dev-{common,tooltips,amp-tooltips,layout-main-content}.css > ./tmp/css/footnotes-amptbrpl3.css
cat ./src/css/settings.css > ./tmp/css/settings.css
echo "Stylesheet concatenation complete."
exit 0
elif [[ $1 == "-m" ]]; then
# TODO: this should automatically minifiy all files, outputting into `.min.css`
# files and deleting the original concatenated `.css` files in `css/tmp/`.
# Once that's done, we can change the `rm -r` command in the deploy step to
# `rmdir`, which will throw us an error if we have any minified files that
# haven't been moved over to `dist/css/` for whatever reason. As it currently
# stands, we have no error checking in place.
echo "Please minify the stylesheets in \`css/tmp/\`, saving them in the same location with the \`.min.css\` file extension."
read -p "Are you ready to continue? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
exit 0
elif [[ $1 == "-d" ]]; then
# NOTE: I've temporarily replaced the `mv` command
# with `cp` and disabled the `rm` command, so the minified
# files won't be removed from the source directory.
echo "Deploying minified stylesheets to \`dist/css/\`..."
mkdir -p ./dist/css
for f in ./css/tmp/*.min.css; do
filename=$(basename $f .css)
cp $f ./dist/css
#mv $f ./dist/css
echo -e '\t' $filename".css moved."
done
# NB: We currently distribute both the minified + concatenated and the
# unminified + unconcatenated stylesheets with the Plugin.
echo "Deploying development stylesheets to \`dist/css/\`..."
for f in ./css/dev-*.css; do
filename=$(basename $f .css)
cp $f ./dist/css
#mv $f ./dist/css
echo -e '\t' $filename".css moved."
done
#echo "Deleting temporary files..."
#rm -r ./css/tmp
echo "All stylesheets added to build."
exit 0
else
echo -e "Concatenates, minifies (TODO) and deploys stylesheets for distribution.\n"
echo -e "Concatenates stylesheets ready for distribution.\n"
echo -e "12 unified style sheets are concatenated out of these files:\n"
echo "\`dev-common.css\`"
echo "\`dev-tooltips.css\`"
@ -86,8 +54,6 @@ else
echo "\`dev-layout-entry-content.css\`"
echo -e "\`dev-layout-main-content.css\`\n"
echo "Command: \`-c\`: Concatenate \`dev-*\` CSS files into temporary directory."
echo "Command: \`-m\`: Minify files (TODO)."
echo "Command: \`-d\`: Deploy minified files to \`dist/css/\` and remove temporary files."
echo "No command, \"--help\", or anything else: Output this help section."
fi

View file

@ -4,17 +4,17 @@ echo "Building Plugin..."
# Moves everything including the style sheets over to `dist/`
echo "Copying directories..."
rm -r dist/
rm -rf dist/
mkdir dist
cp -r -t dist class/ css/ js/ languages/ templates/
cp -r -t dist src/{class,languages,templates}/
# Among the images, only 2 out of 3 are distributed.
echo "Copying the needed images..."
mkdir -p dist/img
cp -t dist/img img/fn-wysiwyg.png
cp -t dist/img src/img/fn-wysiwyg.png
echo "Copying files..."
cp -t dist license.txt readme.txt includes.php wpml-config.xml SECURITY.md
cp -t dist ./{SECURITY.md,CHANGELOG.md,wpml-config.xml} src/{license.txt,readme.txt,includes.php}
echo "Setting production flag..."
sed "s/'PRODUCTION_ENV', false/'PRODUCTION_ENV', true/g" footnotes.php > dist/footnotes.php
sed "s/'PRODUCTION_ENV', false/'PRODUCTION_ENV', true/g" src/footnotes.php > dist/footnotes.php
echo "Production flag set."
# TODO: once automatic minification is implemented, this should handle that.
@ -23,13 +23,13 @@ echo "Production flag set."
echo "Building stylesheets..."
./_tools/build-stylesheets.sh -c
if [ $? != 0 ]; then echo "Concatenation failed!"; exit 1; fi
if [[ $1 != "-y" ]]; then
./_tools/build-stylesheets.sh -m
if [ $? != 0 ]; then echo "Minification failed!"; exit 1; fi
fi
./_tools/build-stylesheets.sh -d
if [ $? != 0 ]; then echo "Deployment failed!"; exit 1; fi
echo "Stylesheet build complete."
echo "Minifying CSS and JS..."
mkdir -p dist/{css,js}
npm run minify
if [ $? != 0 ]; then echo "Minification failed!"; exit 1; fi
echo "Minification complete."
echo "Build complete."
exit 0

View file

@ -27,29 +27,30 @@ if [[ $1 == "-c" ]]; then
read -p "You have passed the \`commit\` flag (\`-c\`). Did you mean to do this? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
fi
# NB: To run on a branch other than `main`, uncomment this line:
#if false; then
# Unless forced to, the script will only run on the `main` branch.
if [[ $1 != "-f" ]]; then
# Step 1: Ensure the local copy has checked out the `main` branch
# Step 1: Ensure the local copy has checked out the `main` branch
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
echo "ERR: You are not on the \`main\` branch, please check it out and re-run this command."
exit 1
else
echo "- \`main\` branch is checked out."
fi
# Step 2: Ensure local copy of `main` is up-to-date with remote
if [[ "$(git status | grep -c 'Your branch is up to date')" != 1 ]]; then
echo "ERR: Your local copy is not up-to-date with the remote, please update it and re-run this command."
exit 1
else
echo "- Local copy of \`main\` is up-to-date with remote."
fi
if [[ "$(git rev-parse --abbrev-ref HEAD)" != "main" ]]; then
echo "ERR: You are not on the \`main\` branch, please check it out and re-run this command."
exit 1
else
echo "- \`main\` branch is checked out."
fi
# Step 2: Ensure local copy of `main` is up-to-date with remote
if [[ "$(git status | grep -c 'Your branch is up to date')" != 1 ]]; then
echo "ERR: Your local copy is not up-to-date with the remote, please update it and re-run this command."
exit 1
else
echo "- Local copy of \`main\` is up-to-date with remote."
fi
# NB: To run on a branch other than `main`, uncomment this line:
#fi
rm -rf ./{dist,tmp,svn-tmp}
# Step 3: Check versioning
@ -62,26 +63,26 @@ fi
echo "- Checking versions..."
STABLE_TAG="$(grep "Stable Tag:" readme.txt)"
ROOT_HEADER_VERSION="$(grep " Version:" footnotes.php | grep -Po " Version: \d+\.\d+(\.\d+)?[a-z]?$")"
JS_VERSION="$(grep "version :" js/wysiwyg-editor.js)"
STABLE_TAG="$(grep "Stable Tag:" src/readme.txt)"
ROOT_HEADER_VERSION="$(grep " Version:" src/footnotes.php | grep -Po " Version: \d+\.\d+(\.\d+)?[a-z]?$")"
JS_VERSION="$(grep "version :" src/js/wysiwyg-editor.js)"
# Step 3(b): Check that all version declarations exists
if [[ -z $STABLE_TAG ]]; then
echo "ERR: No 'Stable Tag' field found in \`readme.txt\`!"
echo "ERR: No 'Stable Tag' field found in \`src/readme.txt\`!"
exit 1
else echo "- 'Stable Tag' field set in \`readme.txt\`."
else echo "- 'Stable Tag' field set in \`src/readme.txt\`."
fi
if [[ -z $ROOT_HEADER_VERSION ]]; then
echo "ERR: No 'Version' field found in \`footnotes.php\` file header!"
echo "ERR: No 'Version' field found in \`src/footnotes.php\` file header!"
exit 1
else echo "- 'Version' field set in \`footnotes.php\` file header."
else echo "- 'Version' field set in \`src/footnotes.php\` file header."
fi
if [[ -z $JS_VERSION ]]; then
echo "ERR: No \`version\` variable found in \`js/wysiwyg-editor.js\`!"
echo "ERR: No \`version\` variable found in \`src/js/wysiwyg-editor.js\`!"
exit 1
else echo "- \`version\` variable set in \`js/wysiwyg-editor.js\`."
else echo "- \`version\` variable set in \`src/js/wysiwyg-editor.js\`."
fi
# Step 3(c)(1): Check that all development versions match
@ -153,7 +154,7 @@ fi
# Step 3(g): Check that the changelog is up-to-date
CHANGELOG_LATEST="$(awk -e '/== Changelog ==/,/= [0-9]+\.[0-9]+(\.[0-9]+)? =/' readme.txt | grep -Po '\d+\.\d+(\.\d+)?')"
CHANGELOG_LATEST="$(awk -e '/== Changelog ==/,/= [0-9]+\.[0-9]+(\.[0-9]+)? =/' src/readme.txt | grep -Po '\d+\.\d+(\.\d+)?')"
if [[ $CHANGELOG_LATEST != $DEVELOPMENT_VERSION ]]; then
echo "ERR: Changelog is not up-to-date!"
echo "Current version is $DEVELOPMENT_VERSION"
@ -176,14 +177,16 @@ echo -e "- Build complete.\n"
echo "- Setting pre-release version flags..."
PRERELEASE_VERSION=$DEVELOPMENT_VERSION'p'
sed -i "s/$JS_VERSION/version : \"$PRERELEASE_VERSION\"/g" dist/js/wysiwyg-editor.js
sed -i "s/$JS_VERSION/$PRERELEASE_VERSION/g" dist/js/wysiwyg-editor.min.js
echo "- Pre-release flags set."
# Step 6: Tag the release
echo "- Tagging release..."
git tag -a $DEVELOPMENT_VERSION -m "Pre-release of version $DEVELOPMENT_VERSION"
git push --tags
if [ $? != 0 ]; then echo "Tag already exists!"; exit 1; fi
git push --tags --no-verify
if [ $? != 0 ]; then echo "Push failed (tag probably exists on remote)!"; exit 1; fi
echo "- Release tagged."
# Step 7: Push release to SVN repo.
@ -195,21 +198,22 @@ echo "For the time being, this part of the process shall remain (mostly) manual.
read -p "Are you ready to continue? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
echo "Creating local copy of SVN repo..."
svn checkout https://plugins.svn.wordpress.org/footnotes tmp --depth immediates
svn update --quiet tmp/trunk --set-depth infinity
svn update --quiet tmp/tags/$PRERELEASE_VERSION --set-depth infinity
svn checkout https://plugins.svn.wordpress.org/footnotes svn-tmp --depth immediates
svn update --quiet svn-tmp/trunk --set-depth infinity
svn update --quiet svn-tmp/tags/$PRERELEASE_VERSION --set-depth infinity
echo -e "Local copy created.\n"
# Step 7(b): Update `trunk/`
echo -e "Copying files from \`dist/\` to SVN \`trunk/\`...\n"
rsync -avhic dist/ tmp/trunk/ --delete | grep -v "^\."
read -p "Does the above list of changes look correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
rsync -avhic dist/ svn-tmp/trunk/ --delete | grep -v "^\."
rsync -avhic assets/ svn-tmp/assets/ --delete | grep -v "^\."
read -p "Does the above list of changes (additions and deletions ONLY) look correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
echo -e "Copying complete.\n"
# Step 7(c): Set a release message
echo "Getting commit message from changelog..."
CHANGELOG_MESSAGE="$(awk -e "/= $DEVELOPMENT_VERSION =/,/= $STABLE_VERSION =/" readme.txt | grep '^-')"
CHANGELOG_MESSAGE="$(awk -e "/= $DEVELOPMENT_VERSION =/,/= $STABLE_VERSION =/" dist/readme.txt | grep '^-')"
echo -e "The changelog message for this version is:\n"
echo -e "$CHANGELOG_MESSAGE\n"
read -p "Is this correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
@ -226,23 +230,22 @@ echo "Stable version:"
echo -e '\t' $STABLE_VERSION '\n'
echo -e "Commit message:\n"
echo -e "$CHANGELOG_MESSAGE" '\n'
svn status | grep '^\!' | sed 's/! *//' | xargs -I% svn rm %
echo -e "Changes made to local \`trunk/\`:\n"
svn stat tmp/trunk/
svn stat svn-tmp/trunk/ | grep '^\!' | sed 's/! *//' | xargs -I% svn rm % >/dev/null
echo -e "Changes made to local \`trunk/\` (should only be 'M', 'D' and '?'):\n"
svn stat svn-tmp/trunk/
echo ""
echo -e "\`readme.txt\` header:\n"
head tmp/trunk/readme.txt
head svn-tmp/trunk/readme.txt
echo ""
read -p "Is this all correct? (Y/N): " CONFIRM && [[ $CONFIRM == [yY] || $CONFIRM == [yY][eE][sS] ]] || exit 1
# Step 7(d): Push to remote `trunk/` (provided the flag is set)
if [[ $1 == "-c" ]]; then
cd tmp && svn ci -m "$CHANGELOG_MESSAGE"
cd ..
cd svn-tmp && svn ci -m "$CHANGELOG_MESSAGE" && cd ..
else echo "- Commit flag not set, skipping commit step."
fi
# Step 8: Cleanup
#rm -rf {dist/,tmp/}
#rm -rf {dist/,svn-tmp/}