Skip to content

Using Shorebird with Codemagic Workflow Editor πŸ› οΈΒ #76

Open
@hadysata

Description

@hadysata

Hey Shorebird team! 🌟

First of all, let me express my appreciation for your amazing work on Shorebird πŸŽ‰! We're all super excited that code push is finally possible on Flutter! πŸ₯³

I wanted to share a solution I found for using Shorebird with the Codemagic Workflow Editor. As per your documentation, it is mentioned that Codemagic Workflow Editor doesn't support changing the build command, which is required for using Shorebird. I came up with a workaround that allows me to override the default flutter build command with Shorebird's command. I have tested this, and it works successfully on Codemagic.

Here's the setup 🎈:

  1. Create a bash script (let's call it setup_shorebird.sh) with the following content:
#!/bin/bash

# πŸš€ Install Shorebird
curl --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/shorebirdtech/install/main/install.sh -sSf | bash

echo PATH="/Users/builder/.shorebird/bin:$PATH" >> $CM_ENV

export SHOREBIRD_TOKEN="$SHOREBIRD_TOKEN"

# πŸ› οΈ Override the flutter command
cat > flutter_override.sh << 'EOF'
#!/bin/bash

# 🧐 Check if the first argument is "build"
if [ "$1" == "build" ]; then
  # 🎯 Run the modified command
  exec shorebird release android --force -- --dart-define=ENVIRONMENT_TYPE=production
else
  # πŸƒ Run the original command with the original arguments
  exec flutter "$@"
fi
EOF

# πŸ”’ Make the script executable
chmod +x flutter_override.sh

# 🚚 Move the script to /usr/local/bin
sudo mv flutter_override.sh /usr/local/bin/flutter

# 🎊 Print a success message
echo "Flutter override script has been installed successfully."

This script downloads and sets up Shorebird, then overrides the default flutter build command.

  1. In the Codemagic Workflow Editor, add the setup_shorebird.sh script to the "Pre-build script" section.
Screenshot 2023-07-11 at 2 26 21 AM
  1. Add the SHOREBIRD_TOKEN environment variable in the "Environment variables" section of the Codemagic Workflow Editor.
Screenshot 2023-07-11 at 2 27 50 AM

And voilà! 🎩✨ After completing these steps, the Codemagic build process should use Shorebird's command instead of the default flutter build.
Screenshot 2023-07-11 at 2 29 56 AM

Please note that I'm using the shorebird release android --force -- --dart-define=ENVIRONMENT_TYPE=production command to define environment variables. You can customize this as you wish or even make the script super-dynamic to accept any configuration set up in the workflow editor. 😁

I hope this workaround helps others who are looking to use Shorebird with Codemagic Workflow Editor 🌈.

Once again, thank you for your fantastic work on Shorebird πŸ™Œ!

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions