Skip to content

Commit 11b3f6f

Browse files
committed
Enhances Cloudflare R2 release workflow with platform-specific commands
Adds support for platform-specific pre/post build commands, allowing for customized build processes on Linux, Windows, and macOS. Makes the `binary_output_dir` input required, ensuring the workflow can locate the built binaries. Refactors R2 configuration to separate account ID and bucket name into individual inputs and uses standard github secrets, providing better clarity and flexibility. Improves archive creation by fixing directory navigation and adding robust error handling.
1 parent 2685700 commit 11b3f6f

1 file changed

Lines changed: 123 additions & 25 deletions

File tree

.github/workflows/_cloudflare-r2-release.yml

Lines changed: 123 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ on:
4747
# Binary output configuration
4848
binary_output_dir:
4949
description: 'Directory containing built binaries (relative to workspace)'
50-
required: false
50+
required: true
5151
type: string
52-
default: 'src-tauri/target/release/bundle'
52+
default: ''
5353

5454
# Upload configuration
5555
upload_enabled:
@@ -79,13 +79,51 @@ on:
7979

8080
# Pre/post build commands
8181
pre_build_command:
82-
description: 'Command to run before building'
82+
description: 'Command to run before building (all platforms)'
83+
required: false
84+
type: string
85+
default: ''
86+
87+
pre_build_command_linux:
88+
description: 'Command to run before building (Linux only)'
89+
required: false
90+
type: string
91+
default: ''
92+
93+
pre_build_command_windows:
94+
description: 'Command to run before building (Windows only)'
95+
required: false
96+
type: string
97+
default: |
98+
choco install vcredist2022 -y
99+
echo "CARGO_BUILD_TARGET=" >> $GITHUB_ENV
100+
101+
pre_build_command_macos:
102+
description: 'Command to run before building (macOS only)'
83103
required: false
84104
type: string
85105
default: ''
86106

87107
post_build_command:
88-
description: 'Command to run after building'
108+
description: 'Command to run after building (all platforms)'
109+
required: false
110+
type: string
111+
default: ''
112+
113+
post_build_command_linux:
114+
description: 'Command to run after building (Linux only)'
115+
required: false
116+
type: string
117+
default: ''
118+
119+
post_build_command_windows:
120+
description: 'Command to run after building (Windows only)'
121+
required: false
122+
type: string
123+
default: ''
124+
125+
post_build_command_macos:
126+
description: 'Command to run after building (macOS only)'
89127
required: false
90128
type: string
91129
default: ''
@@ -146,20 +184,25 @@ on:
146184
required: false
147185
type: string
148186
default: ''
149-
150-
secrets:
151-
R2_ACCOUNT_ID:
187+
188+
# R2 Configuration (non-sensitive)
189+
r2_account_id:
152190
description: 'Cloudflare R2 Account ID'
153191
required: true
192+
type: string
193+
194+
r2_bucket:
195+
description: 'Cloudflare R2 Bucket Name'
196+
required: true
197+
type: string
198+
199+
secrets:
154200
R2_ACCESS_KEY_ID:
155201
description: 'Cloudflare R2 Access Key ID'
156202
required: true
157203
R2_SECRET_ACCESS_KEY:
158204
description: 'Cloudflare R2 Secret Access Key'
159205
required: true
160-
R2_BUCKET:
161-
description: 'Cloudflare R2 Bucket Name'
162-
required: true
163206

164207
outputs:
165208
upload_urls:
@@ -215,26 +258,44 @@ jobs:
215258
- name: Install dependencies
216259
run: ${{ inputs.setup_command }}
217260

218-
- name: Install Rust dependencies (Linux)
219-
if: matrix.platform == 'ubuntu-latest'
220-
run: |
221-
sudo apt-get update
222-
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
223-
224-
- name: Run pre-build command
261+
- name: Run pre-build command (all platforms)
225262
if: inputs.pre_build_command != ''
226263
run: ${{ inputs.pre_build_command }}
227264

265+
- name: Run pre-build command (Linux)
266+
if: inputs.pre_build_command_linux != '' && matrix.platform == 'ubuntu-latest'
267+
run: ${{ inputs.pre_build_command_linux }}
268+
269+
- name: Run pre-build command (Windows)
270+
if: matrix.platform == 'windows-latest'
271+
run: ${{ inputs.pre_build_command_windows }}
272+
273+
- name: Run pre-build command (macOS)
274+
if: inputs.pre_build_command_macos != '' && matrix.platform == 'macos-latest'
275+
run: ${{ inputs.pre_build_command_macos }}
276+
228277
- name: Build project
229278
id: build
230279
run: |
231280
${{ inputs.build_command }}
232281
echo "success=true" >> $GITHUB_OUTPUT
233282
234-
- name: Run post-build command
283+
- name: Run post-build command (all platforms)
235284
if: inputs.post_build_command != ''
236285
run: ${{ inputs.post_build_command }}
237286

287+
- name: Run post-build command (Linux)
288+
if: inputs.post_build_command_linux != '' && matrix.platform == 'ubuntu-latest'
289+
run: ${{ inputs.post_build_command_linux }}
290+
291+
- name: Run post-build command (Windows)
292+
if: inputs.post_build_command_windows != '' && matrix.platform == 'windows-latest'
293+
run: ${{ inputs.post_build_command_windows }}
294+
295+
- name: Run post-build command (macOS)
296+
if: inputs.post_build_command_macos != '' && matrix.platform == 'macos-latest'
297+
run: ${{ inputs.post_build_command_macos }}
298+
238299
- name: Identify platform suffix
239300
id: platform
240301
run: |
@@ -257,13 +318,48 @@ jobs:
257318
if: inputs.enable_compression
258319
shell: bash
259320
run: |
260-
cd ${{ inputs.binary_output_dir }}
321+
echo "=== Debug: Checking binary output directory ==="
322+
echo "Binary output dir: ${{ inputs.binary_output_dir }}"
323+
echo "Working directory: $(pwd)"
324+
325+
if [ ! -d "${{ inputs.binary_output_dir }}" ]; then
326+
echo "ERROR: Binary output directory does not exist!"
327+
exit 1
328+
fi
329+
330+
echo "Contents of binary output directory:"
331+
ls -la "${{ inputs.binary_output_dir }}"
332+
333+
if [ -z "$(ls -A "${{ inputs.binary_output_dir }}")" ]; then
334+
echo "ERROR: Binary output directory is empty!"
335+
exit 1
336+
fi
337+
338+
echo "=== Creating archive ==="
339+
ARCHIVE_NAME="${{ inputs.artifact_name_prefix }}-${{ steps.platform.outputs.suffix }}.${{ steps.platform.outputs.archive_ext }}"
261340
262341
# Create archive based on platform
263342
if [[ "${{ steps.platform.outputs.archive_ext }}" == "tar.gz" ]]; then
264-
tar -czf ../../../${{ inputs.artifact_name_prefix }}-${{ steps.platform.outputs.suffix }}.${{ steps.platform.outputs.archive_ext }} .
343+
echo "Creating tar.gz archive..."
344+
tar -czf "$ARCHIVE_NAME" -C "${{ inputs.binary_output_dir }}" .
345+
echo "Archive created at: $(pwd)/$ARCHIVE_NAME"
265346
else
266-
powershell -Command "Compress-Archive -Path * -DestinationPath ../../../${{ inputs.artifact_name_prefix }}-${{ steps.platform.outputs.suffix }}.${{ steps.platform.outputs.archive_ext }}"
347+
echo "Creating zip archive..."
348+
cd "${{ inputs.binary_output_dir }}"
349+
powershell -Command "Compress-Archive -Path * -DestinationPath '$(pwd)/$ARCHIVE_NAME'"
350+
cd $(pwd)
351+
echo "Archive created at: $(pwd)/$ARCHIVE_NAME"
352+
fi
353+
354+
# Verify archive was created
355+
if [ -f "$ARCHIVE_NAME" ]; then
356+
echo "✅ Archive created successfully!"
357+
ls -la "$ARCHIVE_NAME"
358+
else
359+
echo "❌ Archive was not created!"
360+
echo "Files in current directory:"
361+
ls -la
362+
exit 1
267363
fi
268364
269365
- name: Prepare uncompressed files
@@ -314,10 +410,10 @@ jobs:
314410
id: upload
315411
uses: ryand56/r2-upload-action@latest
316412
with:
317-
r2-account-id: ${{ secrets.R2_ACCOUNT_ID }}
413+
r2-account-id: ${{ inputs.r2_account_id }}
318414
r2-access-key-id: ${{ secrets.R2_ACCESS_KEY_ID }}
319415
r2-secret-access-key: ${{ secrets.R2_SECRET_ACCESS_KEY }}
320-
r2-bucket: ${{ secrets.R2_BUCKET }}
416+
r2-bucket: ${{ inputs.r2_bucket }}
321417
source-dir: upload
322418
destination-dir: ${{ inputs.r2_destination_dir }}/${{ github.ref_name }}/${{ github.sha }}
323419
output-file-url: true
@@ -329,7 +425,9 @@ jobs:
329425
run: |
330426
echo "Upload completed successfully!"
331427
echo "Uploaded files:"
332-
echo "${{ steps.upload.outputs.file-urls }}"
428+
cat << 'EOF'
429+
${{ steps.upload.outputs.file-urls }}
430+
EOF
333431
334432
create-release:
335433
name: Create GitHub Release
@@ -398,7 +496,7 @@ jobs:
398496
<!-- Add changelog here -->
399497
400498
---
401-
*Built with ❤️ using GitHub Actions*
499+
402500
EOF
403501
fi
404502

0 commit comments

Comments
 (0)