Skip to content
Posts

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

How I built a custom GitHub Actions workflow that cuts Cloudflare Worker deployment time from 8 minutes to 2.5 minutes.

GitHub Actions bot comment "Deployed to Cloudflare Workers" with a table of bundle size, build duration, commits, author and preview URL

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.

GitHub Actions page listing 55 workflow run results of the "Deploy to Preview" workflow for pull request #26, mostly successful runs of about 2.5 minutes and one failed run

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.

Cloudflare build details page for a failed build that took 7m 18s: building the application alone took 5m 49s

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

Cloudflare Workers bot comment on a pull request reporting "Deployment failed" for the latest commit

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.

Pull request #26 where the github-actions bot comments "Deployed to Cloudflare Workers" with a table of bundle size, build duration, commits, author and preview URL

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.

Email notification of the github-actions bot comment "Deployed to Cloudflare Workers" with the same table of build details

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.

There’s a production URL: https://www.besidka.com/

Repository: https://github.com/besidka/besidka

Besidka logo: a pink cloud-shaped speech bubble with eyes above the word "besidka" on a light pink background