-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (142 loc) · 6.47 KB
/
deploy.yml
File metadata and controls
162 lines (142 loc) · 6.47 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Deploy to WordPress.org
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
dry_run:
description: 'Run in dry-run mode (no actual deployment)'
required: false
type: boolean
default: false
concurrency:
group: wordpress-deploy
cancel-in-progress: false
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout GitHub repo
uses: actions/checkout@v4
- name: Setup SVN
run: |
sudo apt-get update
sudo apt-get install -y subversion rsync
- name: Export GitHub code to a clean folder
run: |
rm -rf /tmp/wordpress-svn
mkdir -p /tmp/wordpress-svn
svn checkout https://plugins.svn.wordpress.org/searchcraft/ /tmp/wordpress-svn
# Sync plugin code to trunk (excluding assets and dev files)
rsync -av --delete \
--exclude='.git' \
--exclude='.github' \
--exclude='vendor/bin' \
--exclude='vendor/dealerdirect' \
--exclude='vendor/phpcsstandards' \
--exclude='vendor/php-stubs' \
--exclude='vendor/squizlabs' \
--exclude='vendor/wp-coding-standards' \
--exclude='tests' \
--exclude='scripts' \
--exclude='.gitignore' \
--exclude='.vscode' \
--exclude='intelephense.json' \
--exclude='local_publish_prep.sh' \
--exclude='assets' \
./ /tmp/wordpress-svn/trunk/
# Sync assets to top-level assets directory (separate from trunk)
if [ -d "assets" ]; then
rsync -av --delete \
assets/ /tmp/wordpress-svn/assets/
echo "✓ Assets synced to SVN assets directory"
fi
- name: Get plugin version
id: get_version
run: |
VERSION=$(grep -i "Version:" searchcraft.php | head -n1 | awk -F: '{print $2}' | tr -d ' ')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Detected plugin version: $VERSION"
- name: Check Stable tag matches version
run: |
STABLE=$(grep -i "Stable tag:" readme.txt | awk -F: '{print $2}' | tr -d ' ')
VERSION=${{ steps.get_version.outputs.version }}
if [ "$STABLE" != "$VERSION" ]; then
echo "Error: Stable tag ($STABLE) does not match plugin version ($VERSION)"
exit 1
fi
echo "✓ Stable tag matches plugin version: $VERSION"
- name: Check if version already exists in SVN
run: |
cd /tmp/wordpress-svn
VERSION=${{ steps.get_version.outputs.version }}
# Check if tags directory exists and if version exists
if svn list tags 2>/dev/null | grep -q "^$VERSION/$"; then
echo "Error: Version $VERSION already exists in WordPress.org SVN"
echo "Please increment the version number before deploying"
exit 1
fi
echo "✓ Version $VERSION is new and ready to deploy"
- name: Commit to WordPress.org SVN
if: ${{ !inputs.dry_run }}
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd /tmp/wordpress-svn
# Add trunk files
svn add --force trunk/* --auto-props --parents --depth infinity
# Add assets files (if directory exists)
if [ -d "assets" ]; then
svn add --force assets/* --auto-props --parents --depth infinity
# Set proper mime types for images
svn propset svn:mime-type image/png assets/*.png 2>/dev/null || true
svn propset svn:mime-type image/jpeg assets/*.jpg 2>/dev/null || true
svn propset svn:mime-type image/gif assets/*.gif 2>/dev/null || true
fi
# Remove deleted files
svn status | grep '^!' | sed 's/^! *//' | xargs -r svn delete
svn commit -m "Deploy version ${{ steps.get_version.outputs.version }}" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive --no-auth-cache
- name: Tag version in WordPress.org SVN
if: ${{ !inputs.dry_run }}
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd /tmp/wordpress-svn
VERSION=${{ steps.get_version.outputs.version }}
svn copy trunk tags/$VERSION
svn commit -m "Tagging version $VERSION" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive --no-auth-cache
- name: Dry run summary
if: ${{ inputs.dry_run }}
run: |
echo "🔍 DRY RUN MODE - No changes were committed to WordPress.org SVN"
echo "Version ${{ steps.get_version.outputs.version }} would have been deployed"
echo "Review the changes in /tmp/wordpress-svn/trunk/ if needed"
- name: Send Discord notification on success
if: ${{ success() && !inputs.dry_run }}
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
if [ -n "$DISCORD_WEBHOOK" ]; then
curl -H "Content-Type: application/json" \
-d "{\"content\": \"✅ **Searchcraft v${{ steps.get_version.outputs.version }}** successfully deployed to WordPress.org\", \"embeds\": [{\"title\": \"Deployment Success\", \"color\": 3066993, \"fields\": [{\"name\": \"Version\", \"value\": \"${{ steps.get_version.outputs.version }}\", \"inline\": true}, {\"name\": \"Repository\", \"value\": \"${{ github.repository }}\", \"inline\": true}]}]}" \
"$DISCORD_WEBHOOK"
fi
- name: Send Discord notification on failure
if: ${{ failure() && !inputs.dry_run }}
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: |
if [ -n "$DISCORD_WEBHOOK" ]; then
curl -H "Content-Type: application/json" \
-d "{\"content\": \"❌ **Searchcraft deployment failed**\", \"embeds\": [{\"title\": \"Deployment Failed\", \"color\": 15158332, \"fields\": [{\"name\": \"Version\", \"value\": \"${{ steps.get_version.outputs.version }}\", \"inline\": true}, {\"name\": \"Repository\", \"value\": \"${{ github.repository }}\", \"inline\": true}, {\"name\": \"Workflow\", \"value\": \"${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\", \"inline\": false}]}]}" \
"$DISCORD_WEBHOOK"
fi