DEV Community

Manuel Artero Anguita 🟨
Manuel Artero Anguita 🟨

Posted on

1

Reducing Code Duplication in GitHub Actions Workflows (1/2)

We use GitHub Actions to set up our CI/CD. The infra team (they renamed themselves to 'DevOps' a few years ago 🤔) set up a pool of runners for us and shared the IaC (Infrastructure as Code) repository for provisioning them.

- "Hey devs, here you go. Now you can install and run whatever you need in your pipelines"

Since then, I’ve been trying to improve our workflows (pipelines).


Here’s the thing: the YAML file is code. And like any other piece of code, it can benefit from clean code principles.

I don’t consider myself a clean code advocate anymore. I mean, I used to be that nick-piti kind of guy, but now I think I’ve grown... wiser🧙‍♂️?

Some code duplication? yep, fine. Some abstractions? over-engineering.

simpler >> canonically cleaner.


Anyway, reducing code duplication is generally speaking a good thing.

And reducing code duplication in your Github Actions workflows is a good thing 👍


What we have

Two workflows: release.yaml & deploy.yaml.

First, let’s clarify terms—because no, they’re not interchangeable. this question:

  • "What does a release mean?"

...It depends. 🤷‍♂️

In the context of this post -> a web front-end application; I like to picture the output of each workflow:

Release

Build the Docker image and publish it to our image registry (with the appropriate tag).

Release

  • Input: the code base.
  • Output: nn image -we use Docker specifically- for instance awesome-front-app:1.0.3 + (recommended) a tag on git.
    • What's in the image: the application (production build) ready to be served by a web server.

Deploy

Deploying –again, in this context– means updating the Kubernetes (K8s) config to use that fresh image tag. You edit the image field in the deployment YAML file to point to the updated tag (in this example, awesome-front-app:1.0.3).

Then, K8s pulls the new image and rolls it out, gradually swapping out the old pods for the new ones.

Deployment

  • Input: deployment YAML file.
  • Output: the server is running the new version.

So, we’ve got these action workflows, and just like any other code, there can be improvements. Some of the tasks in both the release.yaml and deploy.yaml were repeating themselves.

...Alright, this post is already getting longer than I expected. I’ll stop here for now.
In the next post, I’ll dig into actual GitHub Actions changes I made to reduce code duplication in those workflows. Stay tuned! 🚀

--

thanks for reading.

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (1)

Collapse
 
nausaf profile image
nausaf

cliffhanger!

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay