Skip to content

Commit 8d4887d

Browse files
committed
Add stable release asset URL
This is so that we can point to `/latest/datakit.zip` and have a compiled asset instead of an uncompiled one.
1 parent 93a01d1 commit 8d4887d

File tree

1 file changed

+74
-3
lines changed

1 file changed

+74
-3
lines changed

.github/workflows/deployment.yml

+74-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ jobs:
4646
pull-requests: write
4747
id-token: write
4848

49+
outputs:
50+
plugin_version: ${{ steps.version.outputs.version }}
51+
4952
steps:
5053
- name: Validate Freemius Credentials
5154
id: credentials
@@ -71,7 +74,11 @@ jobs:
7174
tools: composer:v2
7275
coverage: none
7376

74-
# Step 5: Cache Composer dependencies
77+
- name: Setup Git
78+
run: |
79+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
80+
git config --global user.name "github-actions[bot]"
81+
7582
- name: Cache Composer dependencies
7683
uses: actions/cache@v4
7784
with:
@@ -107,6 +114,8 @@ jobs:
107114
echo "::error::Failed to create ZIP file"
108115
exit 1
109116
fi
117+
118+
echo "zip_path=$(realpath build/datakit.zip)" >> $GITHUB_OUTPUT
110119
111120
- name: Validate ZIP
112121
id: validate
@@ -218,7 +227,60 @@ jobs:
218227
}
219228
"
220229
221-
# Step 12: Create Release Comment
230+
- name: Upload Release Assets
231+
if: github.event_name == 'release' && !github.event.release.prerelease
232+
env:
233+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
234+
timeout-minutes: 2
235+
run: |
236+
# Upload to current release
237+
if ! gh release upload ${{ github.ref_name }} build/datakit.zip --clobber; then
238+
echo "::error::Failed to upload to current release"
239+
exit 1
240+
fi
241+
242+
# Only update latest if this is marked as the latest release
243+
if [ "${{ github.event.release.draft }}" != "true" ] && [ "${{ github.event.release.prerelease }}" != "true" ]; then
244+
echo "This is a full release - updating latest tag"
245+
246+
# Create or update latest release with retries
247+
max_attempts=3
248+
attempt=1
249+
while [ $attempt -le $max_attempts ]; do
250+
if gh release view latest > /dev/null 2>&1; then
251+
if gh release upload latest build/datakit.zip --clobber; then
252+
break
253+
fi
254+
else
255+
if gh release create latest build/datakit.zip --notes "Latest stable release"; then
256+
break
257+
fi
258+
fi
259+
260+
echo "Attempt $attempt failed, retrying..."
261+
attempt=$((attempt + 1))
262+
sleep 5
263+
done
264+
265+
if [ $attempt -gt $max_attempts ]; then
266+
echo "::error::Failed to update latest release after $max_attempts attempts"
267+
exit 1
268+
fi
269+
270+
# Update the latest tag
271+
if ! git tag -f latest ${{ github.ref_name }}; then
272+
echo "::error::Failed to create latest tag"
273+
exit 1
274+
fi
275+
276+
if ! git push --force origin latest; then
277+
echo "::error::Failed to push latest tag"
278+
exit 1
279+
fi
280+
else
281+
echo "This is a draft/pre-release - not updating latest tag"
282+
fi
283+
222284
- name: Create Release Comment
223285
if: success() && github.event_name == 'release'
224286
uses: actions/github-script@v6
@@ -239,9 +301,18 @@ jobs:
239301
downloadUrl = 'Download URL not available';
240302
}
241303
304+
const versionedUrl = `https://github.com/${owner}/${repo}/releases/download/${process.env.GITHUB_REF_NAME}/datakit.zip`;
305+
const latestUrl = `https://github.com/${owner}/${repo}/releases/download/latest/datakit.zip`;
306+
242307
await github.rest.repos.updateRelease({
243308
owner,
244309
repo,
245310
release_id,
246-
body: context.payload.release.body + '\n\n✅ Successfully deployed to Freemius\n\n[📥 Download Plugin ZIP File](' + downloadUrl + ')'
311+
body: context.payload.release.body + '\n\n✅ Successfully deployed to Freemius\n\n' +
312+
'[📥 Download from Freemius](' + downloadUrl + ')\n\n' +
313+
'[📦 Download Build](' + versionedUrl + ')\n\n' +
314+
'_Stable URL:_\n' +
315+
'```\n' +
316+
latestUrl + '\n' +
317+
'```'
247318
});

0 commit comments

Comments
 (0)