-
Notifications
You must be signed in to change notification settings - Fork 0
417 lines (352 loc) · 16.5 KB
/
Copy pathrelease.yml
File metadata and controls
417 lines (352 loc) · 16.5 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
name: 🚀 Release Plugin
on:
push:
tags:
- "v*"
jobs:
# ============================================================================
# BUILD PLUGIN PACKAGE
# ============================================================================
build:
name: Build Plugin Package
runs-on: ubuntu-latest
outputs:
plugin_slug: ${{ steps.info.outputs.slug }}
plugin_name: ${{ steps.info.outputs.name }}
plugin_version: ${{ steps.info.outputs.version }}
package_name: ${{ steps.package.outputs.name }}
changelog_content: ${{ steps.changelog.outputs.content }}
steps:
- name: Checkout plugin source
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Extract plugin information
id: info
run: |
# Extract tag version without 'v' prefix
TAG_VERSION="${GITHUB_REF_NAME#v}"
# Auto-detect plugin slug and file from repository name
REPO_NAME="${GITHUB_REPOSITORY##*/}"
PLUGIN_SLUG="${REPO_NAME}"
PLUGIN_FILE="${PLUGIN_SLUG}.php"
# Verify plugin file exists, otherwise find it
if [ ! -f "$PLUGIN_FILE" ]; then
PLUGIN_FILE=$(find . -maxdepth 1 -name "*.php" -exec grep -l "Plugin Name:" {} \; | head -1)
PLUGIN_SLUG=$(basename "$PLUGIN_FILE" .php)
fi
PLUGIN_NAME=$(grep "Plugin Name:" "$PLUGIN_FILE" | head -1 | sed 's/.*Plugin Name:\s*\([^*]*\).*/\1/' | xargs)
echo "slug=${PLUGIN_SLUG}" >> $GITHUB_OUTPUT
echo "name=${PLUGIN_NAME}" >> $GITHUB_OUTPUT
echo "version=${TAG_VERSION}" >> $GITHUB_OUTPUT
echo "📦 Plugin: ${PLUGIN_NAME} (${PLUGIN_SLUG})"
echo "🏷️ Version: ${TAG_VERSION}"
echo "🔖 Tag: ${GITHUB_REF_NAME}"
- name: Extract changelog content
id: changelog
run: |
VERSION="${{ steps.info.outputs.version }}"
echo "Extracting changelog for version: ${VERSION}"
# Extract changelog from CHANGELOG.md if it exists
if [ -f "CHANGELOG.md" ]; then
# Match version with optional brackets, v-prefix, and anything after (like date)
# Matches: "## v1.0.0 - 2024-01-01", "## [1.0.0]", "## 1.0.0"
CHANGELOG=$(sed -n "/^## \[*v*${VERSION}[]\) -]*/,/^## /p" CHANGELOG.md | sed '1d;$d' | awk 'NF {p=1} p')
# If still empty, try unreleased section
if [ -z "$CHANGELOG" ]; then
CHANGELOG=$(sed -n "/^## Unreleased/,/^## /p" CHANGELOG.md | sed '1d;$d' | awk 'NF {p=1} p')
fi
else
CHANGELOG="Release ${VERSION}"
fi
{
echo 'content<<EOF'
echo "$CHANGELOG"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Create release package
id: package
run: |
PLUGIN_SLUG="${{ steps.info.outputs.slug }}"
PLUGIN_VERSION="${{ steps.info.outputs.version }}"
PACKAGE_NAME="${PLUGIN_SLUG}_v${PLUGIN_VERSION}.zip"
echo "📦 Creating package: $PACKAGE_NAME"
# Create ZIP package excluding development files
zip -r "$PACKAGE_NAME" . \
-x "*.git*" \
-x "*.github*" \
-x "node_modules/*" \
-x "bin/*" \
-x "*.DS_Store*" \
-x "*.log" \
-x "*.md" \
-x "*.zip" \
-x "package.json" \
-x "package-lock.json" \
-x ".gitignore" \
-x ".editorconfig" \
-x ".phpcs.xml*" \
-x "composer.json" \
-x "composer.lock" \
-x "phpunit.xml*" \
-x "tests/*"
# Verify package was created
if [ -f "$PACKAGE_NAME" ]; then
FILE_SIZE=$(ls -lh "$PACKAGE_NAME" | awk '{print $5}')
sha256sum "$PACKAGE_NAME" > "${PACKAGE_NAME}.sha256"
echo "✅ Package created: $PACKAGE_NAME ($FILE_SIZE)"
echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT
else
echo "❌ Failed to create package"
exit 1
fi
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.info.outputs.slug }}-${{ steps.info.outputs.version }}
path: |
${{ steps.package.outputs.name }}
${{ steps.package.outputs.name }}.sha256
retention-days: 30
# ============================================================================
# CREATE GITHUB RELEASE
# ============================================================================
github-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: build
outputs:
release_url: ${{ steps.set_url.outputs.release_url }}
upload_url: ${{ steps.release.outputs.upload_url }}
is_prerelease: ${{ steps.prerelease.outputs.is_prerelease }}
steps:
- name: Download package artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.plugin_slug }}-${{ needs.build.outputs.plugin_version }}
- name: Detect pre-release
id: prerelease
run: |
TAG="${{ github.ref_name }}"
if [[ "$TAG" =~ -alpha || "$TAG" =~ -beta || "$TAG" =~ -rc ]]; then
echo "is_prerelease=true" >> $GITHUB_OUTPUT
echo "🔖 Pre-release detected: $TAG"
else
echo "is_prerelease=false" >> $GITHUB_OUTPUT
echo "✅ Production release: $TAG"
fi
- name: Create GitHub Release
id: release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: ${{ needs.build.outputs.plugin_name }} ${{ github.ref_name }}
body: |
# ${{ needs.build.outputs.plugin_name }} ${{ github.ref_name }}
${{ needs.build.outputs.changelog_content }}
## 📦 Installation
1. Download the plugin ZIP file below
2. Upload to WordPress via Plugins → Add New → Upload Plugin
3. Activate the plugin
---
**Package**: `${{ needs.build.outputs.package_name }}`
**Generated**: ${{ github.sha }}
files: |
${{ needs.build.outputs.package_name }}
${{ needs.build.outputs.package_name }}.sha256
draft: false
prerelease: ${{ steps.prerelease.outputs.is_prerelease }}
generate_release_notes: false
- name: Set release URL output
id: set_url
run: |
RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}"
echo "release_url=${RELEASE_URL}" >> $GITHUB_OUTPUT
echo "✅ Release URL: ${RELEASE_URL}"
# ============================================================================
# NOTIFY EDD STORE
# ============================================================================
edd-webhook:
name: Notify EDD Store
runs-on: ubuntu-latest
needs: [build, github-release]
if: |
always() &&
needs.build.result == 'success' &&
needs.github-release.result == 'success'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get release asset API URL
id: get_asset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PACKAGE_NAME="${{ needs.build.outputs.package_name }}"
echo "📦 Fetching asset API URL for: $PACKAGE_NAME"
# Get asset API URL from GitHub API
ASSET_URL=$(gh api repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} \
--jq ".assets[] | select(.name == \"$PACKAGE_NAME\") | .url")
if [ -z "$ASSET_URL" ] || [ "$ASSET_URL" == "null" ]; then
echo "❌ Could not find asset URL for $PACKAGE_NAME"
exit 1
fi
echo "asset_url=${ASSET_URL}" >> $GITHUB_OUTPUT
echo "✅ Asset API URL: ${ASSET_URL}"
- name: Sync release to EDD Store
uses: code-atlantic/edd-release-sync@v0.2.0
with:
edd_id: ${{ secrets.EDD_PRODUCT_ID }}
version: ${{ needs.build.outputs.plugin_version }}
release_url: ${{ needs.github-release.outputs.release_url }}
download_url: "https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/${{ needs.build.outputs.package_name }}"
asset_api_url: ${{ steps.get_asset.outputs.asset_url }}
webhook_url: ${{ secrets.EDD_WEBHOOK_URL }}
webhook_token: ${{ secrets.EDD_WEBHOOK_TOKEN }}
plugin_slug: ${{ needs.build.outputs.plugin_slug }}
is_prerelease: ${{ needs.github-release.outputs.is_prerelease }}
# ============================================================================
# UPLOAD TO GOOGLE DRIVE
# ============================================================================
google-drive-upload:
name: Upload to Google Drive
runs-on: ubuntu-latest
needs: [build, github-release]
if: needs.build.result == 'success' && needs.github-release.result == 'success'
outputs:
file_id: ${{ steps.upload.outputs.file_id }}
web_view_link: ${{ steps.upload.outputs.web_view_link }}
download_link: ${{ steps.upload.outputs.download_link }}
updated: ${{ steps.upload.outputs.updated }}
skipped: ${{ steps.upload.outputs.skipped }}
steps:
- name: Download package artifact
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.plugin_slug }}-${{ needs.build.outputs.plugin_version }}
- name: Upload to Google Drive with sharing
id: upload
uses: code-atlantic/sync-release-to-google-drive@v0.3.1
with:
filename: ${{ needs.build.outputs.package_name }}
credentials: ${{ secrets.GOOGLE_DRIVE_CREDENTIALS_B64 }}
folder_id: ${{ secrets.GOOGLE_DRIVE_FOLDER_ID }}
overwrite: "true"
sharing: anyone
link_discoverable: false # Link-only sharing, not searchable
# ============================================================================
# SLACK NOTIFICATION
# ============================================================================
slack-notification-success:
name: Slack Success Notification
runs-on: ubuntu-latest
needs: [build, github-release, edd-webhook, google-drive-upload]
if: |
always() &&
needs.build.result == 'success' &&
needs.github-release.result == 'success' &&
needs.edd-webhook.result == 'success'
steps:
- name: Send success notification to Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
PLUGIN_NAME="${{ needs.build.outputs.plugin_name }}"
RELEASE_URL="${{ needs.github-release.outputs.release_url }}"
CHANGELOG="${{ needs.build.outputs.changelog_content }}"
DRIVE_DOWNLOAD_URL="${{ needs.google-drive-upload.outputs.download_link }}"
DRIVE_UPDATED="${{ needs.google-drive-upload.outputs.updated }}"
DRIVE_SKIPPED="${{ needs.google-drive-upload.outputs.skipped }}"
MESSAGE="*${PLUGIN_NAME} ${{ github.ref_name }}*\n\n"
# Add changelog
if [ -n "$CHANGELOG" ]; then
MESSAGE="${MESSAGE}\`\`\`\n${CHANGELOG}\n\`\`\`\n\n"
fi
MESSAGE="${MESSAGE}*Downloads:*\n"
MESSAGE="${MESSAGE}🔗 <${RELEASE_URL}|GitHub Release>\n"
MESSAGE="${MESSAGE}⬇️ <${DRIVE_DOWNLOAD_URL}|Download Release Zip (shareable link))>\n"
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "⚠️ SLACK_WEBHOOK_URL not configured"
exit 0
fi
curl -X POST \
--data-urlencode "payload={\"text\": \"${MESSAGE}\", \"username\": \"Release Bot\", \"icon_emoji\": \":package:\"}" \
"$SLACK_WEBHOOK_URL" \
--fail --silent --show-error
echo "✅ Slack sent"
slack-notification-failure:
name: Slack Failure Notification
runs-on: ubuntu-latest
needs: [build, github-release, edd-webhook, google-drive-upload]
if: |
always() &&
needs.build.result == 'success' &&
(needs.github-release.result == 'failure' || needs.edd-webhook.result == 'failure' || needs.google-drive-upload.result == 'failure')
steps:
- name: Send failure notification to Slack
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
run: |
PLUGIN_NAME="${{ needs.build.outputs.plugin_name }}"
GITHUB_STATUS="${{ needs.github-release.result == 'success' && '✅' || '❌' }}"
EDD_STATUS="${{ needs.edd-webhook.result == 'success' && '✅' || '❌' }}"
DRIVE_STATUS="${{ needs.google-drive-upload.result == 'success' && '✅' || '❌' }}"
TITLE="🚨 RELEASE FAILURE: ${PLUGIN_NAME} ${{ github.ref_name }}"
MESSAGE="*Release encountered errors!*\n"
MESSAGE="${MESSAGE}• *Version:* ${{ github.ref_name }}\n"
MESSAGE="${MESSAGE}• *GitHub:* ${GITHUB_STATUS}\n"
MESSAGE="${MESSAGE}• *EDD:* ${EDD_STATUS}\n"
MESSAGE="${MESSAGE}• *Drive:* ${DRIVE_STATUS}\n\n"
MESSAGE="${MESSAGE}🔍 Check workflow: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\n\n"
MESSAGE="${MESSAGE}#release #failure #popup-maker"
echo "📢 Sending failure notification to Slack..."
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "⚠️ SLACK_WEBHOOK_URL secret not configured - skipped"
exit 0
fi
curl -X POST \
--data-urlencode "payload={\"text\": \"${TITLE}\\n\\n${MESSAGE}\", \"username\": \"Release Bot\", \"icon_emoji\": \":x:\"}" \
"$SLACK_WEBHOOK_URL" \
--fail --silent --show-error
echo "✅ Slack notification sent"
# ============================================================================
# RELEASE SUMMARY
# ============================================================================
summary:
name: Generate Release Summary
runs-on: ubuntu-latest
needs:
[
build,
github-release,
edd-webhook,
google-drive-upload,
slack-notification-success,
slack-notification-failure,
]
if: always()
steps:
- name: Generate release summary
run: |
PLUGIN_NAME="${{ needs.build.outputs.plugin_name }}"
VERSION="${{ github.ref_name }}"
echo "# 🚀 Release Summary: ${PLUGIN_NAME} ${VERSION}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Triggered by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
[ "${{ needs.build.result }}" == "success" ] && echo "✅ **Package Creation**: Package built successfully" >> $GITHUB_STEP_SUMMARY || echo "❌ **Package Creation**: Failed" >> $GITHUB_STEP_SUMMARY
[ "${{ needs.github-release.result }}" == "success" ] && echo "✅ **GitHub Release**: Release created" >> $GITHUB_STEP_SUMMARY || echo "❌ **GitHub Release**: Failed" >> $GITHUB_STEP_SUMMARY
[ "${{ needs.edd-webhook.result }}" == "success" ] && echo "✅ **EDD Webhook**: Webhook delivered" >> $GITHUB_STEP_SUMMARY || echo "❌ **EDD Webhook**: Failed or skipped" >> $GITHUB_STEP_SUMMARY
[ "${{ needs.google-drive-upload.result }}" == "success" ] && echo "✅ **Google Drive Upload**: File uploaded" >> $GITHUB_STEP_SUMMARY || echo "❌ **Google Drive Upload**: Failed or skipped" >> $GITHUB_STEP_SUMMARY
[ "${{ needs.slack-notification-success.result }}" == "success" ] && echo "✅ **Slack Notification**: Success notification sent" >> $GITHUB_STEP_SUMMARY || [ "${{ needs.slack-notification-failure.result }}" == "success" ] && echo "⚠️ **Slack Notification**: Failure notification sent" >> $GITHUB_STEP_SUMMARY || echo "❌ **Slack Notification**: Failed or skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## 📦 Package Information" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**File:** \`${{ needs.build.outputs.package_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Download:** [GitHub Release](${{ needs.github-release.outputs.release_url }})" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "*🚀 Release Generated by GitHub Actions*" >> $GITHUB_STEP_SUMMARY