Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .distignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Files and folders that never ship in the customer zip.
# Read by bin/build-release.sh (rsync --exclude-from). Mirrors gruntfile.js copy:build;
# change both together.
# Read by bin/build-release.sh (rsync --exclude-from), the only zip builder.

# VCS / CI / editor
/.git
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/wporg-folder-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: WordPress.org folder lock

# The plugin zip folder must equal the WordPress.org slug, so the store, GitHub and
# WordPress.org copies install into the same folder. Two folder names for one plugin
# means two copies on a site and a fatal error. Identical file in every Wbcom .org plugin.

on:
push:
pull_request:

permissions:
contents: read

jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Zip folder equals the WordPress.org slug
run: |
slug=$(sed -nE 's/^slug="?([a-z0-9-]+)"?.*/\1/p' bin/build-release.sh | head -1)
main=$(grep -lE '^[[:space:]]*\*?[[:space:]]*Plugin Name:' ./*.php | head -1)
main=${main#./}
if [ -z "$slug" ] || [ -z "$main" ]; then
echo "::error::bin/build-release.sh needs a 'slug=' line and the repo root a main plugin file"; exit 1
fi
code=$(curl -s -o /dev/null -w '%{http_code}' "https://plugins.svn.wordpress.org/$slug/trunk/$main")
if [ "$code" != 200 ]; then
echo "::error::slug=$slug is not the WordPress.org folder for $main (HTTP $code). Set slug= in bin/build-release.sh to the WordPress.org slug."; exit 1
fi
if ! grep -q 'WordPress.org folder lock' bin/build-release.sh; then
echo "::error::bin/build-release.sh is missing the standard WordPress.org folder lock block"; exit 1
fi
echo "OK: zip folder '$slug' matches WordPress.org ($main)"
24 changes: 20 additions & 4 deletions bin/build-release.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# Build the customer zip: dist/buddypress-activity-link-preview-<version>.zip
# Build the customer zip: dist/activity-link-preview-for-buddypress-<version>.zip (folder = WordPress.org slug)
#
# Usage: bash bin/build-release.sh [--allow-dirty]
#
Expand All @@ -12,8 +12,10 @@
# Exit codes: 1 generic, 2 dirty tree, 3 version mismatch, 4 zip leaks dev files, 5 docs lint.
set -euo pipefail

SLUG="buddypress-activity-link-preview" # zip folder name (matches the released zips)
slug=activity-link-preview-for-buddypress # WordPress.org slug = zip folder. Locked by CI (wporg-folder-lock.yml).
SLUG="$slug"
MAIN="bp-activity-link-preview.php"
main="$MAIN"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DIST_DIR="${ROOT}/dist"
STAGE_DIR="${DIST_DIR}/${SLUG}"
Expand Down Expand Up @@ -66,8 +68,22 @@ ZIP_PATH="${DIST_DIR}/${SLUG}-${VERSION}.zip"
rm -rf "$STAGE_DIR" "$ZIP_PATH"
mkdir -p "$STAGE_DIR"
rsync -a --exclude-from="${ROOT}/.distignore" ./ "${STAGE_DIR}/"
( cd "$DIST_DIR" && zip -rqX "$ZIP_PATH" "${SLUG}/" )
# Deflate every entry: a PHP file stored uncompressed trips the store's upload firewall.
( cd "$DIST_DIR" && python3 -I -c 'import os,sys,zipfile
out,top=sys.argv[1],sys.argv[2]
with zipfile.ZipFile(out,"w",zipfile.ZIP_DEFLATED,compresslevel=9) as z:
for r,d,f in os.walk(top):
d.sort()
for n in sorted(f): z.write(os.path.join(r,n))' "$ZIP_PATH" "$SLUG" )
rm -rf "$STAGE_DIR"
zip="$ZIP_PATH"
# --- WordPress.org folder lock (Wbcom standard - do not edit) ----------------------
entries=$(unzip -Z1 "$zip") # read the whole list once: no early-exit pipe, safe under pipefail
top=${entries%%/*}
[ "$top" = "$slug" ] || { echo "Zip folder '$top' is not the WordPress.org slug '$slug'"; exit 1; }
grep -qx "$slug/$main" <<<"$entries" || { echo "Main file $slug/$main missing from zip"; exit 1; }
[ "$(LC_ALL=C grep -a -c '<?php' "$zip" || true)" = 0 ] || { echo "Zip has plain-text PHP (upload firewall)"; exit 1; }
# -----------------------------------------------------------------------------------

# --- 5. Verify the zip -----------------------------------------------------------
# Listing captured once: piping unzip into `grep -q` under pipefail fails on SIGPIPE.
Expand All @@ -78,7 +94,7 @@ if [ -n "$LEAKS" ]; then
echo "$LEAKS" >&2
exit 4
fi
for required in "$MAIN" readme.txt "languages/${SLUG}.pot" assets/js/bp-activity-link-preview.js assets/css/bp-activity-link-preview.css; do
for required in "$MAIN" readme.txt languages/buddypress-activity-link-preview.pot assets/js/bp-activity-link-preview.js assets/css/bp-activity-link-preview.css; do
printf '%s\n' "$LISTING" | grep -qx "${SLUG}/${required}" || { echo "FAIL: zip is missing ${required}" >&2; exit 4; }
done

Expand Down
Loading
Loading