-
Notifications
You must be signed in to change notification settings - Fork 1
235 lines (206 loc) · 8.24 KB
/
Copy pathdeploy.yml
File metadata and controls
235 lines (206 loc) · 8.24 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
name: Deploy to WordPress.org
on:
workflow_dispatch:
inputs:
stage:
description: 'Deployment stage'
required: true
default: 'trunk'
type: choice
options:
- trunk
- release
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
jobs:
deploy:
name: Deploy to WordPress.org SVN
runs-on: ubuntu-latest
environment: wordpress-org
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Prepare plugin folder
run: |
mkdir -p dist/chip-for-gravity-forms
git archive HEAD | tar -x -C dist/chip-for-gravity-forms
echo "✅ Plugin folder prepared"
ls -la dist/chip-for-gravity-forms/
- name: Determine stage and version
id: vars
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
STAGE="${{ github.event.inputs.stage }}"
else
STAGE="release"
fi
echo "stage=$STAGE" >> "$GITHUB_OUTPUT"
if [ "$STAGE" = "release" ] && [ "${{ github.event_name }}" = "push" ]; then
VERSION=${GITHUB_REF##*/v}
else
VERSION=$(grep "Version:" chip-for-gravity-forms.php | head -1 | awk '{print $3}')
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "📦 Stage: $STAGE"
echo "📦 Version: $VERSION"
- name: Install SVN
run: sudo apt-get install -y subversion
- name: Revert stable tag for trunk deploy
if: steps.vars.outputs.stage == 'trunk'
run: |
# For trunk testing, keep Stable tag pointing to the version currently
# live on WordPress.org (source of truth from SVN trunk readme.txt).
svn export --force \
--username "${{ secrets.SVN_USERNAME }}" \
--password "${{ secrets.SVN_PASSWORD }}" \
--non-interactive \
"https://plugins.svn.wordpress.org/chip-for-gravity-forms/trunk/readme.txt" \
/tmp/svn-readme.txt >/dev/null 2>&1 || true
if [ -f /tmp/svn-readme.txt ]; then
CURRENT_STABLE=$(grep -m1 "^Stable tag:" /tmp/svn-readme.txt | awk '{print $3}')
fi
if [ -n "${CURRENT_STABLE:-}" ]; then
echo "🧪 Trunk mode: keeping Stable tag at ${CURRENT_STABLE}"
sed -i "s/^Stable tag: .*/Stable tag: ${CURRENT_STABLE}/" dist/chip-for-gravity-forms/readme.txt
grep "^Stable tag:" dist/chip-for-gravity-forms/readme.txt
rm -f /tmp/svn-readme.txt
else
echo "⚠️ Could not read current stable tag from SVN; leaving as-is"
fi
- name: Sparse-checkout SVN (trunk + assets only)
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
# Checkout only the repo root skeleton (no tag history)
svn checkout --depth=empty \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive \
https://plugins.svn.wordpress.org/chip-for-gravity-forms/ \
svn-repo
cd svn-repo
svn update --set-depth=infinity trunk
svn update --set-depth=infinity assets
cd ..
echo "✅ Sparse-checkout complete"
- name: Update trunk
run: |
# Clear existing files in trunk (preserve .svn metadata)
cd svn-repo/trunk
find . -type f -not -path './.svn/*' -delete 2>/dev/null || true
find . -mindepth 1 -type d -not -path './.svn*' -empty -delete 2>/dev/null || true
cd ../..
# Copy new files into trunk
rsync -av \
--exclude='.git*' \
--exclude='.github' \
--exclude='ci-build' \
--exclude='dist' \
--exclude='node_modules' \
--exclude='.wordpress-org' \
dist/chip-for-gravity-forms/ \
svn-repo/trunk/
- name: Sync WordPress.org assets
run: |
if [ -d ".wordpress-org" ]; then
echo "📁 Syncing WordPress.org directory assets..."
cd svn-repo/assets
find . -type f -not -path './.svn/*' -delete 2>/dev/null || true
cd ../..
rsync -av .wordpress-org/ svn-repo/assets/
else
echo "ℹ️ No .wordpress-org directory found; skipping assets sync."
fi
- name: Commit trunk only (test stage)
if: steps.vars.outputs.stage == 'trunk'
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
cd svn-repo
svn add --force . > /dev/null 2>&1 || true
svn status | grep '^!' | sed 's/^! *//' | while read -r f; do
svn delete "$f" --force
done
svn commit \
-m "Update trunk to ${{ steps.vars.outputs.version }} for testing" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive
echo "✅ Deployed trunk for testing. Stable tag unchanged."
- name: Create SVN tag and release
if: steps.vars.outputs.stage == 'release'
env:
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
run: |
VERSION="${{ steps.vars.outputs.version }}"
cd svn-repo
# Add new files
svn add --force . > /dev/null 2>&1 || true
# Remove deleted files
svn status | grep '^!' | sed 's/^! *//' | while read -r f; do
svn delete "$f" --force
done
# Check for duplicate tag
if svn ls \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive \
"https://plugins.svn.wordpress.org/chip-for-gravity-forms/tags/$VERSION" >/dev/null 2>&1; then
echo "❌ Tag $VERSION already exists in SVN. Aborting."
exit 1
fi
# Commit trunk + assets first, then create tag from the new HEAD
svn commit \
-m "Release $VERSION" \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive
svn cp \
--username "$SVN_USERNAME" \
--password "$SVN_PASSWORD" \
--non-interactive \
"https://plugins.svn.wordpress.org/chip-for-gravity-forms/trunk" \
"https://plugins.svn.wordpress.org/chip-for-gravity-forms/tags/$VERSION" \
-m "Create tag $VERSION"
echo "🏷️ Created tag $VERSION"
echo "✅ Released $VERSION to WordPress.org"
- name: Create release zip
if: steps.vars.outputs.stage == 'release'
run: |
cd dist
zip -r ../chip-for-gravity-forms.zip chip-for-gravity-forms
cd ..
echo "✅ Created release zip"
- name: Extract changelog for release notes
if: steps.vars.outputs.stage == 'release'
run: |
VERSION="${{ steps.vars.outputs.version }}"
# Extract the latest changelog entry from changelog.txt (portable awk)
awk '/^== Changelog ==/ { getline; getline; print; while (getline > 0 && NF > 0) print }' changelog.txt > release_notes.md
echo "📝 Release notes from changelog:"
cat release_notes.md
- name: Create or update GitHub release
if: steps.vars.outputs.stage == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION="${{ steps.vars.outputs.version }}"
TAG="v${VERSION}"
if gh release view "$TAG" > /dev/null 2>&1; then
gh release edit "$TAG" --notes-file release_notes.md
echo "✅ Updated existing release"
else
gh release create "$TAG" --title "v${VERSION}" --notes-file release_notes.md
echo "✅ Created new release"
fi
- name: Upload release asset to GitHub
if: steps.vars.outputs.stage == 'release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="v${{ steps.vars.outputs.version }}"
gh release upload "$TAG" chip-for-gravity-forms.zip --clobber || true