Skip to content

An open-source cross-platform alternative to AirDrop

ci: add CLI scripts for linux and macos

Tien Do Nam5bfc03a89ca4
diff --git a/.github/workflows/build_cli_linux.yml b/.github/workflows/build_cli_linux.yml
new file mode 100644
index 00000000..6957ac76
--- /dev/null
+++ b/.github/workflows/build_cli_linux.yml
@@ -0,0 +1,51 @@
+name: Build CLI for Linux
+
+on:
+ workflow_dispatch:
+
+jobs:
+ build:
+ runs-on: ubuntu-22.04
+ outputs:
+ version: ${{ steps.get_version.outputs.version }}
+
+ steps:
+ - uses: actions/checkout@v6
+
+ - name: Get version from pubspec.yaml
+ id: get_version
+ run: |
+ VERSION=$(sed -n 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' app/pubspec.yaml)
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
+
+ build_cli:
+ needs: build
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - runner: ubuntu-22.04
+ suffix: linux-x86-64
+ - runner: ubuntu-22.04-arm
+ suffix: linux-arm-64
+ runs-on: ${{ matrix.runner }}
+
+ steps:
+ - uses: actions/checkout@v6
+
+ # cli/ uses edition 2024; the preinstalled toolchain on the runner may be outdated
+ - name: Update Rust
+ run: rustup update stable
+
+ - name: Compile CLI
+ run: cargo build --release --package localsend-cli
+
+ - name: Rename CLI executable
+ run: mv target/release/localsend-cli target/release/LocalSend-CLI-${{ needs.build.outputs.version }}-${{ matrix.suffix }}
+
+ - name: Upload CLI
+ uses: actions/upload-artifact@v6
+ with:
+ name: cli-${{ matrix.suffix }}-result
+ path: target/release/LocalSend-CLI-${{ needs.build.outputs.version }}-${{ matrix.suffix }}
+ if-no-files-found: error
diff --git a/support/scripts/compile_mac_cli.sh b/support/scripts/compile_mac_cli.sh
new file mode 100644
index 00000000..6c7ed7bf
--- /dev/null
+++ b/support/scripts/compile_mac_cli.sh
@@ -0,0 +1,39 @@
+VERSION=$(sed -n 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' app/pubspec.yaml)
+ARM_BIN="LocalSend-CLI-$VERSION-macos-arm-64"
+X64_BIN="LocalSend-CLI-$VERSION-macos-x86-64"
+
+rustup target add aarch64-apple-darwin x86_64-apple-darwin
+
+echo
+echo "Compiling the CLI..."
+echo
+cargo build --release --package localsend-cli --target aarch64-apple-darwin
+cargo build --release --package localsend-cli --target x86_64-apple-darwin
+
+rm -f "$ARM_BIN" "$X64_BIN" "$ARM_BIN.zip" "$X64_BIN.zip"
+cp target/aarch64-apple-darwin/release/localsend-cli "$ARM_BIN"
+cp target/x86_64-apple-darwin/release/localsend-cli "$X64_BIN"
+
+# sign the binaries
+echo
+echo "Signing the CLI..."
+echo
+SIGN_ID="Developer ID Application: Tien Do Nam (3W7H4PYMCV)"
+codesign --force --verbose --options runtime --sign "$SIGN_ID" "$ARM_BIN"
+codesign --force --verbose --options runtime --sign "$SIGN_ID" "$X64_BIN"
+
+# send to apple for notarization
+APP_PASSWORD=abcd-efgh-ijkl-mnop
+TEAM_ID=3W7H4PYMCV
+
+echo
+echo "Sending to apple for notarization..."
+echo
+zip "$ARM_BIN.zip" "$ARM_BIN"
+zip "$X64_BIN.zip" "$X64_BIN"
+xcrun notarytool submit "$ARM_BIN.zip" --wait --apple-id $DEV_EMAIL --password "$APP_PASSWORD" --team-id "$TEAM_ID"
+xcrun notarytool submit "$X64_BIN.zip" --wait --apple-id $DEV_EMAIL --password "$APP_PASSWORD" --team-id "$TEAM_ID"
+
+# bare binaries cannot be stapled; Gatekeeper fetches the ticket online
+rm -f "$ARM_BIN.zip" "$X64_BIN.zip"
diff --git a/support/scripts/compile_mac_dmg.sh b/support/scripts/compile_mac_dmg.sh
index db9956cb..7f634687 100644
--- a/support/scripts/compile_mac_dmg.sh
+++ b/support/scripts/compile_mac_dmg.sh
@@ -1,6 +1,9 @@
# Prerequisite:
# - brew install create-dmg
+VERSION=$(sed -n 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p' app/pubspec.yaml)
+DMG="LocalSend-$VERSION.dmg"
+
cd app
fvm flutter clean
fvm flutter pub get
@@ -18,21 +21,21 @@ codesign --deep --force --verbose --options runtime --entitlements macos/Runner/
echo
echo "Creating dmg..."
echo
-rm -f LocalSend.dmg
+rm -f "$DMG"
create-dmg \
--volname "LocalSend" \
--window-size 500 300 \
--background "../support/build/dmg/background.png" \
--icon LocalSend.app 130 110 \
--app-drop-link 360 110 \
- LocalSend.dmg \
+ "$DMG" \
build/macos/Build/Products/Release/LocalSend.app
# sign the dmg
echo
echo "Signing the dmg..."
echo
-codesign --force --verbose --sign "$SIGN_ID" LocalSend.dmg
+codesign --force --verbose --sign "$SIGN_ID" "$DMG"
# send to apple for notarization
@@ -42,11 +45,11 @@ TEAM_ID=3W7H4PYMCV
echo
echo "Sending to apple for notarization..."
echo
-xcrun notarytool submit LocalSend.dmg --wait --apple-id $DEV_EMAIL --password "$APP_PASSWORD" --team-id "$TEAM_ID"
+xcrun notarytool submit "$DMG" --wait --apple-id $DEV_EMAIL --password "$APP_PASSWORD" --team-id "$TEAM_ID"
# download notarization result and apply to the dmg
echo
echo "Run stapler..."
echo
-xcrun stapler staple LocalSend.dmg
+xcrun stapler staple "$DMG"
cd ..