-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsync-package-version.sh
More file actions
executable file
·59 lines (46 loc) · 2.04 KB
/
Copy pathsync-package-version.sh
File metadata and controls
executable file
·59 lines (46 loc) · 2.04 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
#!/bin/bash
# Exit on any error
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get the version from package.json
VERSION=$(node -p "require('./package.json').version")
if [ -z "$VERSION" ]; then
echo -e "${RED}Error: Could not read version from package.json${NC}"
exit 1
fi
echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}"
# Update composer.json
if [ -f "composer.json" ]; then
echo "Updating composer.json..."
# Use sed to preserve original formatting (tabs/spaces)
sed -i.bak -E "s/(\"version\":[[:space:]]*\")[^\"]*(\",?)/\1$VERSION\2/" composer.json && rm composer.json.bak
echo -e "${GREEN}✓ Updated composer.json${NC}"
else
echo -e "${YELLOW}⚠ composer.json not found${NC}"
fi
# Update readme.txt (WordPress style)
if [ -f "readme.txt" ]; then
echo "Updating readme.txt..."
sed -i.bak -E "s/(Stable tag:|Version:)[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+/\1 $VERSION/g" readme.txt && rm readme.txt.bak
echo -e "${GREEN}✓ Updated readme.txt${NC}"
else
echo -e "${YELLOW}⚠ readme.txt not found${NC}"
fi
# Update wpgraphql-webhooks.php
PLUGIN_FILE="wpgraphql-webhooks.php"
if [ -f "$PLUGIN_FILE" ]; then
echo "Updating main plugin file: $PLUGIN_FILE..."
# Update WordPress plugin header version (handles beta versions)
sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak"
# Update WPGRAPHQL_WEBHOOKS_VERSION define statement
sed -i.bak -E "s/(define\([[:space:]]*['\"]WPGRAPHQL_WEBHOOKS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak"
echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}"
else
echo -e "${YELLOW}⚠ $PLUGIN_FILE not found${NC}"
fi
echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}"
echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"``