fair-plugin/bin/bundle.sh
Carrie Dils d52ee0fd7b
release: merge release_1.3.0 into development for RC testing (#433)
Signed-off-by: John Blackbourn <john@johnblackbourn.com>
Signed-off-by: Andy Fragen <andy@thefragens.com>
Signed-off-by: Carrie Dils <carriedils@gmail.com>
Signed-off-by: Norcross <andrew.norcross@gmail.com>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Signed-off-by: joedolson <joedolson@users.noreply.github.com>
Signed-off-by: Joe Dolson <design@joedolson.com>
Signed-off-by: Shadi Sharaf <shady@sharaf.me>
Co-authored-by: Chuck Adams <chaz@chaz.works>
Co-authored-by: John Blackbourn <john@johnblackbourn.com>
Co-authored-by: Andy Fragen <andy@thefragens.com>
Co-authored-by: Norcross <andrew.norcross@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: rmccue <21655+rmccue@users.noreply.github.com>
Co-authored-by: joedolson <joedolson@users.noreply.github.com>
Co-authored-by: Joe Dolson <design@joedolson.com>
Co-authored-by: Shady Sharaf <shady@sharaf.me>
Co-authored-by: cdils <3099408+cdils@users.noreply.github.com>
2026-02-10 14:28:10 -06:00

101 lines
3.5 KiB
Bash
Executable file

#!/bin/bash -e
#
# Create our distribution zips.
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Extract a header value from plugin.php
# Usage: get_plugin_header "Header Name"
get_plugin_header() {
sed -n "s/.*$1: \([0-9.]*\).*/\1/p" "$SCRIPT_DIR/../plugin.php"
}
# Prepare the distribution directory.
DIST_DIR="/tmp/fair-dist"
[ -d "$DIST_DIR" ] && rm -rf "$DIST_DIR"
mkdir "$DIST_DIR"
touch /tmp/fair-dist/MD5SUMS
touch /tmp/fair-dist/SHA1SUMS
touch /tmp/fair-dist/SHA256SUMS
touch /tmp/fair-dist/SHA384SUMS
# Auto-detect and hash plugin zip.
PLUGIN_VERSION=$(get_plugin_header "Version")
REPO_NAME=$(basename "$GITHUB_REPOSITORY")
PLUGIN_ZIP="/tmp/${REPO_NAME}-${PLUGIN_VERSION}.zip"
if [ -f "$PLUGIN_ZIP" ]; then
echo "Hashing plugin zip: $PLUGIN_ZIP" >&2
# Change to /tmp so hash files contain just filename, not full path
cd /tmp
md5sum -b "$(basename "$PLUGIN_ZIP")" >> /tmp/fair-dist/MD5SUMS
sha1sum -b "$(basename "$PLUGIN_ZIP")" >> /tmp/fair-dist/SHA1SUMS
sha256sum -b "$(basename "$PLUGIN_ZIP")" >> /tmp/fair-dist/SHA256SUMS
sha384sum -b "$(basename "$PLUGIN_ZIP")" >> /tmp/fair-dist/SHA384SUMS
cd - > /dev/null
fi
# Bundle our plugin first.
[ -d /tmp/fair-temp ] && rm -rf /tmp/fair-temp
mkdir -p /tmp/fair-temp/wordpress/wp-content/plugins/fair-plugin
rsync -a --exclude-from="$SCRIPT_DIR/../.distignore" "$SCRIPT_DIR/../" /tmp/fair-temp/wordpress/wp-content/plugins/fair-plugin
# Extract minimum required WordPress version from plugin header.
REQUIRES_AT_LEAST=$(get_plugin_header "Requires at least")
echo "Plugin requires WordPress $REQUIRES_AT_LEAST or higher" >&2
echo "Fetching WordPress version data" >&2
VERSION_DATA=$(curl -s https://api.wordpress.org/core/version-check/1.7/)
AVAILABLE_VERSIONS=$(echo "$VERSION_DATA" | jq -r '.offers[] | .version')
# For each available version, download WP and add our plugin to the WP zip.
for VERSION in $AVAILABLE_VERSIONS; do
# Skip versions older than minimum required.
if [ "$(printf '%s\n' "$REQUIRES_AT_LEAST" "$VERSION" | sort -V | head -n1)" != "$REQUIRES_AT_LEAST" ]; then
echo "Skipping $VERSION (older than $REQUIRES_AT_LEAST)" >&2
continue
fi
# Skip repeat versions via the API.
if [ -f "$DIST_DIR/wordpress-$VERSION-fair.zip" ]; then
echo "Skipping $VERSION (already bundled)" >&2
continue
fi
echo "Bundling $VERSION..." >&2
# Download the WP zip.
WP_ZIP_URL="https://wordpress.org/wordpress-$VERSION.zip"
WP_ZIP_FILE="/tmp/fair-temp/wordpress-$VERSION.zip"
echo " Downloading $WP_ZIP_URL..." >&2
curl -sSL "$WP_ZIP_URL" -o "$WP_ZIP_FILE"
EXPECTED_HASH=$(curl -sSL "$WP_ZIP_URL.sha1")
# Verify the checksum.
# (sha1 is suboptimal, but it's all we've got.)
echo " Verifying checksum" >&2
echo "$EXPECTED_HASH *$WP_ZIP_FILE" | sha1sum -c --status - || { echo "Checksum verification failed!" >&2; exit 1; }
# Add the plugin into the existing zip.
echo " Adding plugin" >&2
cd /tmp/fair-temp
zip -r /tmp/fair-temp/wordpress-$VERSION.zip wordpress/ >&2
cd - > /dev/null
# Rename altered zip.
mv /tmp/fair-temp/wordpress-$VERSION.zip "$DIST_DIR/wordpress-$VERSION-fair.zip"
# Recalculate hashes.
echo " Calculating hashes" >&2
cd "$DIST_DIR"
md5sum -b "wordpress-$VERSION-fair.zip" >> /tmp/fair-dist/MD5SUMS
sha1sum -b "wordpress-$VERSION-fair.zip" >> /tmp/fair-dist/SHA1SUMS
sha256sum -b "wordpress-$VERSION-fair.zip" >> /tmp/fair-dist/SHA256SUMS
sha384sum -b "wordpress-$VERSION-fair.zip" >> /tmp/fair-dist/SHA384SUMS
cd - > /dev/null
# Output filename.
echo $DIST_DIR/wordpress-$VERSION-fair.zip
done
# Clean up.
rm -rf /tmp/fair-temp