shorebirdtech / docs

The shorebird docs site
https://docs.shorebird.dev
MIT License
9 stars 22 forks source link

Using Shorebird with Codemagic Workflow Editor 🛠️ #76

Open hadysata opened 1 year ago

hadysata commented 1 year ago

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
  2. 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 🙌!

hadysata commented 1 year ago

Oops, i think this should be on https://github.com/shorebirdtech/docs

eseidel commented 1 year ago

It's fine they're easy to move around :)

eseidel commented 1 year ago

@nilsreichardt do you have suggestions for what we should do with this? :) Also feel empowered to redirect us to the right codemagic folks.

nilsreichardt commented 1 year ago

Yes, I know how we can integrate this 👍 Cool, script! I'll update the docs in the next few days 👍

selva-dcx commented 1 year ago

nice hack @hadysata