3x Faster: How I Optimized Cloudflare Worker Deployments with a Custom GitHub Actions Workflow

3x Faster: How I Optimized Cloudflare Worker Deployments with a Custom GitHub Actions Workflow

I've built my own GitHub Actions integration for deploying to Cloudflare Workers. It offers more features, greater convenience, and more build steps, including running linters and tests. I've slashed the build time from 8 minutes down to just 2.5—that's 3 times faster.

One pull request involved 55 attempts at creating a custom GitHub Actions workflow, 26 of which failed. But I finally nailed it.

Article content

The task: build a workflow for both production and preview builds on Cloudflare Workers. The production build is triggered only by a push or a pull request merge into the protected main branch. Cloudflare does have an out-of-the-box integration with GitHub.

But it's limited to just a couple of commands: build and deploy. And even so, a build takes 6-8 minutes, depending on the framework. It also doesn't provide a clean way to run linters and tests.

Article content

One cool thing about their integration is the friendly messages it posts in pull requests for preview deployments.

Article content

If something's missing, build it yourself. Which is undoubtedly what I did. Now I have my bot that displays all the information I need, and in a much cleaner format than the bot from Cloudflare.

Article content

I also configured it to trigger a preview build for every commit in a pull request. The bot posts a separate comment for each build, so you can review individual builds for specific fixes within the same PR.

This way, you can compare specific changes within a pull request, including the bundle size—which is especially useful for optimization tasks. Or simply detect how much larger the bundle gets after adding a new NPM package.

And while the Cloudflare bot just updates its previous comment, mine posts a new one each time. As a result, when I'm subscribed to a pull request, I get clean, structured email notifications for each build.

Article content

And the best part? This entire workflow—running linters, tests, generating different wrangler.json files, building the application, and deploying to Workers—takes just 2.5 minutes, compared to Cloudflare's 6-8 minutes. That's a 3x speed-up.

Besidka is the product on which I am currently working. The open-source AI Chat, where you can bring your API keys and only pay for what you use. I am still in the MVP stage, but much has been accomplished.

Article content


To view or add a comment, sign in

More articles by Serhii Chernenko

Others also viewed

Explore content categories