Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·59 lines (52 loc) · 2.2 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·59 lines (52 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env bash
#
# Build the wordpress.org-ready ZIP for the CaptchaLa WP plugin.
# Delegates to the shared PHP build script which:
# 1. composer install --no-dev --optimize-autoloader
# 2. zips into release/wordpress-<version>.zip with the plugin folder
# flattened to `captchala/` (no version-suffixed wrapper directory).
#
# Usage:
# ./build.sh # uses version from captchala.php
# VERSION=1.0.1 ./build.sh
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
rm -rf release
mkdir -p release
# Fresh vendor — path-repo'd captchala-php SDK won't auto-refresh on src
# change unless we force-reinstall.
rm -rf vendor/captchala
if [[ -f composer.json ]] && command -v composer >/dev/null 2>&1; then
composer install --no-dev --optimize-autoloader --quiet
fi
VERSION="${VERSION:-$(grep -oE "Version:[[:space:]]+[0-9]+\.[0-9]+\.[0-9]+" captchala.php | awk '{print $2}')}"
STAGE="$(mktemp -d)"
mkdir -p "${STAGE}/captchala"
# wordpress.org's plugin scanner rejects unknown files in the root, and we
# don't want to leak dev tooling into the public download. Keep only what
# the plugin actually needs at runtime.
#
# composer.json is intentionally KEPT: the plugin ships a populated vendor/
# directory and the wp.org checker flags `vendor without composer.json`.
# composer.lock is also kept so the dependency tree is auditable.
tar \
--exclude='./release' \
--exclude='./.git' \
--exclude='./tests' \
--exclude='./node_modules' \
--exclude='./*.zip' \
--exclude='./build.sh' \
--exclude='./SUBMIT.md' \
--exclude='./INTEGRATIONS.md' \
--exclude='./assets' \
-cf - . | ( cd "${STAGE}/captchala" && tar -xf - )
# wp.org plugin checker bans hidden files anywhere in the plugin tree
# (.gitignore, .editorconfig, .github/, .DS_Store, …). Strip them from
# every level — including ones that snuck in via vendor/ — so the
# submission passes the hidden_files rule.
find "${STAGE}/captchala" -name '.*' -not -name '.' -not -name '..' -prune -exec rm -rf {} +
( cd "${STAGE}" && zip -rq "${SCRIPT_DIR}/release/wordpress-${VERSION}.zip" captchala )
rm -rf "${STAGE}"
echo "[captchala-wp] Built release/wordpress-${VERSION}.zip"