@@ -47,24 +47,22 @@ jobs:
47
47
id-token : write
48
48
49
49
steps :
50
- # Step 1: Validate Freemius Credentials
51
50
- name : Validate Freemius Credentials
51
+ id : credentials
52
52
run : |
53
53
if [ -z "${{ secrets.FREEMIUS_DEV_ID }}" ] || \
54
54
[ -z "${{ secrets.FREEMIUS_PUBLIC_KEY }}" ] || \
55
55
[ -z "${{ secrets.FREEMIUS_SECRET_KEY }}" ] || \
56
56
[ -z "${{ secrets.FREEMIUS_PLUGIN_ID }}" ]; then
57
- echo "Error: Missing required Freemius credentials"
57
+ echo "::error:: Missing required Freemius credentials"
58
58
exit 1
59
59
fi
60
60
61
- # Step 2: Checkout code
62
61
- name : Checkout Code
63
62
uses : actions/checkout@v4
64
63
with :
65
64
fetch-depth : 0
66
65
67
- # Step 4: Setup PHP
68
66
- name : Setup PHP
69
67
uses : shivammathur/setup-php@v2
70
68
with :
@@ -81,85 +79,87 @@ jobs:
81
79
key : ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
82
80
restore-keys : ${{ runner.os }}-composer-
83
81
84
- # Step 6: Check for Composer Dependencies
85
82
- name : Check for Composer
86
83
id : check_composer
87
84
run : |
88
85
if [ -f "composer.json" ]; then
89
86
echo "has_composer=true" >> $GITHUB_OUTPUT
90
87
fi
91
88
92
- # Step 7: Validate composer.json
93
89
- name : Validate composer.json
94
90
if : steps.check_composer.outputs.has_composer == 'true'
95
91
run : composer validate --strict
96
92
97
- # Step 8: Install Dependencies
98
93
- name : Install Dependencies
99
94
if : steps.check_composer.outputs.has_composer == 'true'
100
95
run : |
101
96
composer install --no-dev --optimize-autoloader
102
97
composer dump-autoload --optimize --no-dev
103
98
104
- # Step 8: Build the ZIP File
105
99
- name : Build Plugin ZIP
100
+ id : build
101
+ timeout-minutes : 5
106
102
run : |
107
- # Create a clean export using git archive
108
103
mkdir -p build
109
104
git archive HEAD --format=zip -o build/datakit.zip
105
+
106
+ if [ ! -f build/datakit.zip ]; then
107
+ echo "::error::Failed to create ZIP file"
108
+ exit 1
109
+ fi
110
110
111
- # Step 9: Validate ZIP
112
111
- name : Validate ZIP
112
+ id : validate
113
+ timeout-minutes : 2
113
114
run : |
114
- if [ ! -f build/datakit.zip ]; then
115
- echo "Error: ZIP file was not created successfully"
115
+ echo "Verifying ZIP contents..."
116
+
117
+ if ! unzip -l build/datakit.zip > zip_contents.txt; then
118
+ echo "::error::Failed to read ZIP contents"
116
119
exit 1
117
120
fi
118
121
119
- echo "ZIP contents:"
120
- unzip -l build/datakit.zip
122
+ missing_files=()
121
123
122
- # Verify key files exist in the ZIP
123
- echo "Verifying key files and directories..."
124
+ if ! grep -q "datakit.php" zip_contents.txt; then
125
+ missing_files+=("Main plugin file (datakit.php)")
126
+ fi
124
127
125
- # Check main plugin file
126
- if ! unzip -l build/datakit.zip | grep -q "datakit.php"; then
127
- echo "Error: Main plugin file not found in ZIP"
128
- exit 1
128
+ if ! grep -q "^.*src/" zip_contents.txt; then
129
+ missing_files+=("src directory")
130
+ elif [ $(grep "src/" zip_contents.txt | wc -l) -le 1 ]; then
131
+ echo "::warning::src directory appears to be empty"
129
132
fi
130
133
131
- # Check src directory exists and has contents
132
- if ! unzip -l build/datakit.zip | grep -q "^.*src/"; then
133
- echo "Error: src directory not found in ZIP"
134
- exit 1
134
+ if ! grep -q "^.*freemius/" zip_contents.txt; then
135
+ missing_files+=("freemius directory")
136
+ elif [ $(grep "freemius/" zip_contents.txt | wc -l) -le 1 ]; then
137
+ echo "::warning::freemius directory appears to be empty"
135
138
fi
136
139
137
- # Check src directory has contents (should show more than just the directory entry)
138
- if [ $(unzip -l build/datakit.zip | grep "src/" | wc -l) -le 1 ]; then
139
- echo "Error: src directory is empty "
140
+ if [ ${#missing_files[@]} -ne 0 ]; then
141
+ echo "::error::Missing required files/directories:"
142
+ printf '%s\n' "${missing_files[@]} "
140
143
exit 1
141
144
fi
142
145
143
- # Check Freemius directory exists and has contents
144
- if ! unzip -l build/datakit.zip | grep -q "^.*freemius/"; then
145
- echo "Error: freemius directory not found in ZIP"
146
+ echo "ZIP validation successful"
147
+
148
+ - name : Download Freemius PHP SDK
149
+ timeout-minutes : 2
150
+ run : |
151
+ if ! curl -L https://github.com/Freemius/php-sdk/archive/refs/heads/master.zip -o freemius-sdk.zip; then
152
+ echo "::error::Failed to download Freemius SDK"
146
153
exit 1
147
154
fi
148
155
149
- # Check Freemius directory has contents (should show more than just the directory entry)
150
- if [ $(unzip -l build/datakit.zip | grep "freemius/" | wc -l) -le 1 ]; then
151
- echo "Error: Freemius directory is empty"
156
+ if ! unzip freemius-sdk.zip; then
157
+ echo "::error::Failed to extract Freemius SDK"
152
158
exit 1
153
159
fi
154
160
155
- # Step 10: Download Freemius PHP SDK
156
- - name : Download Freemius PHP SDK
157
- run : |
158
- curl -L https://github.com/Freemius/php-sdk/archive/refs/heads/master.zip -o freemius-sdk.zip
159
- unzip freemius-sdk.zip
160
-
161
- # Step 11: Deploy to Freemius
162
161
- name : Deploy to Freemius
162
+ id : deploy
163
163
timeout-minutes : 5
164
164
env :
165
165
FREEMIUS_DEV_ID : ${{ secrets.FREEMIUS_DEV_ID }}
@@ -178,17 +178,14 @@ jobs:
178
178
\$plugin_id = getenv('FREEMIUS_PLUGIN_ID');
179
179
180
180
try {
181
- // Init SDK
182
181
\$api = new Freemius_Api(FS__API_SCOPE, FS__API_DEV_ID, FS__API_PUBLIC_KEY, FS__API_SECRET_KEY);
183
182
184
- // Get version from release tag or workflow dispatch input
185
183
\$version = trim(getenv('GITHUB_EVENT_NAME') === 'release'
186
184
? getenv('GITHUB_REF_NAME')
187
185
: getenv('INPUT_VERSION'), 'v');
188
186
189
187
echo \"Deploying version: \$version\\n\";
190
188
191
- // Deploy new version
192
189
\$result = \$api->Api(\"plugins/\$plugin_id/tags.json\", 'POST',
193
190
array(
194
191
'add_contributor' => true,
@@ -203,19 +200,20 @@ jobs:
203
200
throw new Exception('Freemius API Error: ' . \$result->error->message);
204
201
}
205
202
206
- # Generate download URL for GitHub release
207
203
\$free_version_download_url = \$api->GetSignedUrl(\"/plugins/{\$result->plugin_id}/tags/{\$result->id}.zip?is_premium=false\");
208
204
209
205
echo \"Successfully deployed version \$version to Freemius\\n\";
210
206
echo \"Download URL: \$free_version_download_url\\n\";
211
207
212
- file_put_contents('download_url.txt', \$free_version_download_url);
208
+ if (!file_put_contents('download_url.txt', \$free_version_download_url)) {
209
+ throw new Exception('Failed to save download URL');
210
+ }
213
211
214
212
echo 'Deployment details:\\n';
215
213
print_r(\$result);
216
214
217
215
} catch (Exception \$e) {
218
- echo \"Error: \" . \ $e->getMessage() . \" \\n\";
216
+ echo \"::error::{ $e->getMessage()} \\n\";
219
217
exit(1);
220
218
}
221
219
"
@@ -224,15 +222,22 @@ jobs:
224
222
- name : Create Release Comment
225
223
if : success() && github.event_name == 'release'
226
224
uses : actions/github-script@v6
225
+ timeout-minutes : 1
227
226
with :
228
227
github-token : ${{ secrets.GITHUB_TOKEN }}
229
228
script : |
230
229
const fs = require('fs');
231
230
const { owner, repo } = context.repo;
232
231
const release_id = context.payload.release.id;
233
232
234
- // Read the download URL from the file
235
- const downloadUrl = fs.readFileSync('download_url.txt', 'utf8').trim();
233
+ let downloadUrl;
234
+ try {
235
+ downloadUrl = fs.readFileSync('download_url.txt', 'utf8').trim();
236
+ if (!downloadUrl) throw new Error('Empty download URL');
237
+ } catch (error) {
238
+ console.error('Failed to read download URL:', error);
239
+ downloadUrl = 'Download URL not available';
240
+ }
236
241
237
242
await github.rest.repos.updateRelease({
238
243
owner,
0 commit comments