-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
194 lines (172 loc) · 6.5 KB
/
action.yml
File metadata and controls
194 lines (172 loc) · 6.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
name: "EDD Release Sync"
description: "Sync WordPress plugin releases to Easy Digital Downloads via webhook"
author: "Code Atlantic"
branding:
icon: "send"
color: "blue"
inputs:
# Required inputs
edd_id:
description: "EDD Download/Product ID"
required: true
version:
description: "Release version (e.g., 1.2.3)"
required: true
release_url:
description: "GitHub release URL"
required: true
download_url:
description: "Browser download URL for release package (required for file processing and customer downloads)"
required: true
asset_api_url:
description: "GitHub API asset URL (required for Git Updater dropdown compatibility - use API format, not browser URL)"
required: true
webhook_url:
description: "EDD Release Manager webhook endpoint URL"
required: true
webhook_token:
description: "Bearer token for webhook authentication"
required: true
# Optional inputs
plugin_slug:
description: "Plugin slug (fallback identifier if edd_id is invalid)"
required: false
readme_url:
description: "README URL (reserved for future use)"
required: false
is_prerelease:
description: "Is this a pre-release (beta/alpha/rc)"
required: false
default: "false"
changelog:
description: "Changelog content (auto-detects from CHANGELOG.md or readme.txt if not provided)"
required: false
test_mode:
description: "Enable test mode (validates without updating product)"
required: false
default: "false"
outputs:
status:
description: "Webhook delivery status (success/failed)"
value: ${{ steps.webhook.outputs.status }}
http_code:
description: "HTTP response code from webhook"
value: ${{ steps.webhook.outputs.http_code }}
response:
description: "Response body from webhook"
value: ${{ steps.webhook.outputs.response }}
runs:
using: "composite"
steps:
- name: Extract Changelog
id: changelog
shell: bash
run: |
# Use provided changelog or auto-detect
if [ -n "${{ inputs.changelog }}" ]; then
CHANGELOG="${{ inputs.changelog }}"
echo "📝 Using provided changelog"
else
echo "🔍 Auto-detecting changelog..."
VERSION="${{ inputs.version }}"
VERSION="${VERSION#v}" # Strip 'v' prefix
CHANGELOG=""
# Priority 1: CHANGELOG.md
if [ -f "CHANGELOG.md" ]; then
echo " Checking CHANGELOG.md..."
# Match various header formats: ## [2.0.0], ## 2.0.0, ## Version 2.0.0, ## v2.0.0
# Stop at next version heading (## v or ## [v) for efficiency
CHANGELOG=$(sed -n "/^##.*${VERSION}/,/^## \(v\|\[\)/p" CHANGELOG.md | sed '1d;$d' | sed '/^$/d')
fi
# Priority 2: readme.txt (WordPress format)
if [ -z "$CHANGELOG" ] && [ -f "readme.txt" ]; then
echo " Checking readme.txt..."
# Extract from == Changelog == section, stop at next version (= v)
CHANGELOG=$(awk '/^== Changelog ==/,/^== / {print}' readme.txt | \
sed -n "/^= ${VERSION}/,/^= v/p" | sed '1d;$d' | sed '/^$/d')
fi
if [ -n "$CHANGELOG" ]; then
echo " ✅ Changelog extracted successfully"
else
echo " ⚠️ No changelog found for version ${VERSION}"
fi
fi
# Output for next step (handle multiline)
{
echo 'content<<EOF'
echo "$CHANGELOG"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: Send EDD Release Webhook
id: webhook
shell: bash
run: |
echo "📡 Sending webhook to EDD Release Manager..."
echo " EDD ID: ${{ inputs.edd_id }}"
echo " Version: ${{ inputs.version }}"
echo " Pre-release: ${{ inputs.is_prerelease }}"
echo " Test Mode: ${{ inputs.test_mode }}"
# Build JSON payload with all required fields
PAYLOAD=$(jq -n \
--arg edd_id "${{ inputs.edd_id }}" \
--arg version "${{ inputs.version }}" \
--arg release_url "${{ inputs.release_url }}" \
--arg download_url "${{ inputs.download_url }}" \
--arg asset_api_url "${{ inputs.asset_api_url }}" \
'{
edd_id: ($edd_id | tonumber),
version: $version,
release_url: $release_url,
download_url: $download_url,
asset_api_url: $asset_api_url
}')
# Add optional fields if provided
if [ -n "${{ inputs.plugin_slug }}" ]; then
PAYLOAD=$(echo "$PAYLOAD" | jq --arg val "${{ inputs.plugin_slug }}" '. + {plugin: $val}')
fi
if [ -n "${{ inputs.readme_url }}" ]; then
PAYLOAD=$(echo "$PAYLOAD" | jq --arg val "${{ inputs.readme_url }}" '. + {readme_url: $val}')
fi
# Add pre-release flag
if [ "${{ inputs.is_prerelease }}" = "true" ]; then
PAYLOAD=$(echo "$PAYLOAD" | jq '. + {is_prerelease: true}')
else
PAYLOAD=$(echo "$PAYLOAD" | jq '. + {is_prerelease: false}')
fi
# Add changelog if extracted
if [ -n "${{ steps.changelog.outputs.content }}" ]; then
PAYLOAD=$(echo "$PAYLOAD" | jq --arg val "${{ steps.changelog.outputs.content }}" '. + {changelog: $val}')
fi
if [ "${{ inputs.test_mode }}" = "true" ]; then
PAYLOAD=$(echo "$PAYLOAD" | jq '. + {test_mode: true}')
fi
echo "Payload:"
echo "$PAYLOAD" | jq '.'
# Send webhook with error handling
RESPONSE=$(curl -X POST "${{ inputs.webhook_url }}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${{ inputs.webhook_token }}" \
-d "$PAYLOAD" \
-w "\nHTTP_CODE:%{http_code}" \
-s)
# Extract HTTP code and body
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_CODE:" | cut -d':' -f2)
BODY=$(echo "$RESPONSE" | sed '/HTTP_CODE:/d')
# Set outputs
echo "http_code=$HTTP_CODE" >> $GITHUB_OUTPUT
{
echo "response<<EOF"
echo "$BODY"
echo "EOF"
} >> $GITHUB_OUTPUT
# Check success
if [ "$HTTP_CODE" = "200" ]; then
echo "status=success" >> $GITHUB_OUTPUT
echo "✅ Webhook delivered successfully"
echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY"
else
echo "status=failed" >> $GITHUB_OUTPUT
echo "❌ Webhook failed with HTTP $HTTP_CODE"
echo "$BODY" | jq '.' 2>/dev/null || echo "$BODY"
exit 1
fi